diff options
Diffstat (limited to 'packages/ui/src/hooks')
| -rw-r--r-- | packages/ui/src/hooks/create-seen.ts | 20 | ||||
| -rw-r--r-- | packages/ui/src/hooks/index.ts | 1 |
2 files changed, 21 insertions, 0 deletions
diff --git a/packages/ui/src/hooks/create-seen.ts b/packages/ui/src/hooks/create-seen.ts new file mode 100644 index 000000000..c25726e75 --- /dev/null +++ b/packages/ui/src/hooks/create-seen.ts @@ -0,0 +1,20 @@ +import { createSignal, onCleanup, onMount } from "solid-js" +import { isServer } from "solid-js/web" + +export function createSeen(key: string, delay = 1000) { + // 1. Initialize state based on storage (default to true on server to avoid flash) + const storageKey = `app:seen:${key}` + const [hasSeen] = createSignal(!isServer && sessionStorage.getItem(storageKey) === "true") + + onMount(() => { + // 2. If we haven't seen it, mark it as seen for NEXT time + if (!hasSeen()) { + const timer = setTimeout(() => { + sessionStorage.setItem(storageKey, "true") + }, delay) + onCleanup(() => clearTimeout(timer)) + } + }) + + return hasSeen +} diff --git a/packages/ui/src/hooks/index.ts b/packages/ui/src/hooks/index.ts index 7eef78091..98b339cfa 100644 --- a/packages/ui/src/hooks/index.ts +++ b/packages/ui/src/hooks/index.ts @@ -1 +1,2 @@ export * from "./use-filtered-list" +export * from "./create-seen" |
