From b3b499e21871c88645b0459e6f41f6089d5e6dc9 Mon Sep 17 00:00:00 2001 From: thiloho <123883702+thiloho@users.noreply.github.com> Date: Fri, 27 Sep 2024 16:59:29 +0200 Subject: [PATCH] Refactor web app code and add background color setting --- .../migrations/20240719071602_main_tables.sql | 6 +- ...20240720132802_exposed_views_functions.sql | 2 +- .../src/lib/components/MarkdownEditor.svelte | 72 +++++++++++ .../src/lib/components/WebsiteEditor.svelte | 13 +- web-app/src/lib/db-schema.ts | 12 +- web-app/src/lib/runes.svelte.ts | 30 +++++ .../src/lib/templates/common/Footer.svelte | 4 +- web-app/src/lib/utils.ts | 80 +++++++----- .../src/routes/(anonymous)/login/+page.svelte | 19 +-- .../routes/(anonymous)/register/+page.svelte | 19 +-- .../src/routes/(authenticated)/+page.svelte | 41 +----- .../(authenticated)/account/+page.svelte | 34 +---- .../website/[websiteId]/+page.server.ts | 4 +- .../website/[websiteId]/+page.svelte | 121 ++++++------------ .../website/[websiteId]/articles/+page.svelte | 33 +---- .../articles/[articleId]/+page.svelte | 57 ++------- .../[websiteId]/categories/+page.svelte | 43 ++----- .../[websiteId]/collaborators/+page.svelte | 38 +----- .../legal-information/+page.server.ts | 3 +- .../legal-information/+page.svelte | 59 ++------- .../website/[websiteId]/logs/+page.svelte | 9 +- .../[websiteId]/publish/+page.server.ts | 52 +++++--- .../website/[websiteId]/publish/+page.svelte | 41 ++---- web-app/src/routes/+layout.svelte | 3 +- web-app/svelte.config.js | 4 +- web-app/template-styles/common-styles.css | 49 ++++--- web-app/tests/collaborator.spec.ts | 12 +- web-app/tests/website.spec.ts | 8 +- 28 files changed, 375 insertions(+), 493 deletions(-) create mode 100644 web-app/src/lib/components/MarkdownEditor.svelte create mode 100644 web-app/src/lib/runes.svelte.ts diff --git a/rest-api/db/migrations/20240719071602_main_tables.sql b/rest-api/db/migrations/20240719071602_main_tables.sql index 8d7de5c..2c023ab 100644 --- a/rest-api/db/migrations/20240719071602_main_tables.sql +++ b/rest-api/db/migrations/20240719071602_main_tables.sql @@ -53,8 +53,10 @@ CREATE TABLE internal.media ( CREATE TABLE internal.settings ( website_id UUID PRIMARY KEY REFERENCES internal.website (id) ON DELETE CASCADE, - accent_color_light_theme CHAR(7) CHECK (accent_color_light_theme ~ '^#[a-fA-F0-9]{6}$') NOT NULL DEFAULT '#a5d8ff', - accent_color_dark_theme CHAR(7) CHECK (accent_color_dark_theme ~ '^#[a-fA-F0-9]{6}$') NOT NULL DEFAULT '#114678', + accent_color_dark_theme CHAR(7) CHECK (accent_color_light_theme ~ '^#[a-fA-F0-9]{6}$') NOT NULL DEFAULT '#a5d8ff', + accent_color_light_theme CHAR(7) CHECK (accent_color_dark_theme ~ '^#[a-fA-F0-9]{6}$') NOT NULL DEFAULT '#114678', + background_color_dark_theme CHAR(7) CHECK (accent_color_light_theme ~ '^#[a-fA-F0-9]{6}$') NOT NULL DEFAULT '#262626', + background_color_light_theme CHAR(7) CHECK (accent_color_dark_theme ~ '^#[a-fA-F0-9]{6}$') NOT NULL DEFAULT '#ffffff', favicon_image UUID REFERENCES internal.media (id) ON DELETE SET NULL, last_modified_at TIMESTAMPTZ NOT NULL DEFAULT CLOCK_TIMESTAMP(), last_modified_by UUID REFERENCES internal.user (id) ON DELETE SET NULL diff --git a/rest-api/db/migrations/20240720132802_exposed_views_functions.sql b/rest-api/db/migrations/20240720132802_exposed_views_functions.sql index 89c0f3e..0e7e4aa 100644 --- a/rest-api/db/migrations/20240720132802_exposed_views_functions.sql +++ b/rest-api/db/migrations/20240720132802_exposed_views_functions.sql @@ -131,7 +131,7 @@ GRANT SELECT, UPDATE (title, is_published), DELETE ON internal.website TO authen GRANT SELECT, UPDATE, DELETE ON api.website TO authenticated_user; -GRANT SELECT, UPDATE (accent_color_light_theme, accent_color_dark_theme, favicon_image) ON internal.settings TO authenticated_user; +GRANT SELECT, UPDATE (accent_color_dark_theme, accent_color_light_theme, background_color_dark_theme, background_color_light_theme, favicon_image) ON internal.settings TO authenticated_user; GRANT SELECT, UPDATE ON api.settings TO authenticated_user; diff --git a/web-app/src/lib/components/MarkdownEditor.svelte b/web-app/src/lib/components/MarkdownEditor.svelte new file mode 100644 index 0000000..cbe47c6 --- /dev/null +++ b/web-app/src/lib/components/MarkdownEditor.svelte @@ -0,0 +1,72 @@ + + + diff --git a/web-app/src/lib/components/WebsiteEditor.svelte b/web-app/src/lib/components/WebsiteEditor.svelte index 0038b73..639cb06 100644 --- a/web-app/src/lib/components/WebsiteEditor.svelte +++ b/web-app/src/lib/components/WebsiteEditor.svelte @@ -2,30 +2,27 @@ import type { Snippet } from "svelte"; import { md } from "$lib/utils"; import { page } from "$app/stores"; + import { previewContent, textareaScrollTop } from "$lib/runes.svelte"; const { id, contentType, title, children, - fullPreview = false, - previewContent, - previewScrollTop = 0 + fullPreview = false }: { id: string; contentType: string; title: string; children: Snippet; fullPreview?: boolean; - previewContent: string; - previewScrollTop?: number; } = $props(); let previewElement: HTMLDivElement; $effect(() => { const scrollHeight = previewElement.scrollHeight - previewElement.clientHeight; - previewElement.scrollTop = (previewScrollTop / 100) * scrollHeight; + previewElement.scrollTop = (textareaScrollTop.value / 100) * scrollHeight; }); @@ -66,9 +63,9 @@