From a891b13bcdd9e5450c287708ae7d4ed6b3d63715 Mon Sep 17 00:00:00 2001 From: Odyssey346 Date: Sat, 25 Feb 2023 14:25:39 +0100 Subject: [PATCH] Add user count Signed-off-by: Odyssey346 --- src/routes/pubnix/+page.server.ts | 1 + src/routes/pubnix/+page.svelte | 5 +++++ src/routes/pubnix/users/+page.svelte | 3 +++ 3 files changed, 9 insertions(+) diff --git a/src/routes/pubnix/+page.server.ts b/src/routes/pubnix/+page.server.ts index f48f33c..1c33249 100644 --- a/src/routes/pubnix/+page.server.ts +++ b/src/routes/pubnix/+page.server.ts @@ -9,6 +9,7 @@ export const load = (async () => { return { users: get(pubnixUsers), + onlineUserCount: get(pubnixUsers).length, ...meta } }) satisfies PageServerLoad; diff --git a/src/routes/pubnix/+page.svelte b/src/routes/pubnix/+page.svelte index 6b55f38..516dc41 100644 --- a/src/routes/pubnix/+page.svelte +++ b/src/routes/pubnix/+page.svelte @@ -5,6 +5,10 @@ import User, { type UserType } from "./User.svelte"; const isOnline = (user: UserType) => user.online; + + const onlineUserCount = data.users.users.filter(isOnline).length; + + const userCount = data.users.users.length;
@@ -33,6 +37,7 @@ {#if !data.users.error} {#if data.users.users.some(isOnline)} +

There are {onlineUserCount} users online out of {userCount} users.

{#each data.users.users as user} {#if user.online} diff --git a/src/routes/pubnix/users/+page.svelte b/src/routes/pubnix/users/+page.svelte index 6610b2e..87e75db 100644 --- a/src/routes/pubnix/users/+page.svelte +++ b/src/routes/pubnix/users/+page.svelte @@ -3,12 +3,15 @@ export let data: PageData; import User from "../User.svelte"; + + const userCount = data.users.users.length;

{data.title}

{#if !data.users.error} {#if data.users.users.length > 0} +

There are {userCount} users on the pubnix.

{#each data.users.users as user}