From e0fb1c93baa83b334d67eba2da7c99865c145fe9 Mon Sep 17 00:00:00 2001 From: Nikita Galaiko Date: Tue, 4 Apr 2023 16:01:28 +0200 Subject: [PATCH] fix cmdk project switching --- src/routes/projects/[projectId]/+page.svelte | 68 +++++++++----------- 1 file changed, 31 insertions(+), 37 deletions(-) diff --git a/src/routes/projects/[projectId]/+page.svelte b/src/routes/projects/[projectId]/+page.svelte index a7f76450f..30c4feae2 100644 --- a/src/routes/projects/[projectId]/+page.svelte +++ b/src/routes/projects/[projectId]/+page.svelte @@ -12,50 +12,44 @@ import { Button, Tooltip } from '$lib/components'; export let data: PageData; - const { activity, project, statuses, sessions, head } = data; + $: activity = derived(data.activity, (activity) => activity); + $: project = derived(data.project, (project) => project); + $: statuses = derived(data.statuses, (statuses) => statuses); + $: sessions = derived(data.sessions, (sessions) => sessions); + $: head = derived(data.head, (head) => head); - const recentSessions = derived( - sessions, - (sessions) => { - const lastFourDaysOfSessions = sessions.filter( - (session) => session.meta.startTimestampMs >= getTime(subDays(new Date(), 4)) - ); - if (lastFourDaysOfSessions.length >= 4) return lastFourDaysOfSessions; - return sessions.slice(0, 4); - }, - [] - ); + $: recentSessions = derived(sessions, (sessions) => { + const lastFourDaysOfSessions = sessions.filter( + (session) => session.meta.startTimestampMs >= getTime(subDays(new Date(), 4)) + ); + if (lastFourDaysOfSessions.length >= 4) return lastFourDaysOfSessions; + return sessions.slice(0, 4); + }); - const recentActivity = derived( - [activity, recentSessions], - ([activity, recentSessions]) => - activity - .filter((a) => a.timestampMs >= (recentSessions.at(-1)?.meta.startTimestampMs ?? 0)) - .sort((a, b) => b.timestampMs - a.timestampMs), - [] - ); + $: recentActivity = derived([activity, recentSessions], ([activity, recentSessions]) => { + return activity + .filter((a) => a.timestampMs >= (recentSessions.at(-1)?.meta.startTimestampMs ?? 0)) + .sort((a, b) => b.timestampMs - a.timestampMs); + }); - const sessionByDates = derived( - recentSessions, - (sessions) => - sessions.reduce((list: [Session[], Date][], session) => { - const date = startOfDay(new Date(session.meta.startTimestampMs)); - if (list.length === 0) { - list.push([[session], date]); + $: sessionByDates = derived(recentSessions, (sessions) => + sessions.reduce((list: [Session[], Date][], session) => { + const date = startOfDay(new Date(session.meta.startTimestampMs)); + if (list.length === 0) { + list.push([[session], date]); + } else { + const last = list[list.length - 1]; + if (isEqual(last[1], date)) { + last[0].push(session); } else { - const last = list[list.length - 1]; - if (isEqual(last[1], date)) { - last[0].push(session); - } else { - list.push([[session], date]); - } + list.push([[session], date]); } - return list; - }, []), - [] + } + return list; + }, []) ); - const filesActivityByDate = asyncDerived( + $: filesActivityByDate = asyncDerived( [project, sessionByDates], async ([project, sessionByDates]) => await Promise.all(