From 3227400958bcc2123ee6d8239b41d7eb2dbc8e2d Mon Sep 17 00:00:00 2001 From: Willie Date: Wed, 11 Mar 2026 21:39:12 +0800 Subject: [PATCH] refactor(ui): extract PageHeader component, tone down Badge and StatusBadge MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Extract shared PageHeader with icon/title/subtitle/actions props, replacing duplicated header markup across all 16 pages - Shrink Badge to text-xs with tighter padding for subtler appearance - Change StatusBadge normal states (merged/copied/linked) to default grey variant — only anomalies (warning/danger) use color - TargetsPage: move delete button to top-right, restore dashed separator between path and mode row --- ui/src/components/Badge.tsx | 2 +- ui/src/components/PageHeader.tsx | 28 ++++++++ ui/src/components/StatusBadge.tsx | 6 +- ui/src/pages/AuditPage.tsx | 55 +++++++------- ui/src/pages/AuditRulesPage.tsx | 116 +++++++++++++++--------------- ui/src/pages/BackupPage.tsx | 18 ++--- ui/src/pages/CollectPage.tsx | 13 +--- ui/src/pages/ConfigPage.tsx | 56 +++++++-------- ui/src/pages/DashboardPage.tsx | 14 +--- ui/src/pages/ExtrasPage.tsx | 30 ++++---- ui/src/pages/GitSyncPage.tsx | 32 ++++----- ui/src/pages/InstallPage.tsx | 13 +--- ui/src/pages/LogPage.tsx | 43 +++++------ ui/src/pages/SearchPage.tsx | 13 +--- ui/src/pages/SkillsPage.tsx | 18 ++--- ui/src/pages/SyncPage.tsx | 13 +--- ui/src/pages/TargetsPage.tsx | 56 +++++++-------- ui/src/pages/TrashPage.tsx | 17 +---- ui/src/pages/UpdatePage.tsx | 69 +++++++++--------- 19 files changed, 266 insertions(+), 346 deletions(-) create mode 100644 ui/src/components/PageHeader.tsx diff --git a/ui/src/components/Badge.tsx b/ui/src/components/Badge.tsx index f7f2a81f1..259dcdd6a 100644 --- a/ui/src/components/Badge.tsx +++ b/ui/src/components/Badge.tsx @@ -17,7 +17,7 @@ const variants: Record = { export default function Badge({ children, variant = 'default' }: BadgeProps) { return ( +

+ {icon} + {title} +

+ {subtitle &&

{subtitle}

} + + ); + + return ( +
+ {heading} + {actions &&
{actions}
} +
+ ); +} diff --git a/ui/src/components/StatusBadge.tsx b/ui/src/components/StatusBadge.tsx index 0adaf8216..a75c9b01c 100644 --- a/ui/src/components/StatusBadge.tsx +++ b/ui/src/components/StatusBadge.tsx @@ -1,9 +1,9 @@ import Badge from './Badge'; const statusVariant: Record = { - merged: 'success', - copied: 'success', - linked: 'success', + merged: 'default', + copied: 'default', + linked: 'default', 'not exist': 'warning', 'has files': 'info', conflict: 'danger', diff --git a/ui/src/pages/AuditPage.tsx b/ui/src/pages/AuditPage.tsx index 3c354c91c..f55068b1b 100644 --- a/ui/src/pages/AuditPage.tsx +++ b/ui/src/pages/AuditPage.tsx @@ -18,6 +18,7 @@ import { api } from '../api/client'; import type { AuditAllResponse, AuditResult, AuditFinding } from '../api/client'; import Card from '../components/Card'; import Button from '../components/Button'; +import PageHeader from '../components/PageHeader'; import Badge from '../components/Badge'; import { Select } from '../components/Input'; import EmptyState from '../components/EmptyState'; @@ -121,38 +122,30 @@ export default function AuditPage() { return (
{/* Header */} -
-
-

- - Security Audit -

-

- Scan installed skills for malicious patterns and security threats -

-
-
- - + + - - -
-
+ + } + /> {/* Loading / Progress */} {loading && ( diff --git a/ui/src/pages/AuditRulesPage.tsx b/ui/src/pages/AuditRulesPage.tsx index 22c80d97a..ec0510401 100644 --- a/ui/src/pages/AuditRulesPage.tsx +++ b/ui/src/pages/AuditRulesPage.tsx @@ -23,6 +23,7 @@ import { EditorView } from '@codemirror/view'; import { useQuery, useQueryClient, useMutation } from '@tanstack/react-query'; import Card from '../components/Card'; import Button from '../components/Button'; +import PageHeader from '../components/PageHeader'; import Badge from '../components/Badge'; import ConfirmDialog from '../components/ConfirmDialog'; import { Input } from '../components/Input'; @@ -290,70 +291,67 @@ export default function AuditRulesPage() { return (
{/* ─── Header ─── */} -
-
-
- - - -

- - Audit Rules -

-
-

- {isProjectMode - ? 'Browse and manage project-level audit rules' - : 'Browse and manage global audit rules'} -

-
-
- - {viewMode === 'structured' && stats.custom > 0 && ( +
+ + + +
+ } + title="Audit Rules" + subtitle={ + isProjectMode + ? 'Browse and manage project-level audit rules' + : 'Browse and manage global audit rules' + } + className="mb-6" + actions={ + <> - )} - {viewMode === 'yaml' && rawQuery.data?.exists && ( - <> - {dirty && ( - - unsaved changes - + {viewMode === 'structured' ? ( + <> Edit YAML + ) : ( + <> Rule Browser )} - + {viewMode === 'structured' && stats.custom > 0 && ( + - - )} -
-
+ )} + {viewMode === 'yaml' && rawQuery.data?.exists && ( + <> + {dirty && ( + + unsaved changes + + )} + + + )} + + } + /> {/* ─── Structured View ─── */} {viewMode === 'structured' && compiled.data && ( diff --git a/ui/src/pages/BackupPage.tsx b/ui/src/pages/BackupPage.tsx index 76efa41c2..b731aa0c5 100644 --- a/ui/src/pages/BackupPage.tsx +++ b/ui/src/pages/BackupPage.tsx @@ -17,6 +17,7 @@ import { queryKeys, staleTimes } from '../lib/queryKeys'; import { formatSize } from '../lib/format'; import Card from '../components/Card'; import Button from '../components/Button'; +import PageHeader from '../components/PageHeader'; import Badge from '../components/Badge'; import ConfirmDialog from '../components/ConfirmDialog'; import EmptyState from '../components/EmptyState'; @@ -170,18 +171,11 @@ export default function BackupPage() { return (
{/* Header */} -
-

- Backup & Restore -

-

- Create snapshots of your targets and restore them when needed -

-
+ } + title="Backup & Restore" + subtitle="Create snapshots of your targets and restore them when needed" + /> {/* Action Card */} diff --git a/ui/src/pages/CollectPage.tsx b/ui/src/pages/CollectPage.tsx index 6054e2b02..3ded506c9 100644 --- a/ui/src/pages/CollectPage.tsx +++ b/ui/src/pages/CollectPage.tsx @@ -15,6 +15,7 @@ import { XCircle, } from 'lucide-react'; import Card from '../components/Card'; +import PageHeader from '../components/PageHeader'; import Badge from '../components/Badge'; import Button from '../components/Button'; import EmptyState from '../components/EmptyState'; @@ -122,17 +123,7 @@ export default function CollectPage() { return (
- {/* Page header */} -
-

- Collect -

-

- Pull local skills from targets back to source -

-
+ } title="Collect" subtitle="Pull local skills from targets back to source" /> {/* Visual Pipeline (reverse direction) */}
diff --git a/ui/src/pages/ConfigPage.tsx b/ui/src/pages/ConfigPage.tsx index 2d617ee3c..21aba6b9f 100644 --- a/ui/src/pages/ConfigPage.tsx +++ b/ui/src/pages/ConfigPage.tsx @@ -1,11 +1,12 @@ import { useState, useEffect, useMemo } from 'react'; -import { Save, FileCode } from 'lucide-react'; +import { Save, FileCode, Settings } from 'lucide-react'; import CodeMirror from '@uiw/react-codemirror'; import { yaml } from '@codemirror/lang-yaml'; import { EditorView } from '@codemirror/view'; import { useQuery, useQueryClient } from '@tanstack/react-query'; import Card from '../components/Card'; import Button from '../components/Button'; +import PageHeader from '../components/PageHeader'; import { PageSkeleton } from '../components/Skeleton'; import { useToast } from '../components/Toast'; import { api } from '../api/client'; @@ -71,36 +72,31 @@ export default function ConfigPage() { return (
{/* Header */} -
-
-

- Config -

-

- {isProjectMode ? 'Edit your project configuration' : 'Edit your skillshare configuration'} -

-
-
- {dirty && ( - } + title="Config" + subtitle={isProjectMode ? 'Edit your project configuration' : 'Edit your skillshare configuration'} + actions={ + <> + {dirty && ( + + unsaved changes + + )} + -
-
+ + {saving ? 'Saving...' : 'Save'} + + + } + />
diff --git a/ui/src/pages/DashboardPage.tsx b/ui/src/pages/DashboardPage.tsx index 9a98e3b10..16a588c5b 100644 --- a/ui/src/pages/DashboardPage.tsx +++ b/ui/src/pages/DashboardPage.tsx @@ -17,6 +17,7 @@ import { ShieldCheck, ShieldAlert, FolderPlus, + LayoutDashboard, } from 'lucide-react'; import { useQuery, useQueryClient } from '@tanstack/react-query'; import { queryKeys, staleTimes } from '../lib/queryKeys'; @@ -27,6 +28,7 @@ import IconButton from '../components/IconButton'; import Skeleton from '../components/Skeleton'; import { PageSkeleton } from '../components/Skeleton'; import StatusBadge from '../components/StatusBadge'; +import PageHeader from '../components/PageHeader'; import ConfirmDialog from '../components/ConfirmDialog'; import { useToast } from '../components/Toast'; import { api } from '../api/client'; @@ -147,17 +149,7 @@ export default function DashboardPage() { return (
- {/* Page header */} -
-

- Dashboard -

-

- Your skill management overview at a glance -

-
+ } title="Dashboard" subtitle="Your skill management overview at a glance" /> {/* Stats grid */}
diff --git a/ui/src/pages/ExtrasPage.tsx b/ui/src/pages/ExtrasPage.tsx index 69db4837c..bcea1bec8 100644 --- a/ui/src/pages/ExtrasPage.tsx +++ b/ui/src/pages/ExtrasPage.tsx @@ -13,6 +13,7 @@ import DialogShell from '../components/DialogShell'; import { Input, Select } from '../components/Input'; import Badge from '../components/Badge'; import EmptyState from '../components/EmptyState'; +import PageHeader from '../components/PageHeader'; import ConfirmDialog from '../components/ConfirmDialog'; import { PageSkeleton } from '../components/Skeleton'; import { radius } from '../design'; @@ -322,14 +323,14 @@ export default function ExtrasPage() { return (
{/* Header */} -
-
-

- Extras -

-
+ } + title="Extras" + subtitle={isProjectMode + ? 'Sync arbitrary directories to project targets' + : 'Sync arbitrary directories to AI tool targets'} + actions={ + <> {extras.length > 0 && ( -
-
-

- {isProjectMode - ? 'Sync arbitrary directories to project targets' - : 'Sync arbitrary directories to AI tool targets'} -

-
+ + } + /> {/* Loading */} {isPending && } diff --git a/ui/src/pages/GitSyncPage.tsx b/ui/src/pages/GitSyncPage.tsx index 4701963f1..45d50865a 100644 --- a/ui/src/pages/GitSyncPage.tsx +++ b/ui/src/pages/GitSyncPage.tsx @@ -23,6 +23,7 @@ import Card from '../components/Card'; import Button from '../components/Button'; import { Input, Checkbox } from '../components/Input'; import Badge from '../components/Badge'; +import PageHeader from '../components/PageHeader'; import { PageSkeleton } from '../components/Skeleton'; import { useToast } from '../components/Toast'; @@ -145,18 +146,11 @@ export default function GitSyncPage() { return (
{/* Header */} -
-

- Git Sync -

-

- Push and pull your skills source directory via git -

-
+ } + title="Git Sync" + subtitle="Push and pull your skills source directory via git" + /> {/* Repo Status Card */} @@ -276,15 +270,14 @@ export default function GitSyncPage() { />
@@ -327,15 +320,14 @@ export default function GitSyncPage() { />
diff --git a/ui/src/pages/InstallPage.tsx b/ui/src/pages/InstallPage.tsx index 7ec1c7f54..c9387a14b 100644 --- a/ui/src/pages/InstallPage.tsx +++ b/ui/src/pages/InstallPage.tsx @@ -1,18 +1,11 @@ +import { Download } from 'lucide-react'; import InstallForm from '../components/InstallForm'; +import PageHeader from '../components/PageHeader'; export default function InstallPage() { return (
-
-

- Install Skill -

-

- Install a skill from a GitHub URL, owner/repo, or local path -

-
+ } title="Install Skill" subtitle="Install a skill from a GitHub URL, owner/repo, or local path" />
diff --git a/ui/src/pages/LogPage.tsx b/ui/src/pages/LogPage.tsx index c3c12ef4a..4e0a28ff3 100644 --- a/ui/src/pages/LogPage.tsx +++ b/ui/src/pages/LogPage.tsx @@ -6,6 +6,7 @@ import type { LogEntry, LogStatsResponse } from '../api/client'; import { queryKeys, staleTimes } from '../lib/queryKeys'; import Card from '../components/Card'; import Button from '../components/Button'; +import PageHeader from '../components/PageHeader'; import Badge from '../components/Badge'; import ConfirmDialog from '../components/ConfirmDialog'; import EmptyState from '../components/EmptyState'; @@ -661,31 +662,25 @@ export default function LogPage() { return (
{/* ─── Header ─── */} -
-
-

- - Operations & Audit Log -

-

- Persistent record of CLI and UI operations, including audit findings by skill -

-
-
- - {hasEntries && ( - - )} -
-
+ {hasEntries && ( + + )} + + } + /> {/* ─── Tabs ─── */}
diff --git a/ui/src/pages/SearchPage.tsx b/ui/src/pages/SearchPage.tsx index 65d736e20..535800f5b 100644 --- a/ui/src/pages/SearchPage.tsx +++ b/ui/src/pages/SearchPage.tsx @@ -2,6 +2,7 @@ import { useState, useCallback, useEffect, useRef, useMemo } from 'react'; import { Search, Star, Download, Globe, Database, Settings } from 'lucide-react'; import { useQueryClient } from '@tanstack/react-query'; import Card from '../components/Card'; +import PageHeader from '../components/PageHeader'; import Badge from '../components/Badge'; import Button from '../components/Button'; import { Input, Select } from '../components/Input'; @@ -317,17 +318,7 @@ export default function SearchPage() { return (
- {/* Header */} -
-

- Search Skills -

-

- Discover and install skills -

-
+ } title="Search Skills" subtitle="Discover and install skills" /> {/* Mode tabs */}
diff --git a/ui/src/pages/SkillsPage.tsx b/ui/src/pages/SkillsPage.tsx index 99a384752..ec88fb840 100644 --- a/ui/src/pages/SkillsPage.tsx +++ b/ui/src/pages/SkillsPage.tsx @@ -24,6 +24,7 @@ import { PageSkeleton } from '../components/Skeleton'; import EmptyState from '../components/EmptyState'; import Card from '../components/Card'; import Button from '../components/Button'; +import PageHeader from '../components/PageHeader'; import SegmentedControl from '../components/SegmentedControl'; import Pagination from '../components/Pagination'; import { api, type Skill } from '../api/client'; @@ -332,18 +333,11 @@ export default function SkillsPage() { return (
{/* Header */} -
-
-

- Skills -

-

- {skills.length} skill{skills.length !== 1 ? 's' : ''} installed -

-
-
+ } + title="Skills" + subtitle={`${skills.length} skill${skills.length !== 1 ? 's' : ''} installed`} + /> {/* Search + Sort row */}
diff --git a/ui/src/pages/SyncPage.tsx b/ui/src/pages/SyncPage.tsx index 87ae8bf93..9f4597c49 100644 --- a/ui/src/pages/SyncPage.tsx +++ b/ui/src/pages/SyncPage.tsx @@ -18,6 +18,7 @@ import { } from 'lucide-react'; import { Virtuoso } from 'react-virtuoso'; import Card from '../components/Card'; +import PageHeader from '../components/PageHeader'; import Badge from '../components/Badge'; import Button from '../components/Button'; import { useToast } from '../components/Toast'; @@ -125,17 +126,7 @@ export default function SyncPage() { return (
- {/* Page header */} -
-

- Sync -

-

- Push your skills from source to all configured targets -

-
+ } title="Sync" subtitle="Push your skills from source to all configured targets" /> {/* Visual Pipeline */}
diff --git a/ui/src/pages/TargetsPage.tsx b/ui/src/pages/TargetsPage.tsx index 26544d371..92e3cc696 100644 --- a/ui/src/pages/TargetsPage.tsx +++ b/ui/src/pages/TargetsPage.tsx @@ -11,6 +11,7 @@ import FilterTagInput from '../components/FilterTagInput'; import EmptyState from '../components/EmptyState'; import ConfirmDialog from '../components/ConfirmDialog'; import { PageSkeleton } from '../components/Skeleton'; +import PageHeader from '../components/PageHeader'; import { useToast } from '../components/Toast'; import { api } from '../api/client'; import type { AvailableTarget } from '../api/client'; @@ -109,35 +110,30 @@ export default function TargetsPage() { return (
{/* Header */} -
-
-

} + title="Targets" + subtitle={`${targets.length} target${targets.length !== 1 ? 's' : ''} configured`} + actions={ +

-

- {targets.length} target{targets.length !== 1 ? 's' : ''} configured -

-
- -
+ {adding ? null : } + {adding ? 'Cancel' : 'Add Target'} + + } + /> {/* Add target form */} {adding && ( @@ -335,7 +331,7 @@ export default function TargetsPage() { className={`!overflow-visible ${i % 2 === 0 ? 'rotate-[-0.2deg]' : 'rotate-[0.2deg]'}`} style={{ position: 'relative', zIndex: targets.length - i }} > -
+
@@ -351,7 +347,7 @@ export default function TargetsPage() { > {shortenHome(target.path)}

-
+