File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Load Diff This file was deleted.
Original file line number Diff line number Diff line change 11<script lang =" ts" >
2- import { metaApi } from ' $lib/api' ;
3- import { handleApiError } from ' $lib/errorhandling/apiErrorHandling' ;
4- import { onMount } from ' svelte' ;
5-
6- let deviceCount = $state (0 );
7-
8- onMount (async () => {
9- try {
10- const { data } = await metaApi .publicGetOnlineDevicesStatistics ();
11- deviceCount = data .devicesOnline ;
12- } catch (err ) {
13- handleApiError (err );
14- }
15- });
2+ let { data } = $props ();
163 </script >
174
185<section class =" flex flex-col items-center justify-center h-full text-white text-center space-y-6" >
229 </span >
2310 <p class =" text-lg md:text-2xl opacity-75" >
2411 The go-to platform for safe, reliable, real low-latency remote shocking.<br />
25- <span class ="font-semibold" >{deviceCount }</span > people online right now.
12+ {#if data .ok }
13+ <span class ="font-semibold" >{data .deviceCount }</span > people online right now.
14+ {/if }
2615 </p >
2716 <div class =" flex space-x-4 pt-8 text-sm opacity-75" >
2817 <a href =" https://openshock.org" target =" _blank" rel =" noopener" class =" hover:underline" >
Original file line number Diff line number Diff line change 1+ import { metaApi } from '$lib/api' ;
2+
3+ export const ssr = true ;
4+ export const prerender = false ;
5+
6+ export async function load ( { setHeaders } ) : Promise < { ok : false , error : string } | { ok : true , deviceCount : number } > {
7+ setHeaders ( {
8+ 'cache-control' : 'public, max-age=300'
9+ } )
10+
11+ let deviceCount : number ;
12+
13+ try {
14+ const { data } = await metaApi . publicGetOnlineDevicesStatistics ( ) ;
15+
16+ deviceCount = data . devicesOnline ;
17+ } catch ( e ) {
18+ console . error ( e ) ;
19+
20+ return {
21+ ok : false ,
22+ error : 'Failed to fetch device count' ,
23+ } ;
24+ }
25+
26+ return { ok : true , deviceCount } ;
27+ }
Original file line number Diff line number Diff line change @@ -3,6 +3,8 @@ import { goto } from '$app/navigation';
33import { accountV1Api } from '$lib/api' ;
44import { destroyAuth } from '$lib/init' ;
55
6+ export const prerender = false ;
7+
68export async function load ( ) {
79 if ( ! browser ) return ; // Do not run the following on server
810
Original file line number Diff line number Diff line change 1- // Set the default for the application
2- export const ssr = false ; // Only this file and pages under it in browser
31export const prerender = true ;
You can’t perform that action at this time.
0 commit comments