minor fix
This commit is contained in:
@ -157,8 +157,18 @@ const NotificationPositionPicker = ({
|
||||
);
|
||||
};
|
||||
|
||||
const mapNotifPosition = (
|
||||
p: SettingsState['notificationPosition'],
|
||||
): NotificationPosition => {
|
||||
const [vertical, horizontal] = p.split('-') as ['top' | 'bottom', 'left' | 'center' | 'right'];
|
||||
return { vertical, horizontal };
|
||||
};
|
||||
|
||||
const Settings = () => {
|
||||
const [lastSavedSettings, setLastSavedSettings] = useState<SettingsState>(() => {
|
||||
if (typeof window === 'undefined') return defaultSettings;
|
||||
return safeParseSettings(localStorage.getItem(STORAGE_KEY)) ?? defaultSettings;
|
||||
});
|
||||
const [notifOpen, setNotifOpen] = useState(false);
|
||||
const [notifMsg, setNotifMsg] = useState<React.ReactNode>('');
|
||||
const [notifSeverity, setNotifSeverity] = useState<
|
||||
@ -176,22 +186,22 @@ const Settings = () => {
|
||||
});
|
||||
|
||||
const dirty = useMemo(() => {
|
||||
if (typeof window === 'undefined') return false;
|
||||
const saved = safeParseSettings(localStorage.getItem(STORAGE_KEY)) ?? defaultSettings;
|
||||
return JSON.stringify(saved) !== JSON.stringify(settings);
|
||||
}, [settings]);
|
||||
return JSON.stringify(settings) !== JSON.stringify(lastSavedSettings);
|
||||
}, [settings, lastSavedSettings]);
|
||||
|
||||
const save = () => {
|
||||
try {
|
||||
localStorage.setItem(STORAGE_KEY, JSON.stringify(settings));
|
||||
|
||||
setLastSavedSettings(settings);
|
||||
|
||||
window.dispatchEvent(new CustomEvent('settings-updated'));
|
||||
|
||||
// если уведомления выключены — НЕ показываем нотификацию
|
||||
if (!isNotificationsEnabled()) return;
|
||||
setNotifMsg('Настройки успешно сохранены!');
|
||||
setNotifSeverity('info');
|
||||
setNotifPos(getNotifPositionFromSettings());
|
||||
setNotifPos(mapNotifPosition(settings.notificationPosition));
|
||||
setNotifOpen(true);
|
||||
} catch (e) {
|
||||
console.error('Не удалось сохранить настройки', e);
|
||||
@ -200,6 +210,8 @@ const Settings = () => {
|
||||
|
||||
const reset = () => {
|
||||
setSettings(defaultSettings);
|
||||
setLastSavedSettings(defaultSettings);
|
||||
|
||||
try {
|
||||
localStorage.setItem(STORAGE_KEY, JSON.stringify(defaultSettings));
|
||||
} catch (e) {
|
||||
@ -208,28 +220,21 @@ const Settings = () => {
|
||||
};
|
||||
|
||||
const checkNotif = () => {
|
||||
if (!settings.notifications) return; // если выключены — не показываем
|
||||
|
||||
setNotifMsg('Проверка уведомления!');
|
||||
setNotifSeverity('info');
|
||||
setNotifPos(getNotifPositionFromSettings());
|
||||
setNotifPos(mapNotifPosition(settings.notificationPosition)); // 👈 важно
|
||||
setNotifOpen(true);
|
||||
}
|
||||
};
|
||||
|
||||
// Apply a few settings instantly
|
||||
useEffect(() => {
|
||||
if (typeof document === 'undefined') return;
|
||||
|
||||
// UI scale (простая версия)
|
||||
document.documentElement.style.zoom = `${settings.uiScale}%`;
|
||||
|
||||
// Reduce motion
|
||||
const scale = settings.uiScale / 100;
|
||||
document.documentElement.style.setProperty('--ui-scale', String(scale));
|
||||
document.body.classList.toggle('reduce-motion', settings.reduceMotion);
|
||||
|
||||
// Blur effects (можно использовать этот класс в sx, если захочешь)
|
||||
document.body.classList.toggle('no-blur', !settings.blurEffects);
|
||||
|
||||
// Persist
|
||||
save();
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [settings.uiScale, settings.reduceMotion, settings.blurEffects]);
|
||||
|
||||
const SectionTitle = ({ children }: { children: string }) => (
|
||||
|
||||
Reference in New Issue
Block a user