Skip to content

Commit aa370f6

Browse files
committed
feat: create tasks automatically on load and if relevant input changes
1 parent 2fb0b9b commit aa370f6

File tree

1 file changed

+28
-25
lines changed

1 file changed

+28
-25
lines changed

src/components/CalendarForm.tsx

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,27 @@ function CalendarForm() {
7070
window.sessionStorage.setItem(calendarPrefixCacheKey, newPrefix);
7171
}
7272

73+
const resetValues = () => {
74+
window.sessionStorage.removeItem(startDateCacheKey);
75+
setStartDate(initialStartDate)
76+
77+
window.sessionStorage.removeItem(responsibleCacheKey);
78+
setResponsible(initialResponsible)
79+
80+
window.sessionStorage.removeItem(bufferCacheKey);
81+
setPuffer(0)
82+
83+
window.sessionStorage.removeItem(calendarPrefixCacheKey);
84+
setCalendarTitlePrefix('')
85+
}
86+
87+
const hasActiveCache = () => {
88+
return !!window.sessionStorage.getItem(startDateCacheKey)
89+
|| !!window.sessionStorage.getItem(responsibleCacheKey)
90+
|| !!window.sessionStorage.getItem(bufferCacheKey)
91+
|| !!window.sessionStorage.getItem(calendarPrefixCacheKey)
92+
}
93+
7394
const createTasks = useCallback((event?: FormEvent<HTMLFormElement> | undefined) => {
7495
event?.preventDefault()
7596

@@ -102,28 +123,11 @@ function CalendarForm() {
102123
.sort((a: TaskT, b: TaskT) => a.deadline.getTime() - b.deadline.getTime())
103124

104125
setTasks(tasks)
105-
}, [taskList, startDate, responsible, puffer])
126+
}, [startDate, responsible, puffer, taskList]);
106127

107-
const resetValues = () => {
108-
window.sessionStorage.removeItem(startDateCacheKey);
109-
setStartDate(initialStartDate)
110-
111-
window.sessionStorage.removeItem(responsibleCacheKey);
112-
setResponsible(initialResponsible)
113-
114-
window.sessionStorage.removeItem(bufferCacheKey);
115-
setPuffer(0)
116-
117-
window.sessionStorage.removeItem(calendarPrefixCacheKey);
118-
setCalendarTitlePrefix('')
119-
}
120-
121-
const hasActiveCache = () => {
122-
return !!window.sessionStorage.getItem(startDateCacheKey)
123-
|| !!window.sessionStorage.getItem(responsibleCacheKey)
124-
|| !!window.sessionStorage.getItem(bufferCacheKey)
125-
|| !!window.sessionStorage.getItem(calendarPrefixCacheKey)
126-
}
128+
useEffect(() => {
129+
createTasks()
130+
}, [createTasks]);
127131

128132
useEffect(() => {
129133
const getTasks = async () => {
@@ -146,13 +150,13 @@ function CalendarForm() {
146150
}
147151

148152
loadCachedValues()
149-
getTasks().then(() => createTasks())
150-
}, [taskList, createTasks]);
153+
getTasks()
154+
}, []);
151155

152156
return (
153157
<div>
154158
<div className='calendar-form-container'>
155-
<form onSubmit={createTasks}>
159+
<form>
156160
<ul className='calendar-form'>
157161
<li>
158162
<label>
@@ -195,7 +199,6 @@ function CalendarForm() {
195199
</li>
196200
<li>
197201
<div style={buttonGroupStyle}>
198-
<button type="submit"> {t('calendarPage.ics.generate')}</button>
199202
{hasActiveCache() ?
200203
<button className={"as-link"}
201204
onClick={resetValues}>

0 commit comments

Comments
 (0)