feat: persist complete multitheme palettes
This commit is contained in:
1 parent
3fd2a27719
commit
9cdd0b4000
4 files changed
+69
-21
No files matched your search
@@ -7,24 +7,11 @@ import { prisma } from "@/lib/prisma";
|
||||
import { siteSettings } from "@/lib/services/site-settings";
|
||||
import { logStaffActivity } from "@/lib/services/staff-activity";
|
||||
import { FONTS, PRESETS, THEME_COLOR_KEYS } from "@/lib/theme-presets";
|
||||
import { presetSettings, settingKey } from "@/lib/theme-settings";
|
||||
|
||||
// Only hex/keyword colour values are accepted (matches ThemeVars' sanitiser).
|
||||
const COLOR_RE = /^[#a-zA-Z0-9(),.\s%-]+$/;
|
||||
// Extra colour settings beyond the preset palette (buttons + links + gradients).
|
||||
const EXTRA_COLOR_KEYS = [
|
||||
"button_secondary_color",
|
||||
"button_secondary_text_color",
|
||||
"button_danger_color",
|
||||
"button_danger_text_color",
|
||||
"button_outline_color",
|
||||
"button_outline_text_color",
|
||||
"button_secondary_hover_color",
|
||||
"button_danger_hover_color",
|
||||
"link_color",
|
||||
"link_hover_color",
|
||||
"gradient_from",
|
||||
"gradient_to",
|
||||
];
|
||||
const HEADING_KEYS = ["size_heading_h1", "size_heading_h2", "size_heading_h3"];
|
||||
const CUSTOM_CSS_MAX = 20000;
|
||||
|
||||
@@ -40,9 +27,12 @@ export async function saveTheme(formData: FormData): Promise<void> {
|
||||
const staff = await requireStaff();
|
||||
|
||||
try {
|
||||
for (const key of [...THEME_COLOR_KEYS, ...EXTRA_COLOR_KEYS]) {
|
||||
const raw = String(formData.get(key) ?? "").trim();
|
||||
if (raw && COLOR_RE.test(raw)) await writeSetting(key, raw);
|
||||
for (const mode of ["light", "dark"] as const) {
|
||||
for (const key of THEME_COLOR_KEYS) {
|
||||
const dbKey = settingKey(key, mode);
|
||||
const raw = String(formData.get(dbKey) ?? "").trim();
|
||||
if (raw && COLOR_RE.test(raw)) await writeSetting(dbKey, raw);
|
||||
}
|
||||
}
|
||||
const radius = String(formData.get("border_radius") ?? "").trim();
|
||||
if (/^\d{1,3}$/.test(radius)) await writeSetting("border_radius", radius);
|
||||
@@ -82,7 +72,8 @@ export async function applyPreset(formData: FormData): Promise<void> {
|
||||
if (!preset) redirect("/admin/theme");
|
||||
|
||||
try {
|
||||
for (const [key, value] of Object.entries(preset)) await writeSetting(key, value);
|
||||
for (const [key, value] of presetSettings(preset)) await writeSetting(key, value);
|
||||
await writeSetting("theme_preset", name);
|
||||
siteSettings.reload();
|
||||
await logStaffActivity({
|
||||
staffId: staff.id,
|
||||
|
||||
Reference in new issue
Block a user