Admin polish: stability fixes, schema security, consistent UI + sidebar #1
4 changed files with 181 additions and 113 deletions
|
|
@ -4,6 +4,17 @@
|
|||
themes: light --default;
|
||||
}
|
||||
|
||||
/* Admin UI theme: DaisyUI light with a fixed sage primary. Deliberately NOT
|
||||
tied to the site's Globals → Colors (those only apply inside /preview), so
|
||||
a light brand colour can't make admin buttons unreadable. #647556 on white
|
||||
text is ~5:1 contrast (WCAG AA). */
|
||||
@plugin 'daisyui/theme' {
|
||||
name: 'light';
|
||||
default: true;
|
||||
--color-primary: #647556;
|
||||
--color-primary-content: #ffffff;
|
||||
}
|
||||
|
||||
@theme {
|
||||
--font-sans: 'DM Sans', ui-sans-serif, system-ui, sans-serif;
|
||||
--font-serif: 'Playfair Display', Georgia, serif;
|
||||
|
|
|
|||
|
|
@ -1,13 +1,29 @@
|
|||
<script lang="ts">
|
||||
import '../app.css';
|
||||
import favicon from '$lib/assets/favicon.svg';
|
||||
import { page } from '$app/state';
|
||||
import { createBasketStore, setBasketContext } from '$lib/basket.svelte';
|
||||
import { onMount } from 'svelte';
|
||||
|
||||
let { children, data } = $props();
|
||||
let importStatus = $state<{ ok: boolean; message: string } | null>(null);
|
||||
let { children } = $props();
|
||||
let importStatus = $state<{ ok: boolean; message: string; errors?: string[] } | null>(null);
|
||||
let importing = $state(false);
|
||||
|
||||
// Routes rendered without the admin shell: the login screen, and the
|
||||
// preview iframe (which must look like the public site, not the admin).
|
||||
const BARE_ROUTES = ['/login', '/preview'];
|
||||
let bare = $derived(BARE_ROUTES.includes(page.url.pathname));
|
||||
|
||||
const navLinks = [
|
||||
{ href: '/pages', label: 'Pages' },
|
||||
{ href: '/calendar', label: 'Calendar' },
|
||||
{ href: '/items', label: 'Items' },
|
||||
{ href: '/slots', label: 'Slots' },
|
||||
{ href: '/orders', label: 'Orders' },
|
||||
{ href: '/emails', label: 'Emails' },
|
||||
{ href: '/globals', label: 'Globals' }
|
||||
];
|
||||
const isActive = (href: string) => page.url.pathname === href || page.url.pathname.startsWith(`${href}/`);
|
||||
|
||||
// One basket store per layout instance — provided to all children
|
||||
// (preview iframe block renderers). Never module-level state.
|
||||
// Admin doesn't have a real basket; pass null so the store starts empty.
|
||||
|
|
@ -34,12 +50,21 @@
|
|||
const input = event.target as HTMLInputElement;
|
||||
const file = input.files?.[0];
|
||||
if (!file) return;
|
||||
if (!confirm(`Import "${file.name}"? Pages, globals and events with the same slug/key/name will be overwritten.`)) {
|
||||
input.value = '';
|
||||
return;
|
||||
}
|
||||
|
||||
importing = true;
|
||||
importStatus = null;
|
||||
try {
|
||||
const text = await file.text();
|
||||
const json = JSON.parse(text);
|
||||
let json: unknown;
|
||||
try {
|
||||
json = JSON.parse(text);
|
||||
} catch {
|
||||
throw new Error('The file is not valid JSON.');
|
||||
}
|
||||
const res = await fetch('/api/import', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
|
|
@ -51,8 +76,13 @@
|
|||
}
|
||||
const result = await res.json();
|
||||
const msg = `Imported ${result.pagesImported} page(s), ${result.globalsImported} global(s), ${result.eventsImported || 0} event(s), ${result.imagesUploaded} image(s).`;
|
||||
importStatus = { ok: true, message: result.errors?.length ? msg + ` ${result.errors.length} error(s).` : msg };
|
||||
setTimeout(() => location.reload(), 1500);
|
||||
if (result.errors?.length) {
|
||||
// Keep the message up so the errors can be read; no auto-reload.
|
||||
importStatus = { ok: false, message: `${msg} ${result.errors.length} error(s) — reload to see the imported content.`, errors: result.errors };
|
||||
} else {
|
||||
importStatus = { ok: true, message: msg };
|
||||
setTimeout(() => location.reload(), 1500);
|
||||
}
|
||||
} catch (e) {
|
||||
importStatus = { ok: false, message: `Import error: ${e instanceof Error ? e.message : String(e)}` };
|
||||
} finally {
|
||||
|
|
@ -60,19 +90,6 @@
|
|||
input.value = '';
|
||||
}
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
// Apply saved colors so the preview iframe matches the public site.
|
||||
if (data.colors) {
|
||||
const root = document.documentElement;
|
||||
root.style.setProperty('--color-bg', data.colors.background);
|
||||
root.style.setProperty('--color-heading', data.colors.heading);
|
||||
root.style.setProperty('--color-subheading', data.colors.subheading);
|
||||
root.style.setProperty('--color-text', data.colors.text);
|
||||
root.style.setProperty('--color-primary', data.colors.primary);
|
||||
root.style.setProperty('--color-accent', data.colors.accent);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
|
|
@ -80,48 +97,55 @@
|
|||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
</svelte:head>
|
||||
|
||||
<div class="min-h-screen bg-base-200">
|
||||
<div class="navbar bg-base-100 shadow-sm">
|
||||
<div class="flex-1">
|
||||
<a class="btn btn-ghost text-xl" href="/pages">Massage CMS</a>
|
||||
</div>
|
||||
<div class="flex-none gap-2">
|
||||
<a class="btn btn-ghost" href="/pages">Pages</a>
|
||||
<a class="btn btn-ghost" href="/calendar">Calendar</a>
|
||||
<a class="btn btn-ghost" href="/items">Items</a>
|
||||
<a class="btn btn-ghost" href="/slots">Slots</a>
|
||||
<a class="btn btn-ghost" href="/orders">Orders</a>
|
||||
<a class="btn btn-ghost" href="/emails">Emails</a>
|
||||
<a class="btn btn-ghost" href="/globals">Globals</a>
|
||||
<div class="dropdown dropdown-end">
|
||||
<button class="btn btn-ghost btn-sm" type="button" tabindex="0">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16v2a2 2 0 002 2h12a2 2 0 002-2v-2M7 11l5 5 5-5M12 4v12" /></svg>
|
||||
Export/Import
|
||||
</button>
|
||||
<ul class="menu dropdown-content z-20 mt-2 w-48 rounded-box bg-base-100 p-2 shadow">
|
||||
<li><button type="button" onclick={handleExport}>Export all</button></li>
|
||||
<li>
|
||||
<button type="button" onclick={() => (document.getElementById('admin-import-file') as HTMLInputElement)?.click()} disabled={importing}>
|
||||
{importing ? 'Importing…' : 'Import'}
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
{#if bare}
|
||||
{@render children()}
|
||||
{:else}
|
||||
<div class="admin-shell min-h-screen bg-base-200">
|
||||
<header class="navbar sticky top-0 z-30 gap-2 bg-base-100 px-4 shadow-sm">
|
||||
<div class="flex-1">
|
||||
<a class="text-lg font-bold tracking-tight" href="/pages">Massage CMS</a>
|
||||
</div>
|
||||
<input id="admin-import-file" type="file" accept=".json" class="hidden" onchange={handleImport} />
|
||||
<form class="inline" method="POST" action="/login?/logout">
|
||||
<button class="btn btn-outline btn-sm" type="submit">Logout</button>
|
||||
</form>
|
||||
</div>
|
||||
<nav class="flex flex-none flex-wrap items-center gap-1">
|
||||
{#each navLinks as link (link.href)}
|
||||
<a class="btn btn-ghost btn-sm" class:btn-active={isActive(link.href)} aria-current={isActive(link.href) ? 'page' : undefined} href={link.href}>{link.label}</a>
|
||||
{/each}
|
||||
<div class="dropdown dropdown-end">
|
||||
<button class="btn btn-ghost btn-sm" type="button" tabindex="0">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="size-4" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16v2a2 2 0 002 2h12a2 2 0 002-2v-2M7 11l5 5 5-5M12 4v12" /></svg>
|
||||
Export/Import
|
||||
</button>
|
||||
<ul class="menu dropdown-content z-40 mt-2 w-48 rounded-box bg-base-100 p-2 shadow">
|
||||
<li><button type="button" onclick={handleExport}>Export all</button></li>
|
||||
<li>
|
||||
<button type="button" onclick={() => (document.getElementById('admin-import-file') as HTMLInputElement)?.click()} disabled={importing}>
|
||||
{importing ? 'Importing…' : 'Import'}
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<input id="admin-import-file" type="file" accept=".json" class="hidden" onchange={handleImport} />
|
||||
<form method="POST" action="/login?/logout">
|
||||
<button class="btn btn-outline btn-sm" type="submit">Logout</button>
|
||||
</form>
|
||||
</nav>
|
||||
</header>
|
||||
{#if importStatus}
|
||||
<div class="mx-auto max-w-7xl px-4 pt-4 md:px-8">
|
||||
<div class="alert items-start" class:alert-success={importStatus.ok} class:alert-error={!importStatus.ok}>
|
||||
<div class="flex-1">
|
||||
<p>{importStatus.message}</p>
|
||||
{#if importStatus.errors?.length}
|
||||
<ul class="mt-2 list-disc pl-5 text-sm">
|
||||
{#each importStatus.errors as err}<li>{err}</li>{/each}
|
||||
</ul>
|
||||
{/if}
|
||||
</div>
|
||||
<button class="btn btn-ghost btn-xs" type="button" aria-label="Dismiss" onclick={() => (importStatus = null)}>✕</button>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
<main class="mx-auto max-w-7xl p-4 md:p-8">
|
||||
{@render children()}
|
||||
</main>
|
||||
</div>
|
||||
{#if importStatus}
|
||||
<div class="mx-auto max-w-7xl px-4 pt-2">
|
||||
<div class="alert" class:alert-success={importStatus.ok} class:alert-error={!importStatus.ok}>
|
||||
{importStatus.message}
|
||||
<button class="btn btn-ghost btn-xs" onclick={() => (importStatus = null)}>×</button>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
<main class="mx-auto max-w-7xl p-4 md:p-8">
|
||||
{@render children()}
|
||||
</main>
|
||||
</div>
|
||||
{/if}
|
||||
|
|
|
|||
|
|
@ -1,26 +1,38 @@
|
|||
<script lang="ts">
|
||||
let { form } = $props();
|
||||
let submitting = $state(false);
|
||||
</script>
|
||||
|
||||
<svelte:head><title>Admin login</title></svelte:head>
|
||||
<svelte:head><title>Sign in | CMS</title></svelte:head>
|
||||
|
||||
<div class="grid min-h-screen place-items-center bg-base-200 p-6">
|
||||
<form class="card w-full max-w-md bg-base-100 shadow-xl" method="POST" action="?/login">
|
||||
<div class="card-body">
|
||||
<h1 class="card-title text-3xl">Sign in</h1>
|
||||
<p class="text-base-content/60">Use your PocketBase admin or CMS user credentials.</p>
|
||||
{#if form?.message}
|
||||
<div class="alert alert-error mt-4">{form.message}</div>
|
||||
{/if}
|
||||
<label class="form-control mt-4">
|
||||
<span class="label-text">Email</span>
|
||||
<input class="input input-bordered" name="email" type="email" required />
|
||||
</label>
|
||||
<label class="form-control">
|
||||
<span class="label-text">Password</span>
|
||||
<input class="input input-bordered" name="password" type="password" required />
|
||||
</label>
|
||||
<button class="btn btn-primary mt-4" type="submit">Login</button>
|
||||
</div>
|
||||
</form>
|
||||
<div class="grid min-h-screen place-items-center bg-base-200 p-4">
|
||||
<div class="w-full max-w-sm">
|
||||
<p class="mb-6 text-center text-lg font-bold tracking-tight">Massage CMS</p>
|
||||
<form class="card bg-base-100 shadow-xl" method="POST" action="?/login" onsubmit={() => (submitting = true)}>
|
||||
<div class="card-body gap-4">
|
||||
<div>
|
||||
<h1 class="text-2xl font-bold">Sign in</h1>
|
||||
<p class="text-sm text-base-content/60">Use your CMS account to manage the website.</p>
|
||||
</div>
|
||||
{#if form?.message}
|
||||
<div class="alert alert-error text-sm" role="alert">{form.message}</div>
|
||||
{/if}
|
||||
<fieldset class="fieldset gap-3 p-0">
|
||||
<label class="flex flex-col gap-1">
|
||||
<span class="fieldset-legend p-0">Email</span>
|
||||
<!-- svelte-ignore a11y_autofocus -->
|
||||
<input class="input w-full" name="email" type="email" autocomplete="username" defaultValue={form?.email ?? ''} required autofocus />
|
||||
</label>
|
||||
<label class="flex flex-col gap-1">
|
||||
<span class="fieldset-legend p-0">Password</span>
|
||||
<input class="input w-full" name="password" type="password" autocomplete="current-password" required />
|
||||
</label>
|
||||
</fieldset>
|
||||
<button class="btn btn-primary w-full" type="submit" disabled={submitting}>
|
||||
{#if submitting}<span class="loading loading-spinner loading-sm"></span>{/if}
|
||||
Sign in
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -3,11 +3,32 @@
|
|||
import BlockRenderer from '$shared/blocks/BlockRenderer.svelte';
|
||||
import type { ContentBlock } from '$lib/types';
|
||||
|
||||
let { data } = $props();
|
||||
let blocks = $state<ContentBlock[]>([]);
|
||||
let error = $state('');
|
||||
|
||||
onMount(() => {
|
||||
// Apply the site's colors so the preview matches the public site. Only
|
||||
// here: these variable names overlap DaisyUI's theme (--color-primary,
|
||||
// --color-accent), so setting them in the admin shell restyled the admin.
|
||||
if (data.colors) {
|
||||
const root = document.documentElement;
|
||||
root.style.setProperty('--color-bg', data.colors.background);
|
||||
root.style.setProperty('--color-heading', data.colors.heading);
|
||||
root.style.setProperty('--color-subheading', data.colors.subheading);
|
||||
root.style.setProperty('--color-text', data.colors.text);
|
||||
root.style.setProperty('--color-primary', data.colors.primary);
|
||||
root.style.setProperty('--color-accent', data.colors.accent);
|
||||
}
|
||||
|
||||
const raw = sessionStorage.getItem('cms-preview-blocks');
|
||||
if (raw) blocks = JSON.parse(raw);
|
||||
if (!raw) return;
|
||||
try {
|
||||
const parsed = JSON.parse(raw);
|
||||
if (Array.isArray(parsed)) blocks = parsed;
|
||||
} catch {
|
||||
error = 'The preview data could not be read. Close the preview and open it again.';
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
|
|
@ -20,6 +41,6 @@
|
|||
{:else}
|
||||
<section class="mx-auto max-w-3xl px-6 py-20 text-center">
|
||||
<h1 class="text-4xl">No preview content</h1>
|
||||
<p class="mt-4 text-charcoal/65">Open preview from the page editor to view the current draft.</p>
|
||||
<p class="mt-4 text-charcoal/65">{error || 'Open preview from the page editor to view the current draft.'}</p>
|
||||
</section>
|
||||
{/if}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue