|
1 | 1 | <script lang="ts"> |
2 | 2 | import { page } from "$app/state" |
3 | 3 | import UUID from "$lib/components/UUID.svelte" |
4 | | - import { formatNumber } from "$lib/utils" |
5 | 4 | import { SvelteDate } from "svelte/reactivity" |
6 | 5 | const { id } = $props() |
7 | 6 |
|
8 | | - async function getOnline() { |
9 | | - const thirtyDaysAgo = new SvelteDate() |
10 | | - thirtyDaysAgo.setDate(thirtyDaysAgo.getDate() - 30) |
| 7 | + async function getOnline(minutes: number) { |
| 8 | + const cutoffDate = new SvelteDate() |
| 9 | + cutoffDate.setMinutes(cutoffDate.getMinutes() - minutes) |
11 | 10 |
|
12 | 11 | const { data, error: err } = await page.data.supabaseClient |
13 | 12 | .schema("stats") |
14 | 13 | .from("online") |
15 | 14 | .select("user_id, last_seen", { count: "exact" }) |
16 | 15 | .eq("script_id", id) |
17 | | - .gte("last_seen", thirtyDaysAgo.toISOString()) |
| 16 | + .gte("last_seen", cutoffDate.toISOString()) |
18 | 17 |
|
19 | 18 | if (err) { |
20 | 19 | console.error(err) |
|
25 | 24 | } |
26 | 25 |
|
27 | 26 | let show = $state(false) |
| 27 | + let timeframe: number = $state(5) |
28 | 28 | </script> |
29 | 29 |
|
30 | 30 | <header class="my-8 flex flex-col gap-8 text-center"> |
|
33 | 33 | </button> |
34 | 34 |
|
35 | 35 | {#if show} |
36 | | - <div class="flex flex-col rounded-md preset-outlined-surface-500 p-8"> |
37 | | - {#await getOnline()} |
38 | | - Loading... |
39 | | - {:then data} |
40 | | - Total users: {data.length} |
41 | | - {#each data as user} |
42 | | - <small class="mx-auto my-1 w-fit rounded-md preset-outlined-surface-500 p-2"> |
43 | | - <UUID uuid={user.user_id}></UUID> Last seen: |
44 | | - {new Date(user.last_seen).toLocaleString(navigator.language)} |
45 | | - </small> |
46 | | - {/each} |
47 | | - {/await} |
| 36 | + <div class="flex flex-col gap-6 rounded-md preset-outlined-surface-500 p-8"> |
| 37 | + <label class="label"> |
| 38 | + <span class="label-text">Timeframe:</span> |
| 39 | + <select class="mx-auto select w-fit" bind:value={timeframe}> |
| 40 | + <option value={5}>5 Minutes</option> |
| 41 | + <option value={24 * 60}>24 Hours</option> |
| 42 | + <option value={7 * 24 * 60}>7 Days</option> |
| 43 | + <option value={30 * 24 * 60}>30 Days</option> |
| 44 | + </select> |
| 45 | + </label> |
| 46 | + |
| 47 | + <div class="flex flex-col gap-2"> |
| 48 | + {#await getOnline(timeframe)} |
| 49 | + Loading... |
| 50 | + {:then data} |
| 51 | + Total users: {data.length} |
| 52 | + {#each data as user (user.user_id)} |
| 53 | + <small class="mx-auto my-1 w-fit rounded-md preset-outlined-surface-500 p-2"> |
| 54 | + <UUID uuid={user.user_id}></UUID> Last seen: |
| 55 | + {new Date(user.last_seen).toLocaleString(navigator.language)} |
| 56 | + </small> |
| 57 | + {/each} |
| 58 | + {/await} |
| 59 | + </div> |
48 | 60 | </div> |
49 | 61 | {/if} |
50 | 62 | </header> |
0 commit comments