feat: several dashboards with a default, icon search and icon upload
images / check (push) Successful in 33s
images / image (push) Successful in 16s

Dashboards are separate sets of cards (Home, Work). Settings manages them and
sets the one that opens at sign-in, the header and the search bar switch.
Migration 0006 puts the existing cards on a dashboard "Home".

The link dialog searches dashboard-icons and uploads custom icons (/api/icon,
up to 1 MB, SVG served sandboxed). Wallpaper and icons share the upload checks.
This commit is contained in:
2026-11-18 17:53:27 +01:00
parent 4b9690e064
commit e85244e820
18 changed files with 1643 additions and 125 deletions
+125 -16
View File
@@ -1,4 +1,5 @@
import { useRef, useState } from "react"
import type { ComponentProps } from "react"
import {
Link,
createFileRoute,
@@ -12,9 +13,12 @@ import {
CircleUser,
Clock,
Image,
LayoutDashboard,
LogOut,
Plus,
Search,
SlidersHorizontal,
Trash2,
Upload,
} from "lucide-react"
import { Logo } from "@/components/logo"
@@ -27,7 +31,12 @@ import {
CLOCK_STYLE_NAMES,
} from "@/lib/clock"
import type { ClockFont, ClockStyle } from "@/lib/clock"
import { getDashboard, saveSettings } from "@/lib/dashboard.functions"
import {
deleteDashboard,
getDashboard,
saveDashboard,
saveSettings,
} from "@/lib/dashboard.functions"
import { ENGINES, ENGINE_NAMES } from "@/lib/search"
import type { Engine } from "@/lib/search"
import { Button } from "@/vendor/collabry/components/Button/Button"
@@ -76,6 +85,7 @@ export const Route = createFileRoute("/settings")({
const SECTIONS = [
{ id: "general", label: "General", icon: SlidersHorizontal },
{ id: "dashboards", label: "Dashboards", icon: LayoutDashboard },
{ id: "clock", label: "Clock", icon: Clock },
{ id: "search", label: "Search", icon: Search },
{ id: "wallpaper", label: "Wallpaper", icon: Image },
@@ -85,6 +95,30 @@ const SECTIONS = [
// the nav links jump to a section; keep its title clear of the window edge
const section = "[&>section]:scroll-mt-24"
/** A name that is saved when the field is left. An empty one goes back to what it was. */
function NameInput({
value,
onSave,
...props
}: { value: string; onSave: (name: string) => void } & ComponentProps<
typeof Input
>) {
return (
<Input
className="w-64"
defaultValue={value}
maxLength={40}
onKeyDown={(e) => e.key === "Enter" && e.currentTarget.blur()}
onBlur={(e) => {
const name = e.target.value.trim()
if (name && name !== value) onSave(name)
else e.target.value = value
}}
{...props}
/>
)
}
function Settings() {
const data = Route.useLoaderData()
const router = useRouter()
@@ -95,6 +129,8 @@ function Settings() {
// follows the slider at once, the save comes a moment later
const [dim, setDim] = useState(data.wallpaperDim)
const dimSave = useRef<ReturnType<typeof setTimeout>>(undefined)
// deleting a dashboard deletes its cards and links, so it takes a second click
const [confirming, setConfirming] = useState<string | null>(null)
// Every control saves on its own. `action` returns a message when it failed.
const run = async (action: () => Promise<string | void>) => {
@@ -107,6 +143,7 @@ function Settings() {
}
const save = (patch: {
title?: string
defaultDashboardId?: string
searchEngine?: Engine
wallpaperUrl?: string | null
wallpaperDim?: number
@@ -199,37 +236,109 @@ function Settings() {
<SettingsSectionHeader>
<SettingsSectionTitle>General</SettingsSectionTitle>
<SettingsSectionDescription>
How this dashboard is called.
How this start page is called.
</SettingsSectionDescription>
</SettingsSectionHeader>
<SettingsRow>
<SettingsRowText>
<SettingsRowLabel htmlFor="settings-title">
Dashboard name
Title
</SettingsRowLabel>
<SettingsRowDescription>
Shown at the top left of the dashboard.
Shown at the top left of every dashboard.
</SettingsRowDescription>
</SettingsRowText>
<SettingsRowControl>
<Input
<NameInput
id="settings-title"
className="w-64"
defaultValue={data.title}
maxLength={40}
onKeyDown={(e) =>
e.key === "Enter" && e.currentTarget.blur()
}
onBlur={(e) => {
const title = e.target.value.trim()
if (title && title !== data.title) void save({ title })
else e.target.value = data.title
}}
value={data.title}
onSave={(title) => save({ title })}
/>
</SettingsRowControl>
</SettingsRow>
</SettingsSection>
<SettingsSection id="dashboards" className={section}>
<SettingsSectionHeader>
<SettingsSectionTitle>Dashboards</SettingsSectionTitle>
<SettingsSectionDescription>
Each dashboard has its own cards, for example Home and Work.
With more than one, you switch between them at the top of
the dashboard. The default one opens when you sign in.
</SettingsSectionDescription>
</SettingsSectionHeader>
{data.dashboards.map((d) => {
const isDefault = d.id === data.defaultDashboardId
return (
<SettingsRow key={d.id}>
<SettingsRowText>
<NameInput
aria-label="Dashboard name"
value={d.name}
onSave={(name) =>
run(() =>
saveDashboard({ data: { id: d.id, name } })
)
}
/>
</SettingsRowText>
<SettingsRowControl className="flex flex-wrap gap-2">
<Button
disabled={isDefault}
onClick={() => save({ defaultDashboardId: d.id })}
>
{isDefault && <Check size={15} />}
{isDefault ? "Default" : "Make default"}
</Button>
<Button
variant={
confirming === d.id ? "danger" : "danger-outline"
}
disabled={data.dashboards.length < 2}
onClick={() =>
confirming === d.id
? run(() =>
deleteDashboard({ data: { id: d.id } })
)
: setConfirming(d.id)
}
>
<Trash2 size={15} />
{confirming === d.id
? "Yes, delete it with its cards and links"
: "Delete"}
</Button>
</SettingsRowControl>
</SettingsRow>
)
})}
<SettingsRow>
<form
className="flex flex-wrap gap-2"
onSubmit={(e) => {
e.preventDefault()
const form = e.currentTarget
const name = String(new FormData(form).get("name"))
void run(() => saveDashboard({ data: { name } })).then(
() => form.reset()
)
}}
>
<Input
name="name"
aria-label="Name of the new dashboard"
className="w-64"
placeholder="New dashboard"
maxLength={40}
required
/>
<Button type="submit">
<Plus size={15} /> Add dashboard
</Button>
</form>
</SettingsRow>
</SettingsSection>
<SettingsSection id="clock" className={section}>
<SettingsSectionHeader>
<SettingsSectionTitle>Clock</SettingsSectionTitle>