forge
Explore
Log in

Don't you dare go Hollow

🍞 global toast system replaces inline flash banners

Browse files at this commit

6cf99b1f583eafe92bd9229604692fca110cfd3eBurak BoduroğluParent: 3f5523c
  • feat
    • 🍞 global toast system replaces inline flash banners
Show full message
feat: 🍞 global toast system replaces inline flash banners
- new Toast component with Portal-based Toaster, auto-dismiss 3s
- showToast() API for one-liner success feedback anywhere
- createFlash refactored to delegate to showToast, page-level flash
  signal cleared so old Alert banners stay empty
src/components/layout/app-shell.tsxmodified+2 -0
@@ -7,6 +7,7 @@ import { SideNav } from "@/components/layout/side-nav";
77 import { SidebarAccount } from "@/components/layout/sidebar-account";
88 import { Button } from "@/components/ui/button";
99 import { IconPanelLeft, IconX } from "@/components/ui/icons";
10+import { Toaster } from "@/components/ui/toast";
1011 import { useAuth } from "@/stores/auth-context";
1112 import { usePreferences, useT } from "@/stores/preferences-context";
1213 import { cn } from "@/lib/cn";
@@ -128,6 +129,7 @@ export function AppShell(props: ParentProps) {
128129 <Show when={auth.user() && !wide()}>
129130 <MobileTabBar onMenu={() => setMobileOpen(true)} />
130131 </Show>
132+ <Toaster />
131133 </div>
132134 );
133135 }
src/components/ui/toast.tsxadded+49 -0
@@ -0,0 +1,49 @@
1+import { For, createSignal } from "solid-js";
2+import { Portal } from "solid-js/web";
3+import { IconCheck, IconX } from "@/components/ui/icons";
4+import { cn } from "@/lib/cn";
5+
6+type Toast = {
7+ id: number;
8+ title: string;
9+};
10+
11+const [toasts, setToasts] = createSignal<Toast[]>([]);
12+let nextId = 1;
13+
14+export function showToast(props: { title: string }) {
15+ const id = nextId++;
16+ setToasts((items) => [...items, { id, title: props.title }].slice(-4));
17+ window.setTimeout(() => dismissToast(id), 3000);
18+}
19+
20+function dismissToast(id: number) {
21+ setToasts((items) => items.filter((item) => item.id !== id));
22+}
23+
24+export function Toaster() {
25+ return (
26+ <Portal>
27+ <div class="pointer-events-none fixed inset-x-3 bottom-4 z-[80] flex flex-col items-end gap-2 sm:inset-x-auto sm:right-5 sm:w-96">
28+ <For each={toasts()}>
29+ {(toast) => (
30+ <div class="pointer-events-auto flex w-full items-start gap-3 rounded-xl border border-border bg-card px-3 py-3 text-card-foreground shadow-soft">
31+ <span class="mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded-full bg-emerald-500/10 text-emerald-700 dark:text-emerald-300">
32+ <IconCheck class="h-3.5 w-3.5" />
33+ </span>
34+ <p class="min-w-0 flex-1 text-sm font-medium leading-5">{toast.title}</p>
35+ <button
36+ type="button"
37+ class={cn("rounded-md p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground")}
38+ aria-label="Dismiss"
39+ onClick={() => dismissToast(toast.id)}
40+ >
41+ <IconX class="h-3.5 w-3.5" />
42+ </button>
43+ </div>
44+ )}
45+ </For>
46+ </div>
47+ </Portal>
48+ );
49+}
src/lib/flash.tsmodified+6 -13
@@ -1,18 +1,11 @@
1-import { createEffect, createSignal, onCleanup, type Accessor } from "solid-js";
1+import { createSignal, type Accessor } from "solid-js";
2+import { showToast } from "@/components/ui/toast";
23
3-/** Short-lived success banner; auto-clears after `ms` (default 3s). */
4-export function createFlash(ms = 3000): [Accessor<string>, (text: string) => void] {
4+/** Short-lived success feedback; page banners stay empty, global toast renders it. */
5+export function createFlash(_ms = 3000): [Accessor<string>, (text: string) => void] {
56 const [message, setMessage] = createSignal("");
6- const [tick, setTick] = createSignal(0);
7- createEffect(() => {
8- tick();
9- const text = message();
10- if (!text) return;
11- const id = window.setTimeout(() => setMessage(""), ms);
12- onCleanup(() => window.clearTimeout(id));
13- });
147 return [message, (text) => {
15- setMessage(text);
16- setTick((value) => value + 1);
8+ setMessage("");
9+ showToast({ title: text });
1710 }];
1811 }