Skip to content

Commit

Permalink
sort sessions (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
180079995 authored Dec 25, 2024
1 parent 673d969 commit b2664f2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
11 changes: 7 additions & 4 deletions src/routes/dashboard/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,13 @@
sessionSnapshot.forEach(async (docu) => {
const session = await getDoc(docu.ref.parent.parent!);
const host = await getDoc(doc(db, 'profiles', session.data()?.host));
sessions.update((value) => [
...value,
[host.data()?.displayName, session.id, session.data() as Session]
]);
let hoster = '';
if (!host.exists()) {
hoster = 'Unknown';
} else {
hoster = host.data()?.displayName;
}
sessions.update((value) => [...value, [hoster, session.id, session.data() as Session]]);
});
}
Expand Down
25 changes: 20 additions & 5 deletions src/routes/dashboard/recent/participant/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { writable } from 'svelte/store';
import { writable, derived } from 'svelte/store';
import { Card, Button } from 'flowbite-svelte';
import { MessageSquarePlus } from 'lucide-svelte';
import {
Expand All @@ -15,10 +15,17 @@
import { profile } from '$lib/stores/profile';
import { db } from '$lib/firebase';
import type { Session } from '$lib/schema/session';
import { onMount } from 'svelte';
let { data } = $props();
let sessions = writable<[string, string, Session][]>([]);
let unsoredsessions = writable<[string, string, Session][]>([]);
let sessions = derived(unsoredsessions, ($unsoredsessions) =>
$unsoredsessions.sort(
(a, b) => (b[2].createdAt as Timestamp).toMillis() - (a[2].createdAt as Timestamp).toMillis()
)
);
async function getSessions() {
const sessionQuery = query(
Expand All @@ -29,14 +36,22 @@
sessionSnapshot.forEach(async (docu) => {
const session = await getDoc(docu.ref.parent.parent!);
const host = await getDoc(doc(db, 'profiles', session.data()?.host));
sessions.update((value) => [
let hoster = '';
if (!host.exists()) {
hoster = 'Unknown';
} else {
hoster = host.data()?.displayName;
}
unsoredsessions.update((value) => [
...value,
[host.data()?.displayName, session.id, session.data() as Session]
[hoster, session.id, session.data() as Session]
]);
});
}
getSessions();
onMount(() => {
getSessions();
});
</script>

<svelte:head>
Expand Down

0 comments on commit b2664f2

Please sign in to comment.