feat: every dashboard has its own wallpaper
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:
+61
-12
@@ -36,6 +36,7 @@ import {
|
||||
getDashboard,
|
||||
saveDashboard,
|
||||
saveSettings,
|
||||
saveWallpaper,
|
||||
} from "@/lib/dashboard.functions"
|
||||
import { ENGINES, ENGINE_NAMES } from "@/lib/search"
|
||||
import type { Engine } from "@/lib/search"
|
||||
@@ -74,13 +75,18 @@ import { Spinner } from "@/vendor/collabry/components/Spinner/Spinner"
|
||||
import { cn } from "@/vendor/collabry/lib/cn"
|
||||
|
||||
export const Route = createFileRoute("/settings")({
|
||||
loader: async () => {
|
||||
const data = await getDashboard()
|
||||
// ?d=<dashboard id>: the dashboard you came from, and whose wallpaper is shown
|
||||
validateSearch: (search): { d?: string } =>
|
||||
typeof search.d === "string" ? { d: search.d } : {},
|
||||
loaderDeps: ({ search }) => search,
|
||||
loader: async ({ deps }) => {
|
||||
const data = await getDashboard({ data: { dashboardId: deps.d } })
|
||||
if (!data) throw redirect({ to: "/login" })
|
||||
return data
|
||||
},
|
||||
head: () => ({ meta: [{ title: "Settings" }] }),
|
||||
component: Settings,
|
||||
// a new key per dashboard: the page starts again with that dashboard's wallpaper
|
||||
component: () => <Settings key={Route.useLoaderData().dashboardId} />,
|
||||
})
|
||||
|
||||
const SECTIONS = [
|
||||
@@ -145,14 +151,20 @@ function Settings() {
|
||||
title?: string
|
||||
defaultDashboardId?: string
|
||||
searchEngine?: Engine
|
||||
wallpaperUrl?: string | null
|
||||
wallpaperDim?: number
|
||||
clockFont?: ClockFont
|
||||
clockStyle?: ClockStyle
|
||||
}) => run(() => saveSettings({ data: patch }))
|
||||
// the wallpaper belongs to the dashboard that is chosen in its section
|
||||
const saveWall = (patch: {
|
||||
wallpaperUrl?: string | null
|
||||
wallpaperDim?: number
|
||||
}) =>
|
||||
run(() =>
|
||||
saveWallpaper({ data: { dashboardId: data.dashboardId, ...patch } })
|
||||
)
|
||||
const upload = (image: File) =>
|
||||
run(async () => {
|
||||
const res = await fetch("/api/wallpaper", {
|
||||
const res = await fetch(`/api/wallpaper?d=${data.dashboardId}`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": image.type },
|
||||
body: image,
|
||||
@@ -170,7 +182,7 @@ function Settings() {
|
||||
<Logo className="size-5 text-fg" />
|
||||
<span className="min-w-0 truncate font-bold">{data.title}</span>
|
||||
<Button asChild size="sm" className="ml-auto">
|
||||
<Link to="/">
|
||||
<Link to="/" search={{ d: data.dashboardId }}>
|
||||
<ArrowLeft size={14} aria-hidden /> Back to dashboard
|
||||
</Link>
|
||||
</Button>
|
||||
@@ -221,6 +233,7 @@ function Settings() {
|
||||
<Link
|
||||
to="/settings"
|
||||
hash={id}
|
||||
search
|
||||
// without this every link counts as the current page
|
||||
activeOptions={{ includeHash: true }}
|
||||
>
|
||||
@@ -446,10 +459,46 @@ function Settings() {
|
||||
<SettingsSectionHeader>
|
||||
<SettingsSectionTitle>Wallpaper</SettingsSectionTitle>
|
||||
<SettingsSectionDescription>
|
||||
The picture behind your dashboard. Upload one (JPEG, PNG,
|
||||
WebP or AVIF, up to 10 MB) or use any image on the web.
|
||||
The picture behind a dashboard, every dashboard has its own.
|
||||
Upload one (JPEG, PNG, WebP or AVIF, up to 10 MB) or use any
|
||||
image on the web.
|
||||
</SettingsSectionDescription>
|
||||
</SettingsSectionHeader>
|
||||
{data.dashboards.length > 1 && (
|
||||
<SettingsRow>
|
||||
<SettingsRowText>
|
||||
<div
|
||||
id="settings-wallpaper-of"
|
||||
className="leading-tight font-bold"
|
||||
>
|
||||
Dashboard
|
||||
</div>
|
||||
<SettingsRowDescription>
|
||||
Whose wallpaper you change here.
|
||||
</SettingsRowDescription>
|
||||
</SettingsRowText>
|
||||
<SettingsRowControl>
|
||||
<SegmentedControl
|
||||
aria-labelledby="settings-wallpaper-of"
|
||||
size="md"
|
||||
value={data.dashboardId}
|
||||
onValueChange={(d) =>
|
||||
router.navigate({
|
||||
to: "/settings",
|
||||
search: { d },
|
||||
hash: "wallpaper",
|
||||
})
|
||||
}
|
||||
>
|
||||
{data.dashboards.map((d) => (
|
||||
<SegmentedControlItem key={d.id} value={d.id}>
|
||||
{d.name}
|
||||
</SegmentedControlItem>
|
||||
))}
|
||||
</SegmentedControl>
|
||||
</SettingsRowControl>
|
||||
</SettingsRow>
|
||||
)}
|
||||
<SettingsRow stacked>
|
||||
<div className="flex flex-wrap items-start gap-x-6 gap-y-4">
|
||||
<div className="relative w-60 flex-none overflow-hidden rounded-xl border border-line">
|
||||
@@ -483,7 +532,7 @@ function Settings() {
|
||||
const url = e.target.value.trim()
|
||||
if (!url || url === data.wallpaperUrl) return
|
||||
if (e.target.checkValidity())
|
||||
void save({ wallpaperUrl: url })
|
||||
void saveWall({ wallpaperUrl: url })
|
||||
else
|
||||
setError(
|
||||
"The image address must start with http:// or https://"
|
||||
@@ -519,7 +568,7 @@ function Settings() {
|
||||
<Button
|
||||
variant="ghost"
|
||||
disabled={status === "saving" || !data.wallpaperUrl}
|
||||
onClick={() => save({ wallpaperUrl: null })}
|
||||
onClick={() => saveWall({ wallpaperUrl: null })}
|
||||
>
|
||||
Use default
|
||||
</Button>
|
||||
@@ -551,7 +600,7 @@ function Settings() {
|
||||
// one save when the slider rests, not one per step
|
||||
clearTimeout(dimSave.current)
|
||||
dimSave.current = setTimeout(
|
||||
() => save({ wallpaperDim }),
|
||||
() => saveWall({ wallpaperDim }),
|
||||
400
|
||||
)
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user