mirror of
https://github.com/bartvdbraak/omnidash.git
synced 2025-04-27 15:31:21 +00:00
feat: add shadcn styling and conditional nav
This commit is contained in:
parent
8b51e6816e
commit
6ebca59554
15 changed files with 200 additions and 102 deletions
|
@ -3,12 +3,14 @@ import { Loader2 } from 'lucide-svelte';
|
|||
import { GithubLogo, VercelLogo, LinkedinLogo } from 'radix-icons-svelte';
|
||||
import Logo from './logo.svelte';
|
||||
import Svelte from './svelte.svelte';
|
||||
import Microsoft from './microsoft.svelte';
|
||||
|
||||
export type Icon = LucideIcon;
|
||||
|
||||
export const Icons = {
|
||||
logo: Logo,
|
||||
gitHub: GithubLogo,
|
||||
microsoft: Microsoft,
|
||||
svelte: Svelte,
|
||||
vercel: VercelLogo,
|
||||
linkedIn: LinkedinLogo,
|
||||
|
|
12
apps/web/src/lib/components/site/icons/microsoft.svelte
Normal file
12
apps/web/src/lib/components/site/icons/microsoft.svelte
Normal file
|
@ -0,0 +1,12 @@
|
|||
<svg
|
||||
stroke="currentColor"
|
||||
fill="currentColor"
|
||||
stroke-width="0"
|
||||
version="1.2"
|
||||
baseProfile="tiny"
|
||||
viewBox="0 0 24 24"
|
||||
{...$$restProps}
|
||||
><path
|
||||
d="M10 12.5c0-.3-.2-.5-.5-.5h-6c-.3 0-.5.2-.5.5v5c0 .3.2.5.5.6l6 .7c.3 0 .5-.2.5-.4v-5.9zM11.5 12c-.3 0-.5.2-.5.5v5.9c0 .3.2.5.5.6l9 1c.3 0 .5-.2.5-.4v-7c0-.3-.2-.5-.5-.5l-9-.1zM10 4.7c0-.3-.2-.5-.5-.4l-6 .7c-.3 0-.5.2-.5.5v5c0 .3.2.5.5.5h6c.3 0 .5-.2.5-.5v-5.8zM11.5 4.1c-.3 0-.5.3-.5.6v5.9c0 .3.2.5.5.5h9c.3 0 .5-.2.5-.5v-7c0-.3-.2-.5-.5-.4l-9 .9z"
|
||||
></path></svg
|
||||
>
|
After Width: | Height: | Size: 519 B |
|
@ -2,16 +2,18 @@
|
|||
import { page } from '$app/stores';
|
||||
import { cn } from '$lib/utils';
|
||||
import { navConfig } from '$lib/config/nav';
|
||||
|
||||
export let authenticated = false;
|
||||
</script>
|
||||
|
||||
<div class="mr-4 hidden md:flex">
|
||||
<nav class="flex items-center space-x-6 text-sm font-medium">
|
||||
{#each navConfig.mainNav as navItem, index (navItem + index.toString())}
|
||||
{#if navItem.href}
|
||||
{#if navItem.href && (navItem.auth == authenticated || navItem.always)}
|
||||
<a
|
||||
href={navItem.href}
|
||||
class={cn(
|
||||
'transition-colors hover:text-foreground/80',
|
||||
'hover:text-foreground/80 transition-colors',
|
||||
$page.url.pathname === navItem.href ? 'text-foreground' : 'text-foreground/60'
|
||||
)}
|
||||
>
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
import MobileLink from './mobile-link.svelte';
|
||||
|
||||
let open = false;
|
||||
export let authenticated = false;
|
||||
</script>
|
||||
|
||||
<Sheet.Root bind:open>
|
||||
|
@ -30,7 +31,7 @@
|
|||
<div class="my-4 h-[calc(100vh-8rem)] overflow-auto pl-1 pt-10">
|
||||
<div class="flex flex-col space-y-3">
|
||||
{#each navConfig.mainNav as navItem, index (navItem + index.toString())}
|
||||
{#if navItem.href}
|
||||
{#if navItem.href && (navItem.auth == authenticated || navItem.always)}
|
||||
<MobileLink href={navItem.href} bind:open class="pt-2 text-5xl font-bold">
|
||||
{navItem.title}
|
||||
</MobileLink>
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<script lang="ts">
|
||||
import { Icons, ModeToggle, MainNav, MobileNav } from '$lib/components/site';
|
||||
|
||||
export let authenticated = false;
|
||||
</script>
|
||||
|
||||
<header
|
||||
|
@ -10,12 +12,12 @@
|
|||
<span class="sr-only">Logo (return home)</span>
|
||||
<Icons.logo />
|
||||
</a>
|
||||
<MainNav />
|
||||
<MainNav {authenticated}/>
|
||||
<div class="flex flex-1 items-center justify-between space-x-2 sm:space-x-4 md:justify-end">
|
||||
<nav class="flex">
|
||||
<ModeToggle />
|
||||
</nav>
|
||||
</div>
|
||||
<MobileNav />
|
||||
<MobileNav {authenticated}/>
|
||||
</div>
|
||||
</header>
|
||||
|
|
|
@ -9,28 +9,34 @@ export const navConfig: NavConfig = {
|
|||
mainNav: [
|
||||
{
|
||||
title: 'Home',
|
||||
href: '/'
|
||||
},
|
||||
{
|
||||
title: 'Login',
|
||||
href: '/login'
|
||||
},
|
||||
{
|
||||
title: 'Register',
|
||||
href: '/register'
|
||||
href: '/',
|
||||
always: true
|
||||
},
|
||||
{
|
||||
title: 'Dashboard',
|
||||
href: '/dashboard'
|
||||
href: '/dashboard',
|
||||
auth: true
|
||||
},
|
||||
{
|
||||
title: 'Settings',
|
||||
href: '/settings'
|
||||
href: '/settings',
|
||||
auth: true
|
||||
},
|
||||
{
|
||||
title: 'Login',
|
||||
href: '/login',
|
||||
auth: false,
|
||||
},
|
||||
{
|
||||
title: 'Register',
|
||||
href: '/register',
|
||||
auth: false,
|
||||
},
|
||||
{
|
||||
title: 'Logout',
|
||||
href: '/logout'
|
||||
}
|
||||
href: '/logout',
|
||||
auth: true
|
||||
},
|
||||
],
|
||||
sidebarNav: []
|
||||
};
|
||||
|
|
|
@ -3,6 +3,8 @@ import type { Icons } from '$lib/components/site/icons';
|
|||
export type NavItem = {
|
||||
title: string;
|
||||
href: string;
|
||||
auth?: boolean;
|
||||
always?: boolean;
|
||||
disabled?: boolean;
|
||||
external?: boolean;
|
||||
icon?: keyof typeof Icons;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { error, redirect } from '@sveltejs/kit';
|
||||
|
||||
export const actions = {
|
||||
login: async ({ request, locals }: { request: Request; locals: App.Locals }) => {
|
||||
default: async ({ request, locals }: { request: Request; locals: App.Locals }) => {
|
||||
const body = Object.fromEntries(await request.formData());
|
||||
|
||||
try {
|
||||
|
@ -21,4 +21,4 @@ export const actions = {
|
|||
|
||||
throw redirect(303, '/');
|
||||
}
|
||||
};
|
||||
};
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
</p>
|
||||
</div>
|
||||
<div class={cn('grid gap-6')} {...$$restProps}>
|
||||
<form action="?/login" method="POST">
|
||||
<form method="POST">
|
||||
<div class="grid gap-2">
|
||||
<div class="grid gap-1">
|
||||
<Label class="sr-only" for="email">Email</Label>
|
||||
|
@ -66,10 +66,10 @@
|
|||
{#if isLoading}
|
||||
<Icons.spinner class="mr-2 h-4 w-4 animate-spin" />
|
||||
{:else}
|
||||
<Icons.gitHub class="mr-2 h-4 w-4" />
|
||||
<Icons.microsoft class="mr-2 h-4 w-4" />
|
||||
{/if}
|
||||
{' '}
|
||||
GitHub
|
||||
Microsoft
|
||||
</Button>
|
||||
</div>
|
||||
<p class="text-muted-foreground px-8 text-center text-sm">
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { redirect } from '@sveltejs/kit';
|
||||
|
||||
export const actions = {
|
||||
register: async ({ request, locals }: { request: Request; locals: App.Locals }) => {
|
||||
default: async ({ request, locals }: { request: Request; locals: App.Locals }) => {
|
||||
if (locals.pocketBase.authStore.isValid) {
|
||||
return;
|
||||
}
|
||||
|
@ -37,6 +37,10 @@ export const actions = {
|
|||
throw new Error('Password must be at least 8 characters in length');
|
||||
}
|
||||
|
||||
if (password !== formData.get('passwordConfirm')) {
|
||||
throw new Error('Passwords do not match');
|
||||
}
|
||||
|
||||
await locals.pocketBase.collection('users').create({
|
||||
email,
|
||||
password,
|
||||
|
|
|
@ -1,39 +1,84 @@
|
|||
<div class="flex flex-col items-center h-full w-full">
|
||||
<h2 class="mt-2 text-center text-3xl font-bold tracking-tight text-base-content">
|
||||
Register for an account
|
||||
</h2>
|
||||
<p class="text-center mt-1">
|
||||
Or <a href="/login" class="text-primary font-medium hover:cursor-pointer hover:underline"
|
||||
>sign in</a
|
||||
> if you already have an account.
|
||||
</p>
|
||||
<form action="?/register" method="POST" class="flex flex-col items-center space-y-2 w-full pt-4">
|
||||
<div class="form-control w-full max-w-md">
|
||||
<label for="name" class="label font-medium pb-1">
|
||||
<span class="label-text">Name</span>
|
||||
</label>
|
||||
<input type="text" name="name" class="input input-bordered w-full max-w-md" />
|
||||
<script lang="ts">
|
||||
import { Icons } from '$lib/components/site/icons';
|
||||
import { Button } from '$lib/components/ui/button';
|
||||
import { Input } from '$lib/components/ui/input';
|
||||
import { Label } from '$lib/components/ui/label';
|
||||
import { cn } from '$lib/utils';
|
||||
|
||||
let isLoading = false;
|
||||
</script>
|
||||
|
||||
<div class="lg:p-8">
|
||||
<div class="mx-auto flex w-full flex-col justify-center space-y-6 sm:w-[350px]">
|
||||
<div class="flex flex-col space-y-2 text-center">
|
||||
<h1 class="text-2xl font-semibold tracking-tight">Create your account</h1>
|
||||
<p class="text-muted-foreground text-sm">
|
||||
Enter your details below to create a new account
|
||||
</p>
|
||||
</div>
|
||||
<div class="form-control w-full max-w-md">
|
||||
<label for="email" class="label font-medium pb-1">
|
||||
<span class="label-text">Email</span>
|
||||
</label>
|
||||
<input type="email" name="email" class="input input-bordered w-full max-w-md" />
|
||||
<div class={cn('grid gap-6')} {...$$restProps}>
|
||||
<form method="POST">
|
||||
<div class="grid gap-2">
|
||||
<div class="grid gap-1">
|
||||
<Label class="sr-only" for="email">Name</Label>
|
||||
<Input
|
||||
id="name"
|
||||
name="name"
|
||||
placeholder="Michael Jackson"
|
||||
type="name"
|
||||
disabled={isLoading}
|
||||
/>
|
||||
</div>
|
||||
<div class="grid gap-1">
|
||||
<Label class="sr-only" for="email">Email</Label>
|
||||
<Input
|
||||
id="email"
|
||||
name="email"
|
||||
placeholder="michael@jackson.com"
|
||||
type="email"
|
||||
autocapitalize="none"
|
||||
autocomplete="email"
|
||||
autocorrect="off"
|
||||
disabled={isLoading}
|
||||
/>
|
||||
</div>
|
||||
<div class="grid gap-1">
|
||||
<Label class="sr-only" for="password">Password</Label>
|
||||
<Input id="password" name="password" type="password" disabled={isLoading} placeholder="Password" />
|
||||
</div>
|
||||
<div class="grid gap-1">
|
||||
<Label class="sr-only" for="password">Confirm Password</Label>
|
||||
<Input id="password" name="passwordConfirm" type="password" disabled={isLoading} placeholder="Confirm password" />
|
||||
</div>
|
||||
<Button type="submit" disabled={isLoading}>
|
||||
{#if isLoading}
|
||||
<Icons.spinner class="mr-2 h-4 w-4 animate-spin" />
|
||||
{/if}
|
||||
Sign In
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
<div class="relative">
|
||||
<div class="absolute inset-0 flex items-center">
|
||||
<span class="w-full border-t" />
|
||||
</div>
|
||||
<div class="relative flex justify-center text-xs uppercase">
|
||||
<span class="bg-background text-muted-foreground px-2"> Or continue with </span>
|
||||
</div>
|
||||
</div>
|
||||
<Button variant="outline" type="button" disabled={isLoading}>
|
||||
{#if isLoading}
|
||||
<Icons.spinner class="mr-2 h-4 w-4 animate-spin" />
|
||||
{:else}
|
||||
<Icons.microsoft class="mr-2 h-4 w-4" />
|
||||
{/if}
|
||||
{' '}
|
||||
Microsoft
|
||||
</Button>
|
||||
</div>
|
||||
<div class="form-control w-full max-w-md">
|
||||
<label for="password" class="label font-medium pb-1">
|
||||
<span class="label-text">Password</span>
|
||||
</label>
|
||||
<input type="password" name="password" class="input input-bordered w-full max-w-md" />
|
||||
</div>
|
||||
<div class="form-control w-full max-w-md">
|
||||
<label for="passwordConfirm" class="label font-medium pb-1">
|
||||
<span class="label-text">Confirm Password</span>
|
||||
</label>
|
||||
<input type="password" name="passwordConfirm" class="input input-bordered w-full max-w-md" />
|
||||
</div>
|
||||
<div class="w-full max-w-md pt-2">
|
||||
<button type="submit" class="btn btn-primary w-full">Register</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<p class="text-muted-foreground px-8 text-center text-sm">
|
||||
Or <a class="text-primary underline" href="/login">sign in</a> if you already have an account.<br />
|
||||
Forgot password? <a class="text-primary underline" href="/reset-password">Reset password.</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { error } from '@sveltejs/kit';
|
||||
|
||||
export const actions = {
|
||||
resetPassword: async ({ request, locals }: { request: Request; locals: App.Locals }) => {
|
||||
default: async ({ request, locals }: { request: Request; locals: App.Locals }) => {
|
||||
const body = Object.fromEntries(await request.formData());
|
||||
|
||||
try {
|
||||
|
|
|
@ -1,44 +1,56 @@
|
|||
<script>
|
||||
<script lang="ts">
|
||||
import { Icons } from '$lib/components/site/icons';
|
||||
import { Button } from '$lib/components/ui/button';
|
||||
import { Input } from '$lib/components/ui/input';
|
||||
import { Label } from '$lib/components/ui/label';
|
||||
import { cn } from '$lib/utils';
|
||||
import { CheckCircled } from "radix-icons-svelte";
|
||||
import * as Alert from "$lib/components/ui/alert";
|
||||
|
||||
let isLoading = false;
|
||||
export let form;
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col items-center h-full w-full">
|
||||
<h2 class="mt-2 text-center text-3xl font-bold tracking-tight text-base-content">
|
||||
Reset Your Password
|
||||
</h2>
|
||||
<p class="text-center mt-1">We'll send you an email with a link to reset your password.</p>
|
||||
<form
|
||||
action="?/resetPassword"
|
||||
method="POST"
|
||||
class="flex flex-col items-center space-y-2 w-full pt-4"
|
||||
>
|
||||
<div class="form-control w-full max-w-md">
|
||||
<label for="email" class="label font-medium pb-1">
|
||||
<span class="label-text">Email</span>
|
||||
</label>
|
||||
<input type="email" name="email" class="input input-bordered w-full max-w-md" />
|
||||
<div class="lg:p-8">
|
||||
<div class="mx-auto flex w-full flex-col justify-center space-y-6 sm:w-[350px]">
|
||||
<div class="flex flex-col space-y-2 text-center">
|
||||
<h1 class="text-2xl font-semibold tracking-tight">Reset password</h1>
|
||||
<p class="text-muted-foreground text-sm">
|
||||
We'll send you an email with a link to reset your password.
|
||||
</p>
|
||||
</div>
|
||||
<div class="w-full max-w-md pt-2">
|
||||
<button type="submit" class="btn btn-primary w-full">Request Password Reset</button>
|
||||
</div>
|
||||
{#if form?.success}
|
||||
<div class="alert alert-success shadow-lg w-full max-w-md">
|
||||
<div>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
class="stroke-current flex-shrink-0 h-6 w-6"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
><path
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
stroke-width="2"
|
||||
d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"
|
||||
/></svg
|
||||
>
|
||||
<span>An email has been sent to reset your password!</span>
|
||||
<div class={cn('grid gap-6')} {...$$restProps}>
|
||||
<form method="POST">
|
||||
<div class="grid gap-2">
|
||||
<div class="grid gap-1">
|
||||
<Label class="sr-only" for="email">Email</Label>
|
||||
<Input
|
||||
id="email"
|
||||
name="email"
|
||||
placeholder="michael@hihi.com"
|
||||
type="email"
|
||||
autocapitalize="none"
|
||||
autocomplete="email"
|
||||
autocorrect="off"
|
||||
disabled={isLoading}
|
||||
/>
|
||||
</div>
|
||||
<Button type="submit" disabled={isLoading}>
|
||||
{#if isLoading}
|
||||
<Icons.spinner class="mr-2 h-4 w-4 animate-spin" />
|
||||
{/if}
|
||||
Sign In
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</form>
|
||||
</div>
|
||||
{#if form?.success}
|
||||
<Alert.Root variant="default" class="mt-2">
|
||||
<CheckCircled class="h-4 w-4" />
|
||||
<Alert.Description
|
||||
>An email has been sent to reset your password.</Alert.Description
|
||||
>
|
||||
</Alert.Root>
|
||||
{/if}
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
7
apps/web/src/routes/+layout.server.ts
Normal file
7
apps/web/src/routes/+layout.server.ts
Normal file
|
@ -0,0 +1,7 @@
|
|||
import type { PageServerLoad } from './$types';
|
||||
|
||||
export const load: PageServerLoad = (async ({ locals }: { locals: App.Locals }) => {
|
||||
return {
|
||||
authenticated: locals.pocketBase.authStore.isValid
|
||||
};
|
||||
});
|
|
@ -4,6 +4,9 @@
|
|||
import { ModeWatcher } from 'mode-watcher';
|
||||
import '../app.pcss';
|
||||
import { fade } from 'svelte/transition';
|
||||
import type { PageData } from './$types';
|
||||
|
||||
export let data: PageData;
|
||||
</script>
|
||||
|
||||
<ModeWatcher />
|
||||
|
@ -11,7 +14,7 @@
|
|||
<Metadata />
|
||||
|
||||
<div class="relative flex min-h-screen flex-col" id="page">
|
||||
<SiteNavBar />
|
||||
<SiteNavBar authenticated={data.authenticated} />
|
||||
<main class="container relative mb-4 max-w-[980px] flex-1 mt-12">
|
||||
<!-- {#key data.url} -->
|
||||
<div in:fade={{ duration: 200, delay: 100 }} out:fade={{ duration: 100 }}>
|
||||
|
|
Loading…
Reference in a new issue