upgrade to tamagui v2 and guest pwa overhaul
This commit is contained in:
40
resources/js/guest-v2/services/statsApi.ts
Normal file
40
resources/js/guest-v2/services/statsApi.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { getDeviceId } from '../lib/device';
|
||||
import { fetchJson } from './apiClient';
|
||||
import type { EventStats } from './eventApi';
|
||||
|
||||
const statsCache = new Map<string, { etag: string | null; data: EventStats }>();
|
||||
|
||||
export async function fetchEventStats(eventToken: string): Promise<EventStats> {
|
||||
const cached = statsCache.get(eventToken);
|
||||
const response = await fetchJson<{ online_guests?: number; tasks_solved?: number; latest_photo_at?: string | null }>(
|
||||
`/api/v1/events/${encodeURIComponent(eventToken)}/stats`,
|
||||
{
|
||||
headers: {
|
||||
'X-Device-Id': getDeviceId(),
|
||||
},
|
||||
etag: cached?.etag ?? null,
|
||||
noStore: true,
|
||||
}
|
||||
);
|
||||
|
||||
if (response.notModified && cached) {
|
||||
return cached.data;
|
||||
}
|
||||
|
||||
const stats: EventStats = {
|
||||
onlineGuests: response.data?.online_guests ?? 0,
|
||||
tasksSolved: response.data?.tasks_solved ?? 0,
|
||||
latestPhotoAt: response.data?.latest_photo_at ?? null,
|
||||
};
|
||||
|
||||
statsCache.set(eventToken, { etag: response.etag, data: stats });
|
||||
return stats;
|
||||
}
|
||||
|
||||
export function clearStatsCache(eventToken?: string) {
|
||||
if (eventToken) {
|
||||
statsCache.delete(eventToken);
|
||||
return;
|
||||
}
|
||||
statsCache.clear();
|
||||
}
|
||||
Reference in New Issue
Block a user