From 6de1d0f2f1e739a67e504d619c0ee6c228b1dfcb Mon Sep 17 00:00:00 2001 From: oppiliappan Date: Fri, 28 Aug 2026 11:01:54 +0100 Subject: [PATCH] web/components: improve loading state for star button Signed-off-by: oppiliappan --- .../components/repo/StarButton.stories.svelte | 138 ++++++++++++++++++ web/src/lib/components/repo/StarButton.svelte | 77 ++++++---- 2 files changed, 185 insertions(+), 30 deletions(-) create mode 100644 web/src/lib/components/repo/StarButton.stories.svelte diff --git a/web/src/lib/components/repo/StarButton.stories.svelte b/web/src/lib/components/repo/StarButton.stories.svelte new file mode 100644 index 000000000..75e244297 --- /dev/null +++ b/web/src/lib/components/repo/StarButton.stories.svelte @@ -0,0 +1,138 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/web/src/lib/components/repo/StarButton.svelte b/web/src/lib/components/repo/StarButton.svelte index 4637000bf..215d6ca78 100644 --- a/web/src/lib/components/repo/StarButton.svelte +++ b/web/src/lib/components/repo/StarButton.svelte @@ -2,11 +2,14 @@ import { resolve } from "$app/paths"; import { page } from "$app/state"; import Star from "$icon/star"; + import TriangleAlert from "$icon/triangle-alert"; import { getAuth } from "$lib/auth.svelte"; import { loginWithReturn } from "$lib/auth/guards"; import { createStar, deleteStar } from "$lib/api/graph"; import Button from "$lib/components/ui/Button.svelte"; import ButtonGroup from "$lib/components/ui/ButtonGroup.svelte"; + import Spinner from "$lib/components/ui/Spinner.svelte"; + import Tooltip from "$lib/components/ui/Tooltip.svelte"; import { getProfileCounts } from "$lib/components/profile/counts.svelte"; import { createOptimisticRelation, createOptimisticCount } from "$lib/optimistic.svelte"; import { formatCount } from "$lib/format"; @@ -83,6 +86,14 @@ }); const starred = $derived(relation.active); const failed = $derived(relation.failed || starCount.failed); + $effect(() => { + if (!failed) return; + const timer = setTimeout(() => { + relation.resetFailure(); + starCount.resetFailure(); + }, 2000); + return () => clearTimeout(timer); + }); // if signed out, sends you to log in first, then back here const loginHref = $derived( resolve(loginWithReturn(page.url.pathname + page.url.search) as "/login") @@ -122,34 +133,40 @@
- - - - - {#if failed} -

- Something went wrong. Try again. -

- {/if} + + + + + +
-- 2.51.2