From 091ff357661b02a9e5898bc4b35780b9f65e28af Mon Sep 17 00:00:00 2001 From: moonlitgrace Date: Wed, 18 Dec 2024 18:19:00 +0530 Subject: [PATCH] refactor: check valid src before rending avatar --- frontend/src/lib/components/ui/avatar.svelte | 16 +++++++++++++++- .../src/routes/(app)/q/[name]/+page.svelte | 18 +++++++++++++++--- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/frontend/src/lib/components/ui/avatar.svelte b/frontend/src/lib/components/ui/avatar.svelte index cab82270..61e8c137 100644 --- a/frontend/src/lib/components/ui/avatar.svelte +++ b/frontend/src/lib/components/ui/avatar.svelte @@ -7,6 +7,20 @@ }; let { src, class: klass }: Props = $props(); + + let valid_src = $state(false); + + $effect.pre(() => { + if (!src) { + valid_src = false; + return; + } + // create img instance + const img = new Image(); + img.onload = () => (valid_src = true); + img.onerror = () => (valid_src = false); + img.src = src; + });
- {#if src} + {#if valid_src} {:else} { + if (!authStore.state.is_authenticated) return false; + if (authStore.state.profile && quiblet) { + return quiblet.members?.includes(authStore.state.profile.id); + } + }); @@ -25,7 +34,10 @@ >
- +

q/{quiblet?.name}

@@ -34,7 +46,7 @@ Create Quib