Skip to content

Commit ee6ce3e

Browse files
Fix blinking badge not working (pt. 3)
For good this time I hope
1 parent a3798af commit ee6ce3e

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

src/lib/components/BlinkingBadge.svelte

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
11
<script lang="ts">
2+
import { onMount } from "svelte";
23
import { get } from "svelte/store";
3-
import { browser } from "$app/environment";
44
import { localStorageStore } from "$lib/localStorageStore";
55
66
/**
77
* The name of the localStorage item to get the date from.
88
*/
99
export let storedDateItem: string;
10+
/**
11+
* Whether to show the pulse animation.
12+
*/
13+
export let show = false;
1014
11-
let showPulse = false;
15+
let shouldShowPulse = false;
1216
13-
$: if (storedDateItem && browser) {
17+
onMount(() => {
1418
const storedDateStore = localStorageStore(storedDateItem, "");
15-
const storedDate = get(storedDateStore);
19+
const storedDate = get(storedDateStore).replace(/"/g, "");
1620
const lastVisitItem = localStorage.getItem("lastVisit");
1721
if (storedDate && lastVisitItem) {
18-
showPulse = new Date(storedDate) > new Date(lastVisitItem);
22+
shouldShowPulse = new Date(storedDate) > new Date(lastVisitItem);
1923
}
20-
}
24+
});
2125
</script>
2226

23-
{#if showPulse}
27+
{#if show && shouldShowPulse}
2428
<div class="relative inline-flex">
2529
<slot />
2630
<span class="absolute right-0 top-0 -mr-0.5 -mt-0.5 flex size-2.5">

src/routes/+page.svelte

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -262,23 +262,17 @@
262262
>
263263
<Tabs.List class="bg-input dark:bg-muted">
264264
{#each typedEntries(repos) as [id, { name }]}
265-
{#if !visitedTabs.includes(id) && id !== currentRepo}
266-
<BlinkingBadge storedDateItem="{id.toLowerCase()}MostRecentUpdate">
267-
<Tabs.Trigger
268-
class="data-[state=inactive]:text-foreground/60 data-[state=inactive]:hover:bg-background/50 data-[state=active]:hover:text-foreground/75 data-[state=inactive]:hover:text-foreground dark:data-[state=inactive]:hover:bg-background/25"
269-
value={id}
270-
>
271-
{name}
272-
</Tabs.Trigger>
273-
</BlinkingBadge>
274-
{:else}
265+
<BlinkingBadge
266+
storedDateItem="{id.toLowerCase()}MostRecentUpdate"
267+
show={!visitedTabs.includes(id) && id !== currentRepo}
268+
>
275269
<Tabs.Trigger
276270
class="data-[state=inactive]:text-foreground/60 data-[state=inactive]:hover:bg-background/50 data-[state=active]:hover:text-foreground/75 data-[state=inactive]:hover:text-foreground dark:data-[state=inactive]:hover:bg-background/25"
277271
value={id}
278272
>
279273
{name}
280274
</Tabs.Trigger>
281-
{/if}
275+
</BlinkingBadge>
282276
{/each}
283277
</Tabs.List>
284278
<div class="ml-auto flex items-center space-x-2 xs:ml-0">

0 commit comments

Comments
 (0)