From 6cf99b1f583eafe92bd9229604692fca110cfd3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Boduro=C4=9Flu?= <80620802+burakboduroglu@users.noreply.github.com> Date: Sun, 19 Jul 2026 22:33:34 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8D=9E=20global=20toast=20system?= =?UTF-8?q?=20replaces=20inline=20flash=20banners=20-=20new=20Toast=20comp?= =?UTF-8?q?onent=20with=20Portal-based=20Toaster,=20auto-dismiss=203s=20-?= =?UTF-8?q?=20showToast()=20API=20for=20one-liner=20success=20feedback=20a?= =?UTF-8?q?nywhere=20-=20createFlash=20refactored=20to=20delegate=20to=20s?= =?UTF-8?q?howToast,=20page-level=20flash=20=20=20signal=20cleared=20so=20?= =?UTF-8?q?old=20Alert=20banners=20stay=20empty?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/layout/app-shell.tsx | 2 ++ src/components/ui/toast.tsx | 49 +++++++++++++++++++++++++++++ src/lib/flash.ts | 19 ++++------- 3 files changed, 57 insertions(+), 13 deletions(-) create mode 100644 src/components/ui/toast.tsx diff --git a/src/components/layout/app-shell.tsx b/src/components/layout/app-shell.tsx index 2a50805..6f1414a 100644 --- a/src/components/layout/app-shell.tsx +++ b/src/components/layout/app-shell.tsx @@ -7,6 +7,7 @@ import { SideNav } from "@/components/layout/side-nav"; import { SidebarAccount } from "@/components/layout/sidebar-account"; import { Button } from "@/components/ui/button"; import { IconPanelLeft, IconX } from "@/components/ui/icons"; +import { Toaster } from "@/components/ui/toast"; import { useAuth } from "@/stores/auth-context"; import { usePreferences, useT } from "@/stores/preferences-context"; import { cn } from "@/lib/cn"; @@ -128,6 +129,7 @@ export function AppShell(props: ParentProps) { setMobileOpen(true)} /> + ); } diff --git a/src/components/ui/toast.tsx b/src/components/ui/toast.tsx new file mode 100644 index 0000000..a059e2e --- /dev/null +++ b/src/components/ui/toast.tsx @@ -0,0 +1,49 @@ +import { For, createSignal } from "solid-js"; +import { Portal } from "solid-js/web"; +import { IconCheck, IconX } from "@/components/ui/icons"; +import { cn } from "@/lib/cn"; + +type Toast = { + id: number; + title: string; +}; + +const [toasts, setToasts] = createSignal([]); +let nextId = 1; + +export function showToast(props: { title: string }) { + const id = nextId++; + setToasts((items) => [...items, { id, title: props.title }].slice(-4)); + window.setTimeout(() => dismissToast(id), 3000); +} + +function dismissToast(id: number) { + setToasts((items) => items.filter((item) => item.id !== id)); +} + +export function Toaster() { + return ( + +
+ + {(toast) => ( +
+ + + +

{toast.title}

+ +
+ )} +
+
+
+ ); +} diff --git a/src/lib/flash.ts b/src/lib/flash.ts index 5e84486..922eaaf 100644 --- a/src/lib/flash.ts +++ b/src/lib/flash.ts @@ -1,18 +1,11 @@ -import { createEffect, createSignal, onCleanup, type Accessor } from "solid-js"; +import { createSignal, type Accessor } from "solid-js"; +import { showToast } from "@/components/ui/toast"; -/** Short-lived success banner; auto-clears after `ms` (default 3s). */ -export function createFlash(ms = 3000): [Accessor, (text: string) => void] { +/** Short-lived success feedback; page banners stay empty, global toast renders it. */ +export function createFlash(_ms = 3000): [Accessor, (text: string) => void] { const [message, setMessage] = createSignal(""); - const [tick, setTick] = createSignal(0); - createEffect(() => { - tick(); - const text = message(); - if (!text) return; - const id = window.setTimeout(() => setMessage(""), ms); - onCleanup(() => window.clearTimeout(id)); - }); return [message, (text) => { - setMessage(text); - setTick((value) => value + 1); + setMessage(""); + showToast({ title: text }); }]; }