import { useState, useEffect } from "react"; import { PRODUCT_NAME, API_BASE_URL } from "../../../../../core/config"; import type { DialogProps } from "../../../../../core/types"; import { MaterialDialog } from "../core/Dialog"; import { initialize, isSupported, startElectronReceiver, stopElectronReceiver, subscribe, unsubscribe } from "../../../../../core/push-notifications/push-notifications"; import { isElectron } from "../../../../../core/electron/electron"; import { useAppState } from "../../state"; import type { Switch } from "mdui/components/switch"; import { getAuthHeaders } from "../../../../../core/api/authApi"; export function SettingsDialog({ isOpen, onOpenChange }: DialogProps) { const [activePanel, setActivePanel] = useState("notifications-settings"); const [pushNotificationsEnabled, setPushNotificationsEnabled] = useState(false); const [pushSupported, setPushSupported] = useState(false); const user = useAppState(state => state.user); useEffect(() => { setPushSupported(isSupported()); // For Electron, we assume notifications are enabled if supported // For web browsers, we check if there's a subscription setPushNotificationsEnabled(isSupported()); }, []); const handlePanelChange = (panelId: string) => { setActivePanel(panelId); }; const handlePushNotificationToggle = async (enabled: boolean) => { if (!user.authToken) return; try { if (enabled) { const initialized = await initialize(); if (initialized) { await subscribe(user.authToken); // For Electron, start the notification receiver if (isElectron) { await startElectronReceiver(); } setPushNotificationsEnabled(true); } } else { await unsubscribe(); // For Electron, stop the notification receiver if (isElectron) { stopElectronReceiver(); } // Call API to unsubscribe on server (for web browsers) await fetch(`${API_BASE_URL}/push/unsubscribe`, { method: "DELETE", headers: getAuthHeaders(user.authToken) }); setPushNotificationsEnabled(false); } } catch (error) { console.error("Failed to toggle notifications:", error); } }; return (
onOpenChange(false)}> Настройки
handlePanelChange("notifications-settings")} style={{ cursor: "pointer" }} > Уведомления handlePanelChange("appearance-settings")} style={{ cursor: "pointer" }} > Внешний вид handlePanelChange("security-settings")} style={{ cursor: "pointer" }} > Безопасность handlePanelChange("language-settings")} style={{ cursor: "pointer" }} > Язык handlePanelChange("storage-settings")} style={{ cursor: "pointer" }} > Хранилище handlePanelChange("help-settings")} style={{ cursor: "pointer" }} > Помощь handlePanelChange("about-settings")} style={{ cursor: "pointer" }} > О приложении

Уведомления

{pushSupported && ( handlePushNotificationToggle((e.target as Switch).checked)} > Push уведомления )} Новые сообщения Звуковые уведомления Уведомления о статусе Email уведомления

Внешний вид

Тёмная Светлая Авто Маленький Средний Большой

Безопасность

Изменить пароль Двухфакторная аутентификация Автоматический выход

Язык

Русский English Español

Хранилище

Использовано: 2.5 ГБ из 10 ГБ

Очистить кэш

Помощь

Руководство пользователя Связаться с поддержкой FAQ

О приложении

Версия: 1.0.0

© 2025 {PRODUCT_NAME}. Все права защищены.

Политика конфиденциальности Условия использования
); }