Skip to content

Commit

Permalink
Fix a bug regarding the new grouping
Browse files Browse the repository at this point in the history
  • Loading branch information
Dlurak committed Sep 10, 2024
1 parent 2b60e71 commit b81c3cf
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
11 changes: 10 additions & 1 deletion src/lib/components/calendar/List/List.svelte
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
<script lang="ts" context="module">
function groupEvents(events: Calendar[]) {
const grouped = groupBy(events, ({ beginning }) => stringify(beginning));
const values = Object.values(grouped);
return values.map((x) => x!);
}
</script>

<script lang="ts">
import Store from '$lib/components/utils/Store.svelte';
import type { Calendar } from '$lib/dlool/calendar/list';
Expand All @@ -7,7 +15,8 @@
import CalEventListBox from './CalEventListBox.svelte';
export let events: Calendar[];
$: grouped = Object.values(groupBy(events, ({ beginning }) => stringify(beginning)));
$: grouped = groupEvents(events);
</script>

{#each grouped as day, index}
Expand Down
5 changes: 4 additions & 1 deletion src/lib/utils/objects/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ type Key = string | number | symbol;
* @param {(item: T) => K} keySelector A function that extracts the key for grouping from each element.
* @returns {Record<K, T[]>} An object where keys are derived from elements and values are arrays of elements with the same key.
*/
export function groupBy<T, K extends Key>(array: T[], keySelector: (item: T) => K): Record<K, T[]> {
export function groupBy<T, K extends Key>(
array: T[],
keySelector: (item: T) => K
): Partial<Record<K, T[]>> {
return array.reduce(
(result, item) => {
const key = keySelector(item);
Expand Down
4 changes: 2 additions & 2 deletions src/routes/homework/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@
})}
<div class="h-full w-full">
<AssignmentGrid
assignments={grouped.upcoming}
overdueAssignments={grouped.overdue}
assignments={grouped.upcoming ?? []}
overdueAssignments={grouped.overdue ?? []}
school={data.query.school}
on:delete={invalidateAll}
on:update={invalidateAll}
Expand Down

0 comments on commit b81c3cf

Please sign in to comment.