Spaces:
Running
Running
Commit ·
874b177
1
Parent(s): 96f06ee
fix
Browse filesFiles changed (4)
123434 unmodified lines394041424344454628 unmodified lines757677787980818283848586878889909192939495969798import React from 'react';import { motion } from 'framer-motion';import { useNavigate, useLocation } from 'react-router-dom';import { useAuth } from '../context/AuthContext';34 unmodified linesconst Sidebar = () => {const navigate = useNavigate();const location = useLocation();const { logout } = useAuth();const { t } = useTranslation();const handleLogout = () => {logout();28 unmodified lineslabel={t(`sidebar.${item.labelKey}`)}active={location.pathname === item.path}onClick={() => navigate(item.path)}badge={item.labelKey === 'projects' ? '12' : null}/>))}</nav><div className="flex flex-col gap-4"><div className="p-4 bg-secondary/5 rough-border border-dashed border-secondary/30 flex flex-col gap-4"><div className="flex items-center justify-between"><span className="font-accent-note text-2xl text-secondary">{t('sidebar.free_plan')}</span><span className="text-xs font-bold text-primary">3/5 Slots</span></div><buttononClick={() => navigate('/subscription')}className="w-full py-2 bg-primary text-on-primary text-sm font-bold rounded-lg hover:bg-secondary hover:text-primary transition-all">{t('sidebar.upgrade_now')}</button></div><buttononClick={handleLogout}1234534 unmodified lines4041424344454647484950515253545556575859606162636465666728 unmodified lines96979899100101102103104105106107108109110111112113114115116117118119120121import React, { useState, useEffect } from 'react';import axios from 'axios';import { motion } from 'framer-motion';import { useNavigate, useLocation } from 'react-router-dom';import { useAuth } from '../context/AuthContext';34 unmodified linesconst Sidebar = () => {const navigate = useNavigate();const location = useLocation();const { logout, user } = useAuth();const { t } = useTranslation();const [projectCount, setProjectCount] = useState(0);useEffect(() => {if (!user) return;const fetchProjectCount = async () => {try {const API_URL = import.meta.env.VITE_API_URL;const res = await axios.get(`${API_URL}/graphs/user/${user.id}`);if (Array.isArray(res.data)) {setProjectCount(res.data.length);}} catch (err) {console.error('[Sidebar] Failed to fetch project count:', err);}};fetchProjectCount();const interval = setInterval(fetchProjectCount, 10000);return () => clearInterval(interval);}, [user]);const handleLogout = () => {logout();28 unmodified lineslabel={t(`sidebar.${item.labelKey}`)}active={location.pathname === item.path}onClick={() => navigate(item.path)}badge={item.labelKey === 'projects' ? projectCount.toString() : null}/>))}</nav><div className="flex flex-col gap-4">{false && (<div className="p-4 bg-secondary/5 rough-border border-dashed border-secondary/30 flex flex-col gap-4"><div className="flex items-center justify-between"><span className="font-accent-note text-2xl text-secondary">{t('sidebar.free_plan')}</span><span className="text-xs font-bold text-primary">3/5 Slots</span></div><buttononClick={() => navigate('/subscription')}className="w-full py-2 bg-primary text-on-primary text-sm font-bold rounded-lg hover:bg-secondary hover:text-primary transition-all">{t('sidebar.upgrade_now')}</button></div>)}<buttononClick={handleLogout}
136 unmodified lines137138139140141142136 unmodified linesconst triggerNotification = (achievement) => {playUnlockSound();setActiveNotification(achievement);// Auto-clear after 6 secondssetTimeout(() => {setActiveNotification(null);136 unmodified lines137138139140141142143144145146147148149150151152153154155136 unmodified linesconst triggerNotification = (achievement) => {playUnlockSound();setActiveNotification(achievement);const desktopNotifEnabled = localStorage.getItem('desktop_notifications') === 'true';if (desktopNotifEnabled && 'Notification' in window && Notification.permission === 'granted') {try {new Notification(`🏆 Achievement Unlocked: ${achievement.title}`, {body: achievement.desc,icon: '/favicon.ico'});} catch (e) {console.warn('[Notifications] Failed to display native desktop notification:', e);}}// Auto-clear after 6 secondssetTimeout(() => {setActiveNotification(null);
87 unmodified lines888990919293152 unmodified lines24624724824925025125225325425525625725825926026126226326426564 unmodified lines33033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437587 unmodified linesconst [uploading, setUploading] = React.useState(false);const [isAllAchievementsOpen, setIsAllAchievementsOpen] = React.useState(false);const [activeFilter, setActiveFilter] = React.useState('all');React.useEffect(() => {if (!user) {152 unmodified lines</div><div className="flex gap-4"><buttononClick={() => triggerNotification({id: 'test-achievement-' + Date.now(),title: 'Sketch Master',desc: 'Create 100 task nodes overall.',icon: 'Zap',color: 'bg-yellow-500/20',unlocked: true})}className="bg-surface-container-lowest p-4 rough-border rough-shadow-hover hover:text-primary transition-all text-secondary"title="Test Achievement Unlock Animation"><Trophy size={28} /></button><buttononClick={() => navigate('/settings')}className="bg-surface-container-lowest p-4 rough-border rough-shadow-hover hover:text-primary transition-all text-primary"64 unmodified lines<label className="text-xs font-bold uppercase tracking-widest text-on-surface-variant flex items-center gap-2"><Mail size={14} /> {t('auth.email')}</label><input type="email" defaultValue={user?.email} className="w-full p-3 bg-surface-container-low border-2 border-primary/10 rounded-lg focus:border-primary outline-none transition-all" /></div><div className="flex flex-col gap-2"><label className="text-xs font-bold uppercase tracking-widest text-on-surface-variant flex items-center gap-2"><Lock size={14} /> {t('auth.password')}</label><input type="password" defaultValue="********" className="w-full p-3 bg-surface-container-low border-2 border-primary/10 rounded-lg focus:border-primary outline-none transition-all" /></div><button className="bg-primary text-on-primary py-3 px-6 font-bold rough-border rough-shadow-hover transition-all mt-2">{t('profile.save_changes', 'Save Changes')}</button></div></div><div className="flex flex-col gap-6"><h3 className="text-4xl font-display-lg text-primary">{t('profile.privacy_display', 'Privacy & Display')}</h3><div className="bg-surface-container-lowest p-8 rough-border flex flex-col gap-8"><div className="flex items-center justify-between"><div><div className="font-bold">{t('profile.public_profile', 'Public Profile')}</div><div className="text-xs text-on-surface-variant">{t('profile.public_profile_desc', 'Allow others to see your achievements')}</div></div><div className="w-14 h-8 bg-secondary rough-border p-1 flex justify-end items-center"><div className="w-6 h-6 bg-primary rounded-sm" /></div></div><div className="flex items-center justify-between opacity-50"><div><div className="font-bold">{t('profile.focus_mode', 'Focus Mode')}</div><div className="text-xs text-on-surface-variant">{t('profile.focus_mode_desc', 'Hide statistics during deep work sessions')}</div></div><div className="w-14 h-8 bg-surface-variant rough-border p-1 flex justify-start items-center grayscale"><div className="w-6 h-6 bg-on-surface-variant rounded-sm" /></div></div><div className="mt-auto font-accent-note text-2xl text-secondary text-center transform -rotate-1">"{t('profile.privacy_quote', "Your data is stored locally first. You're in control.")}"</div></div></div></div></div>87 unmodified lines888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140152 unmodified lines29329429529629729829930030130230330430530630730830931031131231331464 unmodified lines37938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944087 unmodified linesconst [uploading, setUploading] = React.useState(false);const [isAllAchievementsOpen, setIsAllAchievementsOpen] = React.useState(false);const [activeFilter, setActiveFilter] = React.useState('all');const [password, setPassword] = React.useState('');const handleSaveChanges = async () => {if (!user) return;try {const payload = {};if (password && password.trim() !== '') {payload.password = password;} else {triggerNotification({id: 'account-update-info-' + Date.now(),title: t('profile.no_changes', 'No Changes'),desc: t('profile.no_changes_desc', 'No changes were made to your account details.'),icon: 'ShieldCheck',color: 'bg-blue-500/20',unlocked: true});return;}const API_URL = import.meta.env.VITE_API_URL;const res = await axios.put(`${API_URL}/users/${user.id}`, payload);if (res.data) {updateUser(res.data);setPassword('');triggerNotification({id: 'account-update-success-' + Date.now(),title: t('profile.changes_saved', 'Changes Saved!'),desc: t('profile.changes_saved_desc', 'Your account details have been successfully updated.'),icon: 'ShieldCheck',color: 'bg-green-500/20',unlocked: true});}} catch (err) {console.error('[ProfilePage] Failed to save changes:', err);triggerNotification({id: 'account-update-error-' + Date.now(),title: t('profile.update_failed', 'Update Failed'),desc: err.response?.data?.message || err.message,icon: 'X',color: 'bg-red-500/20',unlocked: true});}};React.useEffect(() => {if (!user) {152 unmodified lines</div><div className="flex gap-4">{false && (<buttononClick={() => triggerNotification({id: 'test-achievement-' + Date.now(),title: 'Sketch Master',desc: 'Create 100 task nodes overall.',icon: 'Zap',color: 'bg-yellow-500/20',unlocked: true})}className="bg-surface-container-lowest p-4 rough-border rough-shadow-hover hover:text-primary transition-all text-secondary"title="Test Achievement Unlock Animation"><Trophy size={28} /></button>)}<buttononClick={() => navigate('/settings')}className="bg-surface-container-lowest p-4 rough-border rough-shadow-hover hover:text-primary transition-all text-primary"64 unmodified lines<label className="text-xs font-bold uppercase tracking-widest text-on-surface-variant flex items-center gap-2"><Mail size={14} /> {t('auth.email')}</label><inputtype="email"defaultValue={user?.email}disabledclassName="w-full p-3 bg-surface-container-low border-2 border-primary/10 rounded-lg outline-none transition-all cursor-not-allowed opacity-60"/></div><div className="flex flex-col gap-2"><label className="text-xs font-bold uppercase tracking-widest text-on-surface-variant flex items-center gap-2"><Lock size={14} /> {t('auth.password')}</label><inputtype="password"value={password}onChange={(e) => setPassword(e.target.value)}placeholder="••••••••"className="w-full p-3 bg-surface-container-low border-2 border-primary/10 rounded-lg focus:border-primary outline-none transition-all"/></div><buttononClick={handleSaveChanges}className="bg-primary text-on-primary py-3 px-6 font-bold rough-border rough-shadow-hover transition-all mt-2">{t('profile.save_changes', 'Save Changes')}</button></div></div>{false && (<div className="flex flex-col gap-6"><h3 className="text-4xl font-display-lg text-primary">{t('profile.privacy_display', 'Privacy & Display')}</h3><div className="bg-surface-container-lowest p-8 rough-border flex flex-col gap-8"><div className="flex items-center justify-between"><div><div className="font-bold">{t('profile.public_profile', 'Public Profile')}</div><div className="text-xs text-on-surface-variant">{t('profile.public_profile_desc', 'Allow others to see your achievements')}</div></div><div className="w-14 h-8 bg-secondary rough-border p-1 flex justify-end items-center"><div className="w-6 h-6 bg-primary rounded-sm" /></div></div><div className="flex items-center justify-between opacity-50"><div><div className="font-bold">{t('profile.focus_mode', 'Focus Mode')}</div><div className="text-xs text-on-surface-variant">{t('profile.focus_mode_desc', 'Hide statistics during deep work sessions')}</div></div><div className="w-14 h-8 bg-surface-variant rough-border p-1 flex justify-start items-center grayscale"><div className="w-6 h-6 bg-on-surface-variant rounded-sm" /></div></div><div className="mt-auto font-accent-note text-2xl text-secondary text-center transform -rotate-1">"{t('profile.privacy_quote', "Your data is stored locally first. You're in control.")}"</div></div></div>)}</div></div>
39 unmodified lines404142434445461 unmodified line48495051525354555657585977 unmodified lines13713813914014114214339 unmodified linesconst { t, i18n } = useTranslation();const [activeTab, setActiveTab] = useState('General');const [settings, setSettings] = useState({notifications: true,aiGuidance: true,snapToGrid: false,publicProfile: true,1 unmodified lineconst tabs = [{ id: 'General', labelKey: 'general', icon: Monitor },{ id: 'Canvas', labelKey: 'canvas', icon: Database },{ id: 'Privacy', labelKey: 'security', icon: Lock },];const toggleSetting = (key) => setSettings(prev => ({ ...prev, [key]: !prev[key] }));return (<div className="flex min-h-screen bg-background"><Sidebar />77 unmodified lineslabel={t('settings.notifications_title', 'Desktop Notifications')}desc={t('settings.notifications_desc', 'Receive alerts for task deadlines and habit reminders.')}active={settings.notifications}onToggle={() => toggleSetting('notifications')}/><div className="flex items-center justify-between py-6 border-b border-primary/5">39 unmodified lines404142434445461 unmodified line4849505152535455565758596061626364656667686970717273747576777879808182838485868788899077 unmodified lines16816917017117217317439 unmodified linesconst { t, i18n } = useTranslation();const [activeTab, setActiveTab] = useState('General');const [settings, setSettings] = useState({notifications: localStorage.getItem('desktop_notifications') === 'true',aiGuidance: true,snapToGrid: false,publicProfile: true,1 unmodified lineconst tabs = [{ id: 'General', labelKey: 'general', icon: Monitor },// { id: 'Canvas', labelKey: 'canvas', icon: Database },// { id: 'Privacy', labelKey: 'security', icon: Lock },];const toggleSetting = (key) => setSettings(prev => ({ ...prev, [key]: !prev[key] }));const toggleNotifications = async () => {const nextVal = !settings.notifications;if (nextVal) {if ('Notification' in window) {const permission = await Notification.requestPermission();if (permission === 'granted') {localStorage.setItem('desktop_notifications', 'true');setSettings(prev => ({ ...prev, notifications: true }));try {new Notification(t('notifications.enabled_title', 'Desktop Notifications Enabled'), {body: t('notifications.enabled_body', 'You will now receive alerts for task deadlines and habits!'),icon: '/favicon.ico'});} catch (e) {console.warn('[Notifications] Failed to display test notification:', e);}} else {localStorage.setItem('desktop_notifications', 'false');setSettings(prev => ({ ...prev, notifications: false }));alert(t('notifications.permission_denied', 'Notification permission denied. Please enable them in your browser settings.'));}} else {alert(t('notifications.unsupported', 'Desktop Notifications are not supported in this browser.'));}} else {localStorage.setItem('desktop_notifications', 'false');setSettings(prev => ({ ...prev, notifications: false }));}};return (<div className="flex min-h-screen bg-background"><Sidebar />77 unmodified lineslabel={t('settings.notifications_title', 'Desktop Notifications')}desc={t('settings.notifications_desc', 'Receive alerts for task deadlines and habit reminders.')}active={settings.notifications}onToggle={toggleNotifications}/><div className="flex items-center justify-between py-6 border-b border-primary/5">
src/components/Sidebar.jsx+37-14
src/context/AchievementNotificationContext.jsx+13
src/pages/ProfilePage.jsx+103-38
src/pages/SettingsPage.jsx+35-4