Skip to content

Commit d0d4ef0

Browse files
committed
fix: online timeframe is now customizable
1 parent f0bcf16 commit d0d4ef0

1 file changed

Lines changed: 29 additions & 17 deletions

File tree

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
<script lang="ts">
22
import { page } from "$app/state"
33
import UUID from "$lib/components/UUID.svelte"
4-
import { formatNumber } from "$lib/utils"
54
import { SvelteDate } from "svelte/reactivity"
65
const { id } = $props()
76
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)
1110
1211
const { data, error: err } = await page.data.supabaseClient
1312
.schema("stats")
1413
.from("online")
1514
.select("user_id, last_seen", { count: "exact" })
1615
.eq("script_id", id)
17-
.gte("last_seen", thirtyDaysAgo.toISOString())
16+
.gte("last_seen", cutoffDate.toISOString())
1817
1918
if (err) {
2019
console.error(err)
@@ -25,6 +24,7 @@
2524
}
2625
2726
let show = $state(false)
27+
let timeframe: number = $state(5)
2828
</script>
2929

3030
<header class="my-8 flex flex-col gap-8 text-center">
@@ -33,18 +33,30 @@
3333
</button>
3434

3535
{#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>
4860
</div>
4961
{/if}
5062
</header>

0 commit comments

Comments
 (0)