From f63d42304d750048c8b8c7d6c3312654023f06dc Mon Sep 17 00:00:00 2001 From: SquidSpirit Date: Mon, 13 Oct 2025 19:43:48 +0800 Subject: [PATCH] feat: implement dashboard layout with navigation and routing; add button component for dashboard links --- frontend/src/app.css | 4 + .../components/ui/button/button.svelte | 82 +++++++++++++++++++ .../framework/components/ui/button/index.ts | 17 ++++ .../framework/ui/DashboardLinkButton.svelte | 20 +++++ .../framework/ui/DashboardNavbar.svelte | 15 ++++ .../dashboard/framework/ui/dashboardLink.ts | 4 + frontend/src/routes/dashboard/+layout.svelte | 12 ++- frontend/src/routes/dashboard/+page.server.ts | 10 +++ frontend/src/routes/dashboard/+page.svelte | 1 - .../src/routes/dashboard/image/+page.svelte | 1 + .../src/routes/dashboard/post/+page.svelte | 1 + 11 files changed, 165 insertions(+), 2 deletions(-) create mode 100644 frontend/src/lib/common/framework/components/ui/button/button.svelte create mode 100644 frontend/src/lib/common/framework/components/ui/button/index.ts create mode 100644 frontend/src/lib/dashboard/framework/ui/DashboardLinkButton.svelte create mode 100644 frontend/src/lib/dashboard/framework/ui/DashboardNavbar.svelte create mode 100644 frontend/src/lib/dashboard/framework/ui/dashboardLink.ts create mode 100644 frontend/src/routes/dashboard/+page.server.ts create mode 100644 frontend/src/routes/dashboard/image/+page.svelte create mode 100644 frontend/src/routes/dashboard/post/+page.svelte diff --git a/frontend/src/app.css b/frontend/src/app.css index 6709bec..de683ad 100644 --- a/frontend/src/app.css +++ b/frontend/src/app.css @@ -149,6 +149,10 @@ body { @apply bg-white font-sans text-base font-normal text-gray-700; } +button { + @apply cursor-pointer; +} + .container { @apply mx-auto max-w-screen-xl px-4 md:px-6; } diff --git a/frontend/src/lib/common/framework/components/ui/button/button.svelte b/frontend/src/lib/common/framework/components/ui/button/button.svelte new file mode 100644 index 0000000..92f6f84 --- /dev/null +++ b/frontend/src/lib/common/framework/components/ui/button/button.svelte @@ -0,0 +1,82 @@ + + + + +{#if href} + + {@render children?.()} + +{:else} + +{/if} diff --git a/frontend/src/lib/common/framework/components/ui/button/index.ts b/frontend/src/lib/common/framework/components/ui/button/index.ts new file mode 100644 index 0000000..fb585d7 --- /dev/null +++ b/frontend/src/lib/common/framework/components/ui/button/index.ts @@ -0,0 +1,17 @@ +import Root, { + type ButtonProps, + type ButtonSize, + type ButtonVariant, + buttonVariants, +} from "./button.svelte"; + +export { + Root, + type ButtonProps as Props, + // + Root as Button, + buttonVariants, + type ButtonProps, + type ButtonSize, + type ButtonVariant, +}; diff --git a/frontend/src/lib/dashboard/framework/ui/DashboardLinkButton.svelte b/frontend/src/lib/dashboard/framework/ui/DashboardLinkButton.svelte new file mode 100644 index 0000000..819b2ce --- /dev/null +++ b/frontend/src/lib/dashboard/framework/ui/DashboardLinkButton.svelte @@ -0,0 +1,20 @@ + + + + + diff --git a/frontend/src/lib/dashboard/framework/ui/DashboardNavbar.svelte b/frontend/src/lib/dashboard/framework/ui/DashboardNavbar.svelte new file mode 100644 index 0000000..a34a8a9 --- /dev/null +++ b/frontend/src/lib/dashboard/framework/ui/DashboardNavbar.svelte @@ -0,0 +1,15 @@ + + +
+
Dashboard
+
+ {#each links as link (link.href)} + + {/each} +
+
diff --git a/frontend/src/lib/dashboard/framework/ui/dashboardLink.ts b/frontend/src/lib/dashboard/framework/ui/dashboardLink.ts new file mode 100644 index 0000000..33ad8da --- /dev/null +++ b/frontend/src/lib/dashboard/framework/ui/dashboardLink.ts @@ -0,0 +1,4 @@ +export interface DashboardLink { + label: string; + href: string; +} diff --git a/frontend/src/routes/dashboard/+layout.svelte b/frontend/src/routes/dashboard/+layout.svelte index 5c2313c..7fe5833 100644 --- a/frontend/src/routes/dashboard/+layout.svelte +++ b/frontend/src/routes/dashboard/+layout.svelte @@ -9,6 +9,8 @@ import type { LayoutProps } from './$types'; import { StatusType } from '$lib/common/adapter/presenter/asyncState'; import ErrorPage from '$lib/common/framework/ui/ErrorPage.svelte'; + import DashboardNavbar from '$lib/dashboard/framework/ui/DashboardNavbar.svelte'; + import type { DashboardLink } from '$lib/dashboard/framework/ui/dashboardLink'; const { children }: LayoutProps = $props(); @@ -34,6 +36,11 @@ } return false; }); + + const links: DashboardLink[] = [ + { label: 'Image', href: '/dashboard/image' }, + { label: 'Post', href: '/dashboard/post' }, + ]; {#if isLoading} @@ -41,5 +48,8 @@ {:else if hasError} {:else} - {@render children()} +
+ + {@render children()} +
{/if} diff --git a/frontend/src/routes/dashboard/+page.server.ts b/frontend/src/routes/dashboard/+page.server.ts new file mode 100644 index 0000000..ff52206 --- /dev/null +++ b/frontend/src/routes/dashboard/+page.server.ts @@ -0,0 +1,10 @@ +import { redirect } from '@sveltejs/kit'; +import type { PageServerLoad } from './$types'; + +export const load: PageServerLoad = async ({ url }) => { + const { pathname } = url; + + if (pathname === '/dashboard') { + redirect(302, '/dashboard/image'); + } +}; diff --git a/frontend/src/routes/dashboard/+page.svelte b/frontend/src/routes/dashboard/+page.svelte index 9e01032..e69de29 100644 --- a/frontend/src/routes/dashboard/+page.svelte +++ b/frontend/src/routes/dashboard/+page.svelte @@ -1 +0,0 @@ -
Dashboard
diff --git a/frontend/src/routes/dashboard/image/+page.svelte b/frontend/src/routes/dashboard/image/+page.svelte new file mode 100644 index 0000000..df5f380 --- /dev/null +++ b/frontend/src/routes/dashboard/image/+page.svelte @@ -0,0 +1 @@ +
Image
diff --git a/frontend/src/routes/dashboard/post/+page.svelte b/frontend/src/routes/dashboard/post/+page.svelte new file mode 100644 index 0000000..fc9a374 --- /dev/null +++ b/frontend/src/routes/dashboard/post/+page.svelte @@ -0,0 +1 @@ +
Post