Skip to content

Commit

Permalink
refactor(das-dui-tool): Refactor timetableData calculation in Timetab…
Browse files Browse the repository at this point in the history
…leGrid.tsx
  • Loading branch information
Florian325 committed Apr 10, 2024
1 parent 9c57cd6 commit 1f7087b
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions apps/das-dui-tool/components/timetable/TimetableGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,19 @@ const TimetableGrid: FC<TimetableGridProps> = ({ data }) => {
TimetableTimeResponse.TimetableTime[] | null
>(["timetableTimes"])

const timetableData = useMemo(() => {
const td: { [key: string]: TimetableResponse.Lesson[] } = {}
data.lessons.forEach((item) =>
td[item.meta.displayname_hour]
? td[item.meta.displayname_hour].push(item)
: (td[item.meta.displayname_hour] = [item])
)
return td
}, [data])
const timetableData = useMemo(
() =>
data.lessons.reduce(
(x, y) => {
;(x[y.meta.displayname_hour] =
x[y.meta.displayname_hour] || []).push(y)

return x
},
{} as { [key: string]: TimetableResponse.Lesson[] }
),
[data.last_updated_at]
)

return (
<>
Expand Down

0 comments on commit 1f7087b

Please sign in to comment.