fix cmdk project switching

This commit is contained in:
Nikita Galaiko 2023-04-04 16:01:28 +02:00
parent 22365668e0
commit e0fb1c93ba

View File

@ -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(