frontend for xcvr appview

add ban page

+54
+27
src/routes/b/[id]/+page.svelte
··· 1 + <script lang="ts"> 2 + import type { PageProps } from "./$types"; 3 + import { dumbAbsoluteTimestamp, smartAbsoluteTimestamp } from "$lib/utils"; 4 + let { data }: PageProps = $props(); 5 + const fetchhandle = async (did: string) => { 6 + return fetch(`https://plc.directory/${did}`).then((res) => res.json()); 7 + }; 8 + </script> 9 + 10 + {#if data.ban} 11 + {#await fetchhandle(data.ban.did)} 12 + fetching handle 13 + {:then result} 14 + {result.alsoKnownAs[0]} 15 + {:catch} 16 + error fetching handle 17 + {/await} 18 + ({data.ban.did}) was banned {smartAbsoluteTimestamp(data.ban.bannedAt)} 19 + {#if data.ban.reason} 20 + for {data.ban.reason}. 21 + {/if} 22 + {#if data.ban.till} 23 + the ban will end on {dumbAbsoluteTimestamp(data.ban.till)}. 24 + {/if} 25 + {:else} 26 + i can't find ban 27 + {/if}
+27
src/routes/b/[id]/+page.ts
··· 1 + import type { PageLoad } from './$types' 2 + 3 + export const load: PageLoad = async ({ params, fetch }) => { 4 + const base = import.meta.env.VITE_API_URL 5 + const query = `?id=${params.id}` 6 + 7 + const fetchSafely = async (url: string) => { 8 + try { 9 + const res = await fetch(url) 10 + return res.ok ? await res.json() : null 11 + } catch { 12 + return null 13 + } 14 + } 15 + 16 + const [ban] = await Promise.allSettled([ 17 + fetchSafely(`${base}/oauth/ban${query}`), 18 + ]).then(results => 19 + results.map(result => 20 + result.status === 'fulfilled' ? result.value : null 21 + ) 22 + ) 23 + 24 + return { 25 + ban, 26 + } 27 + }