From f1d34524f55ae2241aade905eadb3bf40a7d5ba5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Boduro=C4=9Flu?= <80620802+burakboduroglu@users.noreply.github.com> Date: Fri, 17 Jul 2026 20:01:31 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=E2=9C=A8=20empty-state=20CTAs=20and=20?= =?UTF-8?q?save=20flash=20banners=20-=20EmptyState=20component=20with=20op?= =?UTF-8?q?tional=20primary=20action=20-=20notes/courses/exams/events=20em?= =?UTF-8?q?pty=20lists=20show=20create=20CTA=20when=20allowed=20-=20create?= =?UTF-8?q?Flash=20helper=20+=20Alert=20success=20variant=20for=20short=20?= =?UTF-8?q?confirmations=20-=20i18n:=20common.created/deleted/saved=20(en/?= =?UTF-8?q?tr)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/notes/note-list.tsx | 15 ++++++++++----- src/components/ui/alert.tsx | 10 ++++++---- src/components/ui/empty-state.tsx | 28 ++++++++++++++++++++++++++++ src/i18n/messages.ts | 9 +++++++++ src/lib/flash.ts | 13 +++++++++++++ src/pages/courses-page.tsx | 26 ++++++++++++++++++++++++-- src/pages/events-page.tsx | 21 ++++++++++++++++++--- src/pages/exams-page.tsx | 27 +++++++++++++++++++++++++-- src/pages/notes-page.tsx | 27 ++++++++++++++++++++++----- 9 files changed, 155 insertions(+), 21 deletions(-) create mode 100644 src/components/ui/empty-state.tsx create mode 100644 src/lib/flash.ts diff --git a/src/components/notes/note-list.tsx b/src/components/notes/note-list.tsx index 94d00b6..ac85c84 100644 --- a/src/components/notes/note-list.tsx +++ b/src/components/notes/note-list.tsx @@ -1,11 +1,14 @@ -import { For, Show, createSignal } from "solid-js"; +import { For, Show, createSignal, type JSX } from "solid-js"; import type { Note } from "@/api/types"; import { NoteCard } from "@/components/notes/note-card"; import { NoteReaderPanel } from "@/components/notes/note-reader-panel"; +import { EmptyState } from "@/components/ui/empty-state"; export function NoteList(props: { notes: Note[]; - emptyLabel?: string; + emptyTitle: string; + emptyDescription?: string; + emptyAction?: JSX.Element; onUpdate: (id: string, values: { title: string; content: string }) => Promise; onDelete: (id: string) => Promise; }) { @@ -16,9 +19,11 @@ export function NoteList(props: { 0} fallback={ -
- {props.emptyLabel ?? ""} -
+ } >
    diff --git a/src/components/ui/alert.tsx b/src/components/ui/alert.tsx index 51049a2..e056f50 100644 --- a/src/components/ui/alert.tsx +++ b/src/components/ui/alert.tsx @@ -2,16 +2,18 @@ import type { ComponentProps, ParentProps } from "solid-js"; import { splitProps } from "solid-js"; import { cn } from "@/lib/cn"; -export function Alert(props: ParentProps & { variant?: "default" | "destructive" }>) { +export function Alert( + props: ParentProps & { variant?: "default" | "destructive" | "success" }>, +) { const [local, rest] = splitProps(props, ["class", "children", "variant"]); return ( + ); +} diff --git a/src/i18n/messages.ts b/src/i18n/messages.ts index a4e3e87..06dc0db 100644 --- a/src/i18n/messages.ts +++ b/src/i18n/messages.ts @@ -77,6 +77,9 @@ export type MessageKey = | "common.searchPlaceholder" | "common.all" | "common.saveAttendance" + | "common.created" + | "common.deleted" + | "common.saved" | "theme.light" | "theme.dark" | "theme.toggle" @@ -618,6 +621,9 @@ const en: Dict = { "common.searchPlaceholder": "Search…", "common.all": "All", "common.saveAttendance": "Save my attendance", + "common.created": "Created.", + "common.deleted": "Deleted.", + "common.saved": "Saved.", "theme.light": "Light", "theme.dark": "Dark", "theme.toggle": "Toggle theme", @@ -1171,6 +1177,9 @@ const tr: Dict = { "common.searchPlaceholder": "Ara…", "common.all": "Tümü", "common.saveAttendance": "Yoklamamı kaydet", + "common.created": "Oluşturuldu.", + "common.deleted": "Silindi.", + "common.saved": "Kaydedildi.", "theme.light": "Açık", "theme.dark": "Koyu", "theme.toggle": "Tema", diff --git a/src/lib/flash.ts b/src/lib/flash.ts new file mode 100644 index 0000000..a979749 --- /dev/null +++ b/src/lib/flash.ts @@ -0,0 +1,13 @@ +import { createEffect, createSignal, onCleanup, type Accessor, type Setter } from "solid-js"; + +/** Short-lived success banner; auto-clears after `ms` (default 3s). */ +export function createFlash(ms = 3000): [Accessor, Setter] { + const [message, setMessage] = createSignal(""); + createEffect(() => { + const text = message(); + if (!text) return; + const id = window.setTimeout(() => setMessage(""), ms); + onCleanup(() => window.clearTimeout(id)); + }); + return [message, setMessage]; +} diff --git a/src/pages/courses-page.tsx b/src/pages/courses-page.tsx index 90b69ad..0419f04 100644 --- a/src/pages/courses-page.tsx +++ b/src/pages/courses-page.tsx @@ -12,7 +12,8 @@ import { RouteGuard } from "@/components/layout/route-guard"; import { PageHeader } from "@/components/layout/page-header"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; -import { DataTableEmpty, DataTableFrame, DataTableSkeleton } from "@/components/ui/data-table"; +import { DataTableFrame, DataTableSkeleton } from "@/components/ui/data-table"; +import { EmptyState } from "@/components/ui/empty-state"; import { DataToolbar } from "@/components/ui/data-toolbar"; import { IconEye, IconPlus } from "@/components/ui/icons"; import { Input } from "@/components/ui/input"; @@ -23,6 +24,7 @@ import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@ import { TableRowActions } from "@/components/ui/table-row-actions"; import { Textarea } from "@/components/ui/textarea"; import { PaginationControls } from "@/components/ui/pagination-controls"; +import { createFlash } from "@/lib/flash"; import { loadListPage, totalPages as pagesOf } from "@/lib/list-page"; import { useAuth } from "@/stores/auth-context"; import { useT } from "@/stores/preferences-context"; @@ -49,6 +51,7 @@ function CoursesContent() { const [kind, setKind] = createSignal("course"); const [termId, setTermId] = createSignal(""); const [error, setError] = createSignal(""); + const [flash, setFlash] = createFlash(); const [pending, setPending] = createSignal(false); const [query, setQuery] = createSignal(""); const [termFilter, setTermFilter] = createSignal("all"); @@ -128,6 +131,7 @@ function CoursesContent() { setTermId(""); setShowForm(false); await refetch(); + setFlash(t("common.created")); } catch (err) { setError(formatApiError(err)); } finally { @@ -221,11 +225,29 @@ function CoursesContent() { } /> + + {flash()} + }> {formatApiError(list.error)} - 0} fallback={{t("courses.empty")}}> + 0} + fallback={ + setShowForm(true)}> + + {t("courses.create")} + + ) : undefined + } + /> + } + >
    diff --git a/src/pages/events-page.tsx b/src/pages/events-page.tsx index a1ea192..420371d 100644 --- a/src/pages/events-page.tsx +++ b/src/pages/events-page.tsx @@ -10,11 +10,13 @@ import { EventForm } from "@/components/events/event-form"; import { RouteGuard } from "@/components/layout/route-guard"; import { PageHeader } from "@/components/layout/page-header"; import { DataToolbar } from "@/components/ui/data-toolbar"; +import { EmptyState } from "@/components/ui/empty-state"; import { IconPlus } from "@/components/ui/icons"; import { PageSpinner } from "@/components/ui/page-spinner"; import { PaginationControls } from "@/components/ui/pagination-controls"; import { Select } from "@/components/ui/select"; import { SidePanel } from "@/components/ui/side-panel"; +import { createFlash } from "@/lib/flash"; import { formatDateTime } from "@/lib/format"; import { loadListPage, totalPages as pagesOf } from "@/lib/list-page"; import { hasMinRole } from "@/lib/roles"; @@ -36,6 +38,7 @@ function EventsContent() { const { locale } = usePreferences(); const t = useT(); const [error, setError] = createSignal(""); + const [flash, setFlash] = createFlash(); const [showForm, setShowForm] = createSignal(false); const [query, setQuery] = createSignal(""); const [timeFilter, setTimeFilter] = createSignal("all"); @@ -120,6 +123,7 @@ function EventsContent() { await postEvent(body); setShowForm(false); await refetch(); + setFlash(t("common.created")); } catch (err) { setError(formatApiError(err)); throw err; @@ -128,6 +132,9 @@ function EventsContent() { /> + + {flash()} + {error() &&

    {error()}

    }
    @@ -163,9 +170,17 @@ function EventsContent() { 0} fallback={ -
    - {t("events.empty")} -
    + setShowForm(true)}> + + {t("events.create")} + + ) : undefined + } + /> } >
    diff --git a/src/pages/exams-page.tsx b/src/pages/exams-page.tsx index 6a49953..562d5fe 100644 --- a/src/pages/exams-page.tsx +++ b/src/pages/exams-page.tsx @@ -13,7 +13,8 @@ import { PageHeader } from "@/components/layout/page-header"; import { Alert } from "@/components/ui/alert"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; -import { DataTableEmpty, DataTableFrame, DataTableSkeleton } from "@/components/ui/data-table"; +import { DataTableFrame, DataTableSkeleton } from "@/components/ui/data-table"; +import { EmptyState } from "@/components/ui/empty-state"; import { DataToolbar } from "@/components/ui/data-toolbar"; import { IconEdit, IconEye, IconPlus } from "@/components/ui/icons"; import { PaginationControls } from "@/components/ui/pagination-controls"; @@ -23,6 +24,7 @@ import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@ import { TableRowActions } from "@/components/ui/table-row-actions"; import { createNow } from "@/lib/create-now"; import { examKindLabel } from "@/lib/exam-labels"; +import { createFlash } from "@/lib/flash"; import { formatDateTime } from "@/lib/format"; import { loadListPage, totalPages as pagesOf } from "@/lib/list-page"; import { hasMinRole } from "@/lib/roles"; @@ -56,6 +58,7 @@ function ExamsContent() { const [selectedCourseId, setSelectedCourseId] = createSignal(""); const [editingExam, setEditingExam] = createSignal(null); const [page, setPage] = createSignal(0); + const [flash, setFlash] = createFlash(); const [courses] = createResource( () => (auth.user()?.role && auth.user()?.role !== "student" ? true : null), @@ -160,6 +163,7 @@ function ExamsContent() { }); setCreateOpen(false); await refetchExams(); + setFlash(t("common.created")); }; const updateExam = async (values: ExamFormValues) => { @@ -168,6 +172,7 @@ function ExamsContent() { await patchExamById(exam.id, values); setEditingExam(null); await refetchExams(); + setFlash(t("common.saved")); }; return ( @@ -238,11 +243,29 @@ function ExamsContent() { } /> + + {flash()} + }> {formatApiError(list.error)} - 0} fallback={{t("exams.empty")}}> + 0} + fallback={ + setCreateOpen(true)}> + + {t("exams.create")} + + ) : undefined + } + /> + } + > diff --git a/src/pages/notes-page.tsx b/src/pages/notes-page.tsx index 71e2d80..47e6dfe 100644 --- a/src/pages/notes-page.tsx +++ b/src/pages/notes-page.tsx @@ -15,6 +15,7 @@ import { IconPlus } from "@/components/ui/icons"; import { PageSpinner } from "@/components/ui/page-spinner"; import { PaginationControls } from "@/components/ui/pagination-controls"; import { SidePanel } from "@/components/ui/side-panel"; +import { createFlash } from "@/lib/flash"; import { loadListPage, totalPages as pagesOf } from "@/lib/list-page"; import { useT } from "@/stores/preferences-context"; @@ -31,6 +32,7 @@ export default function NotesPage() { function NotesContent() { const t = useT(); const [error, setError] = createSignal(""); + const [flash, setFlash] = createFlash(); const [createOpen, setCreateOpen] = createSignal(false); const [page, setPage] = createSignal(0); @@ -50,11 +52,12 @@ function NotesContent() { const totalPages = createMemo(() => pagesOf(total(), NOTE_PAGE_SIZE)); const safePage = createMemo(() => Math.min(page(), totalPages() - 1)); - const wrap = async (fn: () => Promise) => { + const wrap = async (fn: () => Promise, okMessage: string) => { setError(""); try { await fn(); await refetch(); + setFlash(okMessage); } catch (err) { setError(formatApiError(err)); } @@ -101,13 +104,20 @@ function NotesContent() { } await refetch(); setCreateOpen(false); - if (failedUploads > 0) setError(t("notes.fileUploadPartial", { count: failedUploads })); + if (failedUploads > 0) { + setError(t("notes.fileUploadPartial", { count: failedUploads })); + return; + } + setFlash(t("common.created")); }} />
    + + {flash()} + {error() &&

    {error()}

    } }> @@ -116,16 +126,23 @@ function NotesContent() { setCreateOpen(true)}> + + {t("notes.new")} + + } onUpdate={(id, values) => wrap(async () => { await patchNoteById(id, values); - }) + }, t("common.saved")) } onDelete={(id) => wrap(async () => { await deleteNoteById(id); - }) + }, t("common.deleted")) } /> NOTE_PAGE_SIZE}>