function Dashboard({ user: initialUser, token, onLogout }) {
const [user, setUser] = useState(initialUser);
const [activeTab, setActiveTab] = useState('home');
const [showProfileMenu, setShowProfileMenu] = useState(false);
const [showSettings, setShowSettings] = useState(false);
const [showProfile, setShowProfile] = useState(false);
const [showFeedbackModal, setShowFeedbackModal] = useState(false);
const [actionParams, setActionParams] = useState(null); // For passing actions between tabs
const [settings, setSettings] = useState(() => {
const saved = localStorage.getItem('appSettings');
const defaults = {
appearance: 'light',
fontSize: 'medium',
dailyWord: true, // ON by default
dailyQuote: true, // ON by default
fileStorage: false
};
return saved ? { ...defaults, ...JSON.parse(saved) } : defaults;
});
const { t, language, setLanguage } = useTranslation();
const tabs = [
{ id: 'home', label: t('navigation.home'), icon: '🏠' },
{ id: 'notes', label: t('navigation.notes'), icon: '📝' },
{ id: 'ask', label: t('navigation.ask'), icon: '❓' },
{ id: 'share', label: 'Share Notes', icon: '🔗' },
{ id: 'tools', label: t('navigation.tools'), icon: '🔧' },
];
const languages = [
{ code: 'en', name: 'English', flag: '🇺🇸' },
{ code: 'pa', name: 'ਪੰਜਾਬੀ (Punjabi)', flag: '🇮🇳' },
{ code: 'hi', name: 'हिन्दी (Hindi)', flag: '🇮🇳' },
{ code: 'bn', name: 'বাংলা (Bengali)', flag: '🇧🇩' },
{ code: 'de', name: 'Deutsch (German)', flag: '🇩🇪' },
{ code: 'fr', name: 'Français (French)', flag: '🇫🇷' },
{ code: 'nl', name: 'Nederlands (Dutch)', flag: '🇳🇱' },
{ code: 'zh', name: '中文 (Chinese)', flag: '🇨🇳' },
{ code: 'ru', name: 'Русский (Russian)', flag: '🇷🇺' },
{ code: 'ar', name: 'العربية (Arabic)', flag: '🇸🇦' },
{ code: 'es', name: 'Español (Spanish)', flag: '🇪🇸' }
];
const updateSettings = (key, value) => {
const newSettings = { ...settings, [key]: value };
setSettings(newSettings);
localStorage.setItem('appSettings', JSON.stringify(newSettings));
};
const updateMultipleSettings = (updates) => {
const newSettings = { ...settings, ...updates };
setSettings(newSettings);
localStorage.setItem('appSettings', JSON.stringify(newSettings));
};
const handleUserUpdate = (updatedUser) => {
setUser(updatedUser);
// Update user in localStorage
const storedUser = JSON.parse(localStorage.getItem('user') || '{}');
const mergedUser = { ...storedUser, ...updatedUser };
localStorage.setItem('user', JSON.stringify(mergedUser));
};
// Apply settings on mount and when they change
useEffect(() => {
const fontSize = settings.fontSize === 'small' ? '0.875rem' : settings.fontSize === 'large' ? '1.125rem' : '1rem';
document.documentElement.style.fontSize = fontSize;
let theme = settings.appearance;
if (theme === 'auto') {
theme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
}
document.body.setAttribute('data-theme', theme);
}, [settings]);
// Close profile dropdown when clicking outside
useEffect(() => {
const handleClickOutside = (event) => {
if (showProfileMenu) {
const profileButton = event.target.closest('[data-profile-button]');
const profileMenu = event.target.closest('[data-profile-menu]');
if (!profileButton && !profileMenu) {
setShowProfileMenu(false);
}
}
};
document.addEventListener('mousedown', handleClickOutside);
return () => document.removeEventListener('mousedown', handleClickOutside);
}, [showProfileMenu]);
return (
{/* Sidebar for Desktop */}
📚 NoteVerse
{showProfileMenu && (
{/* Mobile Navigation Links */}
{tabs.map(tab => (
))}
)}
{activeTab === 'home' &&
}
{activeTab === 'dashboard' &&
}
{activeTab === 'notes' &&
}
{activeTab === 'archive' &&
}
{activeTab === 'share' && < ShareView token={token} t={t} setActiveTab={setActiveTab} setActionParams={setActionParams} />}
{activeTab === 'ask' &&
}
{activeTab === 'tools' &&
}
{/* Settings Modal */}
{showSettings && (
{
// Close if clicking on backdrop
if (e.target === e.currentTarget) {
setShowSettings(false);
}
}}
style={{
position: 'fixed',
top: 0,
left: 0,
right: 0,
bottom: 0,
background: 'rgba(0, 0, 0, 0.5)',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
zIndex: 2000,
padding: '20px'
}}>
{t('common.settings')}
{/* Appearance Mode */}
{['light', 'dark', 'auto'].map(mode => (
))}
{/* Font Size */}
{['small', 'medium', 'large'].map(size => (
))}
{/* Language */}
{/* Toggles Section */}
📁 File Storage
Store original files
updateSettings('fileStorage', e.target.checked)} style={{ width: '20px', height: '20px', cursor: 'pointer' }} />
📖 Daily Word
Show vocabulary
updateSettings('dailyWord', e.target.checked)} style={{ width: '20px', height: '20px', cursor: 'pointer' }} />
💭 Daily Quote
Show inspiration
updateSettings('dailyQuote', e.target.checked)} style={{ width: '20px', height: '20px', cursor: 'pointer' }} />
)
}
{/* Profile Modal */}
{showProfile && (
{
// Close if clicking on backdrop
if (e.target === e.currentTarget) {
setShowProfile(false);
}
}}
style={{
position: 'fixed',
top: 0,
left: 0,
right: 0,
bottom: 0,
background: 'rgba(0, 0, 0, 0.5)',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
zIndex: 2000,
padding: '20px'
}}>
{t('common.profile')}
)
}
{/* Feedback Modal */}
{showFeedbackModal &&
setShowFeedbackModal(false)} />}
);
}
// Export to global scope
window.Dashboard = Dashboard;