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
+6 -2
View File
@@ -95,6 +95,10 @@ scripts/sync-collabry.sh copies them from upstream at a pinned commit
- [x] 14. Icons: the link dialog searches dashboard-icons (`src/lib/icons.ts` and its test) and
uploads custom icons (table `icon`, `/api/icon`, ≤ 1 MB, SVG allowed because it is served
sandboxed). `src/lib/upload.ts` holds the upload checks that wallpaper and icons share.
- [x] 15. A wallpaper per dashboard: `wallpaperUrl` and `wallpaperDim` move from `settings` to
`dashboard`, the `wallpaper` table is keyed by dashboard (migration `0007_dashboard_wallpaper`
copies what each user had to all their dashboards). `/settings?d=<id>` is the dashboard whose
wallpaper is shown, and where "Back to dashboard" goes.
## Not doing (not asked)
@@ -102,8 +106,8 @@ scripts/sync-collabry.sh copies them from upstream at a pinned commit
- Inline SearXNG result rendering (search opens the engine's result page)
- Reordering the cards themselves (they stay in the order they were made), free placement with
gaps in the grid, per-user SearXNG URL (SSRF risk — it is a server env)
- Per dashboard wallpaper, clock or search engine (they stay per user), moving a card to another
dashboard, reordering dashboards, remembering the last opened dashboard (the default opens)
- Per dashboard clock or search engine (they stay per user), moving a card to another dashboard,
reordering dashboards, remembering the last opened dashboard (the default opens)
- A list of the icons a user uploaded, to use one again for another link
- Email verification / password reset mail (needs an SMTP setup)
- In CI: version tags and releases, a Helm chart, an image vulnerability scan (typst-workspace has all three)
+4 -1
View File
@@ -56,7 +56,8 @@ Build it yourself: `docker build -t dahoam .`
- **Dashboards** are separate sets of cards, for example Home and Work. Settings → Dashboards
adds, renames and deletes them and sets the default, the one that opens when you sign in.
With more than one, switch at the top of the page or with `/switch to work`. The address
of a dashboard (`/?d=…`) can be bookmarked. Wallpaper, clock and search are the same on all.
of a dashboard (`/?d=…`) can be bookmarked. Every dashboard has its own wallpaper, clock
and search are the same on all.
- **Cards** group your links (Apps, Media, Bookmarks, ...). "New card" under the cards adds
one. Click a card's name to rename or delete it.
- **Links**: **+** at the top or on a card adds a link. Hover a link and click the pencil to
@@ -71,6 +72,8 @@ Build it yourself: `docker build -t dahoam .`
a link, `/settings`, `/add link`, `/add card`, `/add dashboard` and `/sign out` run commands.
- **Wallpaper**: Settings (or the pencil at the bottom right) takes an image URL or an
upload (JPEG, PNG, WebP, AVIF, up to 10 MB). A slider sets how much it is darkened.
Each dashboard has its own: the pencil opens the one of the dashboard you are on, and
Settings → Wallpaper has a switch for the others.
- **Clock**: Settings has five fonts and three styles. Glass shows the wallpaper blurred
through the digits, Tinted takes its color from the wallpaper.
+26
View File
@@ -0,0 +1,26 @@
-- Hand-written: the wallpaper moves from the user to the dashboard. Every dashboard of a
-- user starts with the wallpaper that the user had, so nothing looks different.
ALTER TABLE "dashboard" ADD COLUMN "wallpaper_url" text;--> statement-breakpoint
ALTER TABLE "dashboard" ADD COLUMN "wallpaper_dim" integer DEFAULT 40 NOT NULL;--> statement-breakpoint
-- a user who chose a wallpaper but has no dashboard yet keeps it too
INSERT INTO "dashboard" ("user_id", "name")
SELECT "user_id", 'Home' FROM "settings"
WHERE NOT EXISTS (SELECT 1 FROM "dashboard" WHERE "dashboard"."user_id" = "settings"."user_id");--> statement-breakpoint
-- the address of an upload now names its dashboard: /api/wallpaper?d=<id>&v=<upload time>
UPDATE "dashboard" SET
"wallpaper_dim" = "settings"."wallpaper_dim",
"wallpaper_url" = CASE WHEN "settings"."wallpaper_url" LIKE '/api/wallpaper?v=%'
THEN replace("settings"."wallpaper_url", '?v=', '?d=' || "dashboard"."id" || '&v=')
ELSE "settings"."wallpaper_url" END
FROM "settings" WHERE "settings"."user_id" = "dashboard"."user_id";--> statement-breakpoint
ALTER TABLE "wallpaper" DROP CONSTRAINT "wallpaper_pkey";--> statement-breakpoint
ALTER TABLE "wallpaper" ADD COLUMN "dashboard_id" uuid;--> statement-breakpoint
-- one upload per user becomes one copy per dashboard of that user
INSERT INTO "wallpaper" ("dashboard_id", "user_id", "mime", "data")
SELECT "dashboard"."id", "wallpaper"."user_id", "wallpaper"."mime", "wallpaper"."data"
FROM "wallpaper" JOIN "dashboard" ON "dashboard"."user_id" = "wallpaper"."user_id";--> statement-breakpoint
DELETE FROM "wallpaper" WHERE "dashboard_id" IS NULL;--> statement-breakpoint
ALTER TABLE "wallpaper" ADD PRIMARY KEY ("dashboard_id");--> statement-breakpoint
ALTER TABLE "wallpaper" ADD CONSTRAINT "wallpaper_dashboard_id_dashboard_id_fk" FOREIGN KEY ("dashboard_id") REFERENCES "public"."dashboard"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "settings" DROP COLUMN "wallpaper_url";--> statement-breakpoint
ALTER TABLE "settings" DROP COLUMN "wallpaper_dim";
+902
View File
@@ -0,0 +1,902 @@
{
"id": "c89fef31-f0cf-4f87-8683-df4f9eb49fa8",
"prevId": "7a2af09b-64c1-4ae0-8b47-a669a9e399f0",
"version": "7",
"dialect": "postgresql",
"tables": {
"public.account": {
"name": "account",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true
},
"account_id": {
"name": "account_id",
"type": "text",
"primaryKey": false,
"notNull": true
},
"provider_id": {
"name": "provider_id",
"type": "text",
"primaryKey": false,
"notNull": true
},
"user_id": {
"name": "user_id",
"type": "text",
"primaryKey": false,
"notNull": true
},
"access_token": {
"name": "access_token",
"type": "text",
"primaryKey": false,
"notNull": false
},
"refresh_token": {
"name": "refresh_token",
"type": "text",
"primaryKey": false,
"notNull": false
},
"id_token": {
"name": "id_token",
"type": "text",
"primaryKey": false,
"notNull": false
},
"access_token_expires_at": {
"name": "access_token_expires_at",
"type": "timestamp",
"primaryKey": false,
"notNull": false
},
"refresh_token_expires_at": {
"name": "refresh_token_expires_at",
"type": "timestamp",
"primaryKey": false,
"notNull": false
},
"scope": {
"name": "scope",
"type": "text",
"primaryKey": false,
"notNull": false
},
"password": {
"name": "password",
"type": "text",
"primaryKey": false,
"notNull": false
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {
"account_user_id_idx": {
"name": "account_user_id_idx",
"columns": [
{
"expression": "user_id",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
}
},
"foreignKeys": {
"account_user_id_user_id_fk": {
"name": "account_user_id_user_id_fk",
"tableFrom": "account",
"tableTo": "user",
"columnsFrom": [
"user_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.card": {
"name": "card",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "uuid",
"primaryKey": true,
"notNull": true,
"default": "gen_random_uuid()"
},
"user_id": {
"name": "user_id",
"type": "text",
"primaryKey": false,
"notNull": true
},
"dashboard_id": {
"name": "dashboard_id",
"type": "uuid",
"primaryKey": false,
"notNull": true
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {
"card_user_id_idx": {
"name": "card_user_id_idx",
"columns": [
{
"expression": "user_id",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
},
"card_dashboard_id_idx": {
"name": "card_dashboard_id_idx",
"columns": [
{
"expression": "dashboard_id",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
}
},
"foreignKeys": {
"card_user_id_user_id_fk": {
"name": "card_user_id_user_id_fk",
"tableFrom": "card",
"tableTo": "user",
"columnsFrom": [
"user_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
},
"card_dashboard_id_dashboard_id_fk": {
"name": "card_dashboard_id_dashboard_id_fk",
"tableFrom": "card",
"tableTo": "dashboard",
"columnsFrom": [
"dashboard_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.dashboard": {
"name": "dashboard",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "uuid",
"primaryKey": true,
"notNull": true,
"default": "gen_random_uuid()"
},
"user_id": {
"name": "user_id",
"type": "text",
"primaryKey": false,
"notNull": true
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true
},
"wallpaper_url": {
"name": "wallpaper_url",
"type": "text",
"primaryKey": false,
"notNull": false
},
"wallpaper_dim": {
"name": "wallpaper_dim",
"type": "integer",
"primaryKey": false,
"notNull": true,
"default": 40
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {
"dashboard_user_id_idx": {
"name": "dashboard_user_id_idx",
"columns": [
{
"expression": "user_id",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
}
},
"foreignKeys": {
"dashboard_user_id_user_id_fk": {
"name": "dashboard_user_id_user_id_fk",
"tableFrom": "dashboard",
"tableTo": "user",
"columnsFrom": [
"user_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.icon": {
"name": "icon",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "uuid",
"primaryKey": true,
"notNull": true,
"default": "gen_random_uuid()"
},
"user_id": {
"name": "user_id",
"type": "text",
"primaryKey": false,
"notNull": true
},
"mime": {
"name": "mime",
"type": "text",
"primaryKey": false,
"notNull": true
},
"data": {
"name": "data",
"type": "bytea",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {
"icon_user_id_idx": {
"name": "icon_user_id_idx",
"columns": [
{
"expression": "user_id",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
}
},
"foreignKeys": {
"icon_user_id_user_id_fk": {
"name": "icon_user_id_user_id_fk",
"tableFrom": "icon",
"tableTo": "user",
"columnsFrom": [
"user_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.link": {
"name": "link",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "uuid",
"primaryKey": true,
"notNull": true,
"default": "gen_random_uuid()"
},
"user_id": {
"name": "user_id",
"type": "text",
"primaryKey": false,
"notNull": true
},
"card_id": {
"name": "card_id",
"type": "uuid",
"primaryKey": false,
"notNull": true
},
"position": {
"name": "position",
"type": "integer",
"primaryKey": false,
"notNull": true,
"default": 0
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true
},
"url": {
"name": "url",
"type": "text",
"primaryKey": false,
"notNull": true
},
"icon": {
"name": "icon",
"type": "text",
"primaryKey": false,
"notNull": false
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {
"link_user_id_idx": {
"name": "link_user_id_idx",
"columns": [
{
"expression": "user_id",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
},
"link_card_id_idx": {
"name": "link_card_id_idx",
"columns": [
{
"expression": "card_id",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
}
},
"foreignKeys": {
"link_user_id_user_id_fk": {
"name": "link_user_id_user_id_fk",
"tableFrom": "link",
"tableTo": "user",
"columnsFrom": [
"user_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
},
"link_card_id_card_id_fk": {
"name": "link_card_id_card_id_fk",
"tableFrom": "link",
"tableTo": "card",
"columnsFrom": [
"card_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.session": {
"name": "session",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true
},
"expires_at": {
"name": "expires_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true
},
"token": {
"name": "token",
"type": "text",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"ip_address": {
"name": "ip_address",
"type": "text",
"primaryKey": false,
"notNull": false
},
"user_agent": {
"name": "user_agent",
"type": "text",
"primaryKey": false,
"notNull": false
},
"user_id": {
"name": "user_id",
"type": "text",
"primaryKey": false,
"notNull": true
}
},
"indexes": {
"session_user_id_idx": {
"name": "session_user_id_idx",
"columns": [
{
"expression": "user_id",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
}
},
"foreignKeys": {
"session_user_id_user_id_fk": {
"name": "session_user_id_user_id_fk",
"tableFrom": "session",
"tableTo": "user",
"columnsFrom": [
"user_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {
"session_token_unique": {
"name": "session_token_unique",
"nullsNotDistinct": false,
"columns": [
"token"
]
}
},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.settings": {
"name": "settings",
"schema": "",
"columns": {
"user_id": {
"name": "user_id",
"type": "text",
"primaryKey": true,
"notNull": true
},
"title": {
"name": "title",
"type": "text",
"primaryKey": false,
"notNull": true,
"default": "'Dahoam'"
},
"default_dashboard_id": {
"name": "default_dashboard_id",
"type": "uuid",
"primaryKey": false,
"notNull": false
},
"search_engine": {
"name": "search_engine",
"type": "text",
"primaryKey": false,
"notNull": true,
"default": "'duckduckgo'"
},
"clock_font": {
"name": "clock_font",
"type": "text",
"primaryKey": false,
"notNull": true,
"default": "'serif'"
},
"clock_style": {
"name": "clock_style",
"type": "text",
"primaryKey": false,
"notNull": true,
"default": "'solid'"
}
},
"indexes": {},
"foreignKeys": {
"settings_user_id_user_id_fk": {
"name": "settings_user_id_user_id_fk",
"tableFrom": "settings",
"tableTo": "user",
"columnsFrom": [
"user_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
},
"settings_default_dashboard_id_dashboard_id_fk": {
"name": "settings_default_dashboard_id_dashboard_id_fk",
"tableFrom": "settings",
"tableTo": "dashboard",
"columnsFrom": [
"default_dashboard_id"
],
"columnsTo": [
"id"
],
"onDelete": "set null",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.user": {
"name": "user",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true
},
"email": {
"name": "email",
"type": "text",
"primaryKey": false,
"notNull": true
},
"email_verified": {
"name": "email_verified",
"type": "boolean",
"primaryKey": false,
"notNull": true,
"default": false
},
"image": {
"name": "image",
"type": "text",
"primaryKey": false,
"notNull": false
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {
"user_email_unique": {
"name": "user_email_unique",
"nullsNotDistinct": false,
"columns": [
"email"
]
}
},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.verification": {
"name": "verification",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true
},
"identifier": {
"name": "identifier",
"type": "text",
"primaryKey": false,
"notNull": true
},
"value": {
"name": "value",
"type": "text",
"primaryKey": false,
"notNull": true
},
"expires_at": {
"name": "expires_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {
"verification_identifier_idx": {
"name": "verification_identifier_idx",
"columns": [
{
"expression": "identifier",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
}
},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.wallpaper": {
"name": "wallpaper",
"schema": "",
"columns": {
"dashboard_id": {
"name": "dashboard_id",
"type": "uuid",
"primaryKey": true,
"notNull": true
},
"user_id": {
"name": "user_id",
"type": "text",
"primaryKey": false,
"notNull": true
},
"mime": {
"name": "mime",
"type": "text",
"primaryKey": false,
"notNull": true
},
"data": {
"name": "data",
"type": "bytea",
"primaryKey": false,
"notNull": true
}
},
"indexes": {},
"foreignKeys": {
"wallpaper_dashboard_id_dashboard_id_fk": {
"name": "wallpaper_dashboard_id_dashboard_id_fk",
"tableFrom": "wallpaper",
"tableTo": "dashboard",
"columnsFrom": [
"dashboard_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
},
"wallpaper_user_id_user_id_fk": {
"name": "wallpaper_user_id_user_id_fk",
"tableFrom": "wallpaper",
"tableTo": "user",
"columnsFrom": [
"user_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
}
},
"enums": {},
"schemas": {},
"sequences": {},
"roles": {},
"policies": {},
"views": {},
"_meta": {
"columns": {},
"schemas": {},
"tables": {}
}
}
+7
View File
@@ -50,6 +50,13 @@
"when": 1795020380796,
"tag": "0006_dashboards_icons",
"breakpoints": true
},
{
"idx": 7,
"version": "7",
"when": 1795021173823,
"tag": "0007_dashboard_wallpaper",
"breakpoints": true
}
]
}
+9 -5
View File
@@ -86,6 +86,10 @@ export const dashboard = pgTable(
.notNull()
.references(() => user.id, { onDelete: "cascade" }),
name: text("name").notNull(),
// null = bundled default wallpaper
wallpaperUrl: text("wallpaper_url"),
// percent of black over the wallpaper, see DEFAULT_WALLPAPER_DIM
wallpaperDim: integer("wallpaper_dim").notNull().default(40),
createdAt: timestamp("created_at").notNull().defaultNow(),
},
(t) => [index("dashboard_user_id_idx").on(t.userId)]
@@ -151,10 +155,6 @@ export const settings = pgTable("settings", {
})
.notNull()
.default("duckduckgo"),
// null = bundled default wallpaper
wallpaperUrl: text("wallpaper_url"),
// percent of black over the wallpaper, see DEFAULT_WALLPAPER_DIM
wallpaperDim: integer("wallpaper_dim").notNull().default(40),
// the big clock, see src/lib/clock.ts
clockFont: text("clock_font", {
enum: ["serif", "sans", "light", "rounded", "slab"],
@@ -181,9 +181,13 @@ export const icon = pgTable(
(t) => [index("icon_user_id_idx").on(t.userId)]
)
/** The wallpaper that was uploaded for a dashboard, served from /api/wallpaper. */
export const wallpaper = pgTable("wallpaper", {
userId: text("user_id")
dashboardId: uuid("dashboard_id")
.primaryKey()
.references(() => dashboard.id, { onDelete: "cascade" }),
userId: text("user_id")
.notNull()
.references(() => user.id, { onDelete: "cascade" }),
mime: text("mime").notNull(),
data: bytea("data").notNull(),
+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" })
+29 -14
View File
@@ -1,7 +1,8 @@
import { createFileRoute } from "@tanstack/react-router"
import { eq } from "drizzle-orm"
import { and, eq } from "drizzle-orm"
import { z } from "zod"
import { db } from "@/db"
import { settings, wallpaper } from "@/db/schema"
import { dashboard, wallpaper } from "@/db/schema"
import { readImage, serveImage, userId } from "@/lib/upload"
const LIMITS = {
@@ -11,6 +12,10 @@ const LIMITS = {
maxMb: 10,
}
/** ?d=<dashboard id>: every dashboard has its own wallpaper. */
const dashboardOf = (request: Request) =>
z.uuid().safeParse(new URL(request.url).searchParams.get("d")).data
export const Route = createFileRoute("/api/wallpaper")({
server: {
handlers: {
@@ -18,32 +23,42 @@ export const Route = createFileRoute("/api/wallpaper")({
GET: async ({ request }) => {
const id = await userId(request)
if (!id) return new Response("Unauthorized", { status: 401 })
const d = dashboardOf(request)
if (!d) return new Response("Not found", { status: 404 })
return serveImage(
(
await db.select().from(wallpaper).where(eq(wallpaper.userId, id))
await db
.select()
.from(wallpaper)
.where(
and(eq(wallpaper.dashboardId, d), eq(wallpaper.userId, id))
)
).at(0)
)
},
POST: async ({ request }) => {
const image = await readImage(request, LIMITS)
if (image instanceof Response) return image
const wallpaperUrl = `/api/wallpaper?v=${Date.now()}`
await db.transaction(async (tx) => {
const d = dashboardOf(request)
if (!d) return new Response("Not found", { status: 404 })
const wallpaperUrl = `/api/wallpaper?d=${d}&v=${Date.now()}`
const saved = await db.transaction(async (tx) => {
const mine = await tx
.update(dashboard)
.set({ wallpaperUrl })
.where(and(eq(dashboard.id, d), eq(dashboard.userId, image.userId)))
.returning({ id: dashboard.id })
if (!mine.length) return false
await tx
.insert(wallpaper)
.values(image)
.values({ ...image, dashboardId: d })
.onConflictDoUpdate({
target: wallpaper.userId,
target: wallpaper.dashboardId,
set: { mime: image.mime, data: image.data },
})
await tx
.insert(settings)
.values({ userId: image.userId, wallpaperUrl })
.onConflictDoUpdate({
target: settings.userId,
set: { wallpaperUrl },
})
return true
})
if (!saved) return new Response("Not found", { status: 404 })
return Response.json({ wallpaperUrl })
},
},
+15 -4
View File
@@ -50,6 +50,8 @@ function Dashboard() {
const [link, setLink] = useState<LinkTarget | null>(null)
const [card, setCard] = useState<CardTarget | null>(null)
// settings open for this dashboard: its wallpaper, and back to it
const here = { d: data.dashboardId }
// the server makes sure there is always a card
const addLink = () => setLink({ cardId: data.cards[0].id })
@@ -93,7 +95,7 @@ function Dashboard() {
<Plus className="size-5" />
</Button>
<Button asChild variant="ghost" iconOnly className={onWallpaper}>
<Link to="/settings" aria-label="Settings">
<Link to="/settings" search={here} aria-label="Settings">
<Settings2 className="size-5" />
</Link>
</Button>
@@ -135,12 +137,16 @@ function Dashboard() {
label: "Add dashboard",
icon: <LayoutDashboard className="size-4" />,
run: () =>
router.navigate({ to: "/settings", hash: "dashboards" }),
router.navigate({
to: "/settings",
search: here,
hash: "dashboards",
}),
},
{
label: "Settings",
icon: <Settings2 className="size-4" />,
run: () => router.navigate({ to: "/settings" }),
run: () => router.navigate({ to: "/settings", search: here }),
},
{
label: "Sign out",
@@ -180,7 +186,12 @@ function Dashboard() {
</span>
)}
<Button asChild variant="ghost" iconOnly className={onWallpaper}>
<Link to="/settings" hash="wallpaper" aria-label="Change wallpaper">
<Link
to="/settings"
search={here}
hash="wallpaper"
aria-label="Change wallpaper"
>
<Pencil className="size-4" />
</Link>
</Button>
+61 -12
View File
@@ -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
)
}}