diff --git a/README.md b/README.md index ca09571..5af1fe9 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ Build it yourself: `docker build -t dahoam .` - **Search**: `/` focuses the bar. `!w cats` uses DuckDuckGo bangs. `/plex` jumps to a link, `/settings`, `/add link`, `/add card` 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). + upload (JPEG, PNG, WebP, AVIF, up to 10 MB). A slider sets how much it is darkened. - **Clock**: Settings has five fonts and three styles. Glass shows the wallpaper blurred through the digits, Tinted takes its color from the wallpaper. diff --git a/drizzle/0005_wallpaper_dim.sql b/drizzle/0005_wallpaper_dim.sql new file mode 100644 index 0000000..7be256a --- /dev/null +++ b/drizzle/0005_wallpaper_dim.sql @@ -0,0 +1 @@ +ALTER TABLE "settings" ADD COLUMN "wallpaper_dim" integer DEFAULT 40 NOT NULL; \ No newline at end of file diff --git a/drizzle/meta/0005_snapshot.json b/drizzle/meta/0005_snapshot.json new file mode 100644 index 0000000..131a66a --- /dev/null +++ b/drizzle/meta/0005_snapshot.json @@ -0,0 +1,686 @@ +{ + "id": "4df576be-2fef-462c-affd-4aff0ab26918", + "prevId": "ac3af713-2f43-44c7-8e48-d840cfee12c0", + "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 + }, + "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": {} + } + }, + "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" + } + }, + "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'" + }, + "search_engine": { + "name": "search_engine", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'duckduckgo'" + }, + "wallpaper_url": { + "name": "wallpaper_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "wallpaper_dim": { + "name": "wallpaper_dim", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 40 + }, + "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" + } + }, + "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": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "mime": { + "name": "mime", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "data": { + "name": "data", + "type": "bytea", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "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": {} + } +} \ No newline at end of file diff --git a/drizzle/meta/_journal.json b/drizzle/meta/_journal.json index 05a9613..82d4e29 100644 --- a/drizzle/meta/_journal.json +++ b/drizzle/meta/_journal.json @@ -36,6 +36,13 @@ "when": 1795017311884, "tag": "0004_clock", "breakpoints": true + }, + { + "idx": 5, + "version": "7", + "when": 1795017884385, + "tag": "0005_wallpaper_dim", + "breakpoints": true } ] } \ No newline at end of file diff --git a/src/components/wallpaper.tsx b/src/components/wallpaper.tsx index 068d949..a096b5e 100644 --- a/src/components/wallpaper.tsx +++ b/src/components/wallpaper.tsx @@ -1,6 +1,8 @@ import { cn } from "@/vendor/collabry/lib/cn" export const DEFAULT_WALLPAPER = "/wallpaper.jpg" +/** How dark the wallpaper is made until the user moves the slider, in percent. */ +export const DEFAULT_WALLPAPER_DIM = 40 function showDefault(img: HTMLImageElement) { if (!img.src.endsWith(DEFAULT_WALLPAPER)) img.src = DEFAULT_WALLPAPER @@ -28,11 +30,21 @@ export function WallpaperImage({ ) } -export function Wallpaper({ src }: { src?: string | null }) { +export function Wallpaper({ + src, + dim = DEFAULT_WALLPAPER_DIM, +}: { + src?: string | null + /** 0 shows the picture as it is, 100 is black */ + dim?: number +}) { return (
-
+
) } diff --git a/src/db/schema.ts b/src/db/schema.ts index 93aecad..a1ff2aa 100644 --- a/src/db/schema.ts +++ b/src/db/schema.ts @@ -127,6 +127,8 @@ export const settings = pgTable("settings", { .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"], diff --git a/src/lib/dashboard.functions.ts b/src/lib/dashboard.functions.ts index c1264ae..9487aac 100644 --- a/src/lib/dashboard.functions.ts +++ b/src/lib/dashboard.functions.ts @@ -2,6 +2,7 @@ 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, link, settings, wallpaper } from "@/db/schema" import { auth, requireUser, signUpEnabled, ssoName } from "@/lib/auth" @@ -75,6 +76,7 @@ export const getDashboard = createServerFn({ method: "GET" }).handler( title: s?.title ?? "Dahoam", searchEngine: s?.searchEngine ?? "duckduckgo", wallpaperUrl: s?.wallpaperUrl ?? null, + wallpaperDim: s?.wallpaperDim ?? DEFAULT_WALLPAPER_DIM, clockFont: s?.clockFont ?? "serif", clockStyle: s?.clockStyle ?? "solid", searxngUrl: process.env.SEARXNG_URL || null, @@ -190,6 +192,7 @@ export const saveSettings = createServerFn({ method: "POST" }) 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), }) diff --git a/src/routes/index.tsx b/src/routes/index.tsx index 22862d6..aae5533 100644 --- a/src/routes/index.tsx +++ b/src/routes/index.tsx @@ -44,7 +44,7 @@ function Dashboard() { return (
- +
diff --git a/src/routes/settings.tsx b/src/routes/settings.tsx index 75e6971..72b772b 100644 --- a/src/routes/settings.tsx +++ b/src/routes/settings.tsx @@ -92,6 +92,9 @@ function Settings() { const file = useRef(null) const [status, setStatus] = useState<"idle" | "saving" | "saved">("idle") const [error, setError] = useState("") + // follows the slider at once, the save comes a moment later + const [dim, setDim] = useState(data.wallpaperDim) + const dimSave = useRef>(undefined) // Every control saves on its own. `action` returns a message when it failed. const run = async (action: () => Promise) => { @@ -106,6 +109,7 @@ function Settings() { title?: string searchEngine?: Engine wallpaperUrl?: string | null + wallpaperDim?: number clockFont?: ClockFont clockStyle?: ClockStyle }) => run(() => saveSettings({ data: patch })) @@ -339,11 +343,18 @@ function Settings() {
- Current wallpaper +
+ Current wallpaper + {/* as dark as on the dashboard */} +
+
Image address @@ -407,6 +418,44 @@ function Settings() {
+ + + + Darken + + + How much the wallpaper is darkened, so that the text on it + stays readable. + + + + { + const wallpaperDim = Number(e.target.value) + setDim(wallpaperDim) + // one save when the slider rests, not one per step + clearTimeout(dimSave.current) + dimSave.current = setTimeout( + () => save({ wallpaperDim }), + 400 + ) + }} + className="w-48 accent-accent scheme-dark" + /> + + {dim}% + + + diff --git a/src/styles.css b/src/styles.css index 9f3a61b..187f115 100644 --- a/src/styles.css +++ b/src/styles.css @@ -25,19 +25,3 @@ background: black; } } - -/* Halftone dots plus a fade to black, as on the reference start page */ -@utility wallpaper-dither { - background-image: - linear-gradient( - to bottom, - rgb(0 0 0 / 0.45), - rgb(0 0 0 / 0.25) 30%, - rgb(0 0 0 / 0.4) 65%, - rgb(0 0 0 / 0.95) 100% - ), - radial-gradient(rgb(0 0 0 / 0.45) 1px, transparent 1.5px); - background-size: - auto, - 4px 4px; -}