feat: every dashboard has its own wallpaper
images / check (push) Successful in 32s
images / image (push) Successful in 15s

The wallpaper and how much it is darkened move from the user to the dashboard.
Migration 0007 copies what each user had to all their dashboards.

Settings open for the dashboard you came from (/settings?d=<id>): its wallpaper
is shown, a switch reaches the others, and "Back to dashboard" returns to it.
This commit is contained in:
2026-11-18 18:03:10 +01:00
parent e85244e820
commit dacd374946
10 changed files with 1100 additions and 54 deletions
+41 -16
View File
@@ -2,7 +2,6 @@ import { createServerFn } from "@tanstack/react-start"
import { getRequestHeaders } from "@tanstack/react-start/server"
import { and, asc, eq, inArray, sql } from "drizzle-orm"
import { z } from "zod"
import { DEFAULT_WALLPAPER_DIM } from "@/components/wallpaper"
import { db } from "@/db"
import { card, dashboard, link, settings, wallpaper } from "@/db/schema"
import { auth, requireUser, signUpEnabled, ssoName } from "@/lib/auth"
@@ -39,6 +38,14 @@ export const getAuthInfo = createServerFn({ method: "GET" }).handler(
})
)
/** What the pages need of a dashboard. */
const shown = {
id: dashboard.id,
name: dashboard.name,
wallpaperUrl: dashboard.wallpaperUrl,
wallpaperDim: dashboard.wallpaperDim,
}
/**
* Everything the dashboard renders, or null when signed out. Without a
* `dashboardId`, or with one that does not exist, it is the default dashboard.
@@ -52,7 +59,7 @@ export const getDashboard = createServerFn({ method: "GET" })
const userId = session.user.id
const [dashboards, rows] = await Promise.all([
db
.select({ id: dashboard.id, name: dashboard.name })
.select(shown)
.from(dashboard)
.where(eq(dashboard.userId, userId))
.orderBy(asc(dashboard.createdAt)),
@@ -66,12 +73,13 @@ export const getDashboard = createServerFn({ method: "GET" })
...(await db
.insert(dashboard)
.values({ userId, name: "Home" })
.returning({ id: dashboard.id, name: dashboard.name }))
.returning(shown))
)
const s = rows.at(0) // no row until the first save
const has = (id?: string | null) => dashboards.find((d) => d.id === id)?.id
const defaultDashboardId = has(s?.defaultDashboardId) ?? dashboards[0].id
const dashboardId = has(data?.dashboardId) ?? defaultDashboardId
const find = (id?: string | null) => dashboards.find((d) => d.id === id)
const byDefault = find(s?.defaultDashboardId) ?? dashboards[0]
const current = find(data?.dashboardId) ?? byDefault
const dashboardId = current.id
const [cards, links] = await Promise.all([
db
.select({ id: card.id, name: card.name })
@@ -102,15 +110,15 @@ export const getDashboard = createServerFn({ method: "GET" })
user: { name: session.user.name, email: session.user.email },
dashboards,
dashboardId,
defaultDashboardId,
defaultDashboardId: byDefault.id,
cards: cards.map((c) => ({
...c,
links: links.filter((l) => l.cardId === c.id),
})),
title: s?.title ?? "Dahoam",
searchEngine: s?.searchEngine ?? "duckduckgo",
wallpaperUrl: s?.wallpaperUrl ?? null,
wallpaperDim: s?.wallpaperDim ?? DEFAULT_WALLPAPER_DIM,
wallpaperUrl: current.wallpaperUrl,
wallpaperDim: current.wallpaperDim,
clockFont: s?.clockFont ?? "serif",
clockStyle: s?.clockStyle ?? "solid",
searxngUrl: process.env.SEARXNG_URL || null,
@@ -255,11 +263,6 @@ export const saveSettings = createServerFn({ method: "POST" })
title: z.string().trim().min(1).max(40),
defaultDashboardId: z.uuid(),
searchEngine: z.enum(ENGINES),
// external image, the user's own upload, or null for the default
wallpaperUrl: z
.union([httpUrl, z.string().regex(/^\/api\/wallpaper\?v=\d+$/)])
.nullable(),
wallpaperDim: z.int().min(0).max(100),
clockFont: z.enum(CLOCK_FONTS),
clockStyle: z.enum(CLOCK_STYLES),
})
@@ -274,9 +277,31 @@ export const saveSettings = createServerFn({ method: "POST" })
.insert(settings)
.values({ ...data, userId: user.id })
.onConflictDoUpdate({ target: settings.userId, set: data })
})
/** The wallpaper of one dashboard. An upload goes to /api/wallpaper instead. */
export const saveWallpaper = createServerFn({ method: "POST" })
.validator(
z
.object({
dashboardId: z.uuid(),
// an image on the web, or null for the default photo
wallpaperUrl: httpUrl.nullable().optional(),
wallpaperDim: z.int().min(0).max(100).optional(),
})
.refine((patch) => Object.keys(patch).length > 1)
)
.handler(async ({ data: { dashboardId, ...patch } }) => {
const user = await requireUser()
const saved = await db
.update(dashboard)
.set(patch)
.where(and(eq(dashboard.id, dashboardId), eq(dashboard.userId, user.id)))
.returning({ id: dashboard.id })
if (!saved.length) throw new Error("Unknown dashboard")
// the stored upload is no longer shown
if (data.wallpaperUrl !== undefined && !data.wallpaperUrl?.startsWith("/"))
await db.delete(wallpaper).where(eq(wallpaper.userId, user.id))
if (patch.wallpaperUrl !== undefined)
await db.delete(wallpaper).where(eq(wallpaper.dashboardId, dashboardId))
})
export const suggest = createServerFn({ method: "GET" })