Skip to content

Commit 703cf4f

Browse files
committed
feat: added loading and updating indication for calendar tasks
1 parent 6f4b53d commit 703cf4f

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

src/pages/calendar/calendar.less

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
}
1818

1919
.calendar-table {
20-
2120
ul {
2221
list-style-type: none;
2322
padding-left: 2px;
@@ -53,6 +52,10 @@
5352
}
5453
}
5554

55+
.calendar-table.is-updating table {
56+
opacity: 0.5;
57+
}
58+
5659
.calendar-form-container {
5760
hr {
5861
border: 0.5px solid #8c3c4f

src/pages/calendar/components/CalendarForm.tsx

+17-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { TaskT } from './Task';
77
import client from '../../../client';
88
import { addDays, format, isValid, parse, startOfDay } from "date-fns";
99
import Downloads from "./Downloads";
10+
import Loading from "../../../components/loading/Loading";
1011

1112
type Roles = {
1213
rolle: string
@@ -34,12 +35,14 @@ function CalendarForm() {
3435

3536
const { t } = useTranslation()
3637

38+
const [isLoadingTasks, setIsLoadingTasks] = useState<boolean>(true)
39+
const [isUpdatingTasks, setIsUpdatingTasks] = useState<boolean>(true)
3740
const [startDate, setStartDate] = useState<string>(initialStartDate)
3841
const [parsedStartDate, setParsedStartDate] = useState<Date>(new Date())
3942
const [responsible, setResponsible] = useState<string>(initialResponsible)
4043
const [puffer, setPuffer] = useState<number>(0)
4144
const [calendarTitlePrefix, setCalendarTitlePrefix] = useState<string>('')
42-
const [taskList, setTaskList] = useState<Task[]>([])
45+
const [taskList, setTaskList] = useState<Task[] | undefined>(undefined)
4346
const [tasks, setTasks] = useState<TaskT[]>([])
4447

4548
const onStartDateChanged = (e: ChangeEvent<HTMLInputElement>) => {
@@ -97,10 +100,13 @@ function CalendarForm() {
97100

98101
useEffect(() => {
99102
const isValidDate = isValid(parsedStartDate)
100-
if (!isValidDate) {
103+
if (!isValidDate || !taskList) {
101104
return
102105
}
103106

107+
// Introduce pseudo loading time so that the user sees that something is updating
108+
setIsUpdatingTasks(true);
109+
104110
const filteredTasks = taskList.filter((task: Task) => {
105111
const rollen = task.responsible.map((resp) => resp.rolle)
106112
return responsible === 'all'
@@ -128,13 +134,18 @@ function CalendarForm() {
128134
})
129135
.sort((a: TaskT, b: TaskT) => a.deadline.getTime() - b.deadline.getTime())
130136

131-
setTasks(tasks)
137+
// Update tasks after the pseudo loading time
138+
setTimeout(() => {
139+
setTasks(tasks)
140+
setIsUpdatingTasks(false)
141+
}, 500)
132142
}, [parsedStartDate, responsible, puffer, taskList]);
133143

134144
useEffect(() => {
135145
const getTasks = async () => {
136146
const response = await client.get('/tasks?_locale=' + i18n.language)
137147
setTaskList(response.data)
148+
setIsLoadingTasks(false)
138149
}
139150

140151
const loadCachedValues = () => {
@@ -214,7 +225,9 @@ function CalendarForm() {
214225
<Downloads startDate={parsedStartDate} tasks={tasks} calendarTitlePrefix={calendarTitlePrefix}/>
215226
</div>
216227

217-
<CalendarTable tasks={tasks} prefix={calendarTitlePrefix}/>
228+
<Loading isLoading={isLoadingTasks || !taskList}/>
229+
{!isLoadingTasks && !!taskList
230+
&& <CalendarTable tasks={tasks} prefix={calendarTitlePrefix} isUpdating={isUpdatingTasks}/>}
218231
</div>
219232
);
220233
}

src/pages/calendar/components/CalendarTable.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { useTranslation } from "react-i18next";
55
type Props = {
66
tasks: TaskT[]
77
prefix: string
8+
isUpdating: boolean;
89
}
910

1011
function CalendarTable(props: Props) {
@@ -18,7 +19,7 @@ function CalendarTable(props: Props) {
1819
})
1920

2021
return (
21-
<div className='calendar-table table-overflow'>
22+
<div className={`calendar-table table-overflow ${props.isUpdating ? 'is-updating' : ''}`}>
2223
<table>
2324
<thead>
2425
<tr>

0 commit comments

Comments
 (0)