fix(cms): align profile, site navigation and surfaces with design system
DC CMS qualification / qualify (push) Successful in 1m52s

This commit is contained in:
DCCONSTRUCTIONS
2026-11-05 12:34:43 +03:00
parent 8a17013579
commit 73bf4639a2
15 changed files with 225 additions and 150 deletions
+58
View File
@@ -0,0 +1,58 @@
import React, { useEffect, useState } from "react";
import { createRoot } from "react-dom/client";
import { flushSync } from "react-dom";
import { applyNodedcTheme } from "@nodedc/ui-dom";
import { HeaderProfile, UserProfileMenu, IconButton, Icon, FeatureSettingsWindow, SettingsCard, Select, ColorField, Button } from "@nodedc/ui-react";
const h = React.createElement;
const storageKey = "dc-cms.ui-preferences.v1";
const defaults = { theme: "dark", accent: "#ffffff" };
function normalize(value) {
return { theme: value?.theme === "light" ? "light" : "dark", accent: /^#[\da-f]{6}$/i.test(value?.accent || "") ? value.accent.toLowerCase() : defaults.accent };
}
function read() {
try { return normalize(JSON.parse(localStorage.getItem(storageKey))); } catch { return { ...defaults }; }
}
function apply(preferences) {
const accent = preferences.accent.match(/[\da-f]{2}/gi).map(v => parseInt(v, 16));
applyNodedcTheme(document.documentElement, { theme: preferences.theme, accent, edges: "flat" });
}
function Preferences({ initial }) {
const [preferences, setPreferences] = useState(initial);
const [open, setOpen] = useState(false);
const [session, setSession] = useState(null);
const [storageError, setStorageError] = useState(false);
useEffect(() => {
const controller = new AbortController();
fetch("/api/me", { credentials: "same-origin", signal: controller.signal }).then(r => r.ok ? r.json() : null).then(setSession).catch(() => {});
const sync = event => { if (event.key === storageKey || event.key === null) { const value = read(); apply(value); setPreferences(value); } };
window.addEventListener("storage", sync);
return () => { controller.abort(); window.removeEventListener("storage", sync); };
}, []);
function update(patch) {
const value = normalize({ ...preferences, ...patch });
apply(value);
setPreferences(value);
try { localStorage.setItem(storageKey, JSON.stringify(value)); setStorageError(false); } catch { setStorageError(true); }
}
const user = session?.user;
const name = user?.name || user?.username || "Профиль";
const actions = [{ id: "appearance", label: "Настройки интерфейса", icon: "settings", onSelect: () => setOpen(true) }];
if (session?.authEnabled) actions.push({ id: "logout", label: "Выйти", icon: "external", href: "/auth/logout" });
return h(React.Fragment, null,
h(HeaderProfile, null,
h(UserProfileMenu, { displayName: name, subtitle: user?.email || undefined, avatarUrl: user?.picture || undefined, triggerLabel: "Профиль", triggerIcon: "inbox", actions }),
h(IconButton, { label: "Настройки интерфейса", onClick: () => setOpen(true) }, h(Icon, { name: "settings" }))
),
h(FeatureSettingsWindow, { open, title: "Настройки", subtitle: "Интерфейс CMS", identity: { title: name, subtitle: "NODE.DC CMS", avatarLabel: name, avatarUrl: user?.picture || undefined }, sections: [{ id: "appearance", label: "Оформление", icon: "settings", group: "Общие" }], activeSection: "appearance", onSectionChange: () => {}, onClose: () => setOpen(false),
footer: h(Button, { onClick: () => update(defaults), tone: "neutral" }, "Сбросить оформление") },
h("div", {className:"cms-preferences-fields"}, h(SettingsCard, { title: "Тема", description: "Светлый или тёмный интерфейс", actions: h("div", { className: "cms-preference-controls" }, h(Select, { label: "Тема интерфейса", value: preferences.theme, options: [{ value: "dark", label: "Тёмная" }, { value: "light", label: "Светлая" }], onChange: theme => update({ theme }) })) }),
h(SettingsCard, { title: "Акцентный цвет", description: "Цвет активных элементов", actions: h("div", { className: "cms-preference-controls" }, h(ColorField, { label: "Акцентный цвет", value: preferences.accent, onChange: accent => update({ accent }) })) })),
h("p", { className: "nodedc-description", role: "status" }, storageError ? "Настройки действуют в этой вкладке. Браузер не разрешил сохранить их для следующего входа." : "Изменения сохраняются автоматически в этом браузере.")
)
);
}
export function installPreferences() {
const preferences = read();
apply(preferences);
flushSync(() => createRoot(document.querySelector("#cms-profile")).render(h(Preferences, { initial: preferences })));
}