import React, { useState, useEffect } from 'react'; import { motion } from 'framer-motion'; import { toast } from 'react-toastify'; import { classNames } from '~/utils/classNames'; import { Switch } from '~/components/ui/Switch'; import type { UserProfile } from '~/components/@settings/core/types'; import { isMac } from '~/utils/os'; // Helper to get modifier key symbols/text const getModifierSymbol = (modifier: string): string => { switch (modifier) { case 'meta': return isMac ? '⌘' : 'Win'; case 'alt': return isMac ? '⌥' : 'Alt'; case 'shift': return '⇧'; default: return modifier; } }; export default function SettingsTab() { const [currentTimezone, setCurrentTimezone] = useState(''); const [settings, setSettings] = useState(() => { const saved = localStorage.getItem('bolt_user_profile'); return saved ? JSON.parse(saved) : { notifications: true, language: 'en', timezone: Intl.DateTimeFormat().resolvedOptions().timeZone, }; }); useEffect(() => { setCurrentTimezone(Intl.DateTimeFormat().resolvedOptions().timeZone); }, []); // Save settings automatically when they change useEffect(() => { try { // Get existing profile data const existingProfile = JSON.parse(localStorage.getItem('bolt_user_profile') || '{}'); // Merge with new settings const updatedProfile = { ...existingProfile, notifications: settings.notifications, language: settings.language, timezone: settings.timezone, }; localStorage.setItem('bolt_user_profile', JSON.stringify(updatedProfile)); toast.success('Settings updated'); } catch (error) { console.error('Error saving settings:', error); toast.error('Failed to update settings'); } }, [settings]); return (
{/* Language & Notifications */}
Preferences
{settings.notifications ? 'Notifications are enabled' : 'Notifications are disabled'} { // Update local state setSettings((prev) => ({ ...prev, notifications: checked })); // Update localStorage immediately const existingProfile = JSON.parse(localStorage.getItem('bolt_user_profile') || '{}'); const updatedProfile = { ...existingProfile, notifications: checked, }; localStorage.setItem('bolt_user_profile', JSON.stringify(updatedProfile)); // Dispatch storage event for other components window.dispatchEvent( new StorageEvent('storage', { key: 'bolt_user_profile', newValue: JSON.stringify(updatedProfile), }), ); toast.success(`Notifications ${checked ? 'enabled' : 'disabled'}`); }} />
{/* Timezone */}
Time Settings
{/* Simplified Keyboard Shortcuts */}
Keyboard Shortcuts
Toggle Theme Switch between light and dark mode
{getModifierSymbol('meta')} {getModifierSymbol('alt')} {getModifierSymbol('shift')} D
); }