'use client'; import React, { useState } from 'react'; import { Label } from '@/components/ui/label'; import { Select, SelectTrigger, SelectContent, SelectItem, SelectValue } from '@/components/ui/select'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { Input } from '@/components/ui/input'; import { Button } from '@/components/ui/button'; import { useTheme } from '@/app/components/ThemeProvider'; import { useNavidromeConfig } from '@/app/components/NavidromeConfigContext'; import { useToast } from '@/hooks/use-toast'; import { FaServer, FaUser, FaLock, FaCheck, FaTimes, FaLastfm } from 'react-icons/fa'; const SettingsPage = () => { const { theme, setTheme } = useTheme(); const { config, updateConfig, isConnected, testConnection, clearConfig } = useNavidromeConfig(); const { toast } = useToast(); const [formData, setFormData] = useState({ serverUrl: config.serverUrl, username: config.username, password: config.password }); const [isTesting, setIsTesting] = useState(false); const [hasUnsavedChanges, setHasUnsavedChanges] = useState(false); // Last.fm scrobbling settings const [scrobblingEnabled, setScrobblingEnabled] = useState(() => { if (typeof window !== 'undefined') { return localStorage.getItem('lastfm-scrobbling-enabled') === 'true'; } return true; }); const handleInputChange = (field: string, value: string) => { setFormData(prev => ({ ...prev, [field]: value })); setHasUnsavedChanges(true); }; const handleTestConnection = async () => { if (!formData.serverUrl || !formData.username || !formData.password) { toast({ title: "Missing Information", description: "Please fill in all fields before testing the connection.", variant: "destructive" }); return; } setIsTesting(true); try { // Strip trailing slash from server URL before testing const cleanServerUrl = formData.serverUrl.replace(/\/+$/, ''); const success = await testConnection({ serverUrl: cleanServerUrl, username: formData.username, password: formData.password }); if (success) { toast({ title: "Connection Successful", description: "Successfully connected to Navidrome server.", }); } else { toast({ title: "Connection Failed", description: "Could not connect to the server. Please check your settings.", variant: "destructive" }); } } catch (error) { toast({ title: "Connection Error", description: "An error occurred while testing the connection.", variant: "destructive" }); } finally { setIsTesting(false); } }; const handleSaveConfig = async () => { if (!formData.serverUrl || !formData.username || !formData.password) { toast({ title: "Missing Information", description: "Please fill in all fields.", variant: "destructive" }); return; } // Strip trailing slash from server URL to ensure consistency const cleanServerUrl = formData.serverUrl.replace(/\/+$/, ''); updateConfig({ serverUrl: cleanServerUrl, username: formData.username, password: formData.password }); // Update form data to reflect the cleaned URL setFormData(prev => ({ ...prev, serverUrl: cleanServerUrl })); setHasUnsavedChanges(false); toast({ title: "Settings Saved", description: "Navidrome configuration has been saved.", }); }; const handleClearConfig = () => { clearConfig(); setFormData({ serverUrl: '', username: '', password: '' }); setHasUnsavedChanges(false); toast({ title: "Configuration Cleared", description: "Navidrome configuration has been cleared.", }); }; const handleScrobblingToggle = (enabled: boolean) => { setScrobblingEnabled(enabled); localStorage.setItem('lastfm-scrobbling-enabled', enabled.toString()); toast({ title: enabled ? "Scrobbling Enabled" : "Scrobbling Disabled", description: enabled ? "Tracks will now be scrobbled to Last.fm via Navidrome" : "Last.fm scrobbling has been disabled", }); }; return (
Customize your music experience
Note: Your credentials are stored locally in your browser
Security: Always use HTTPS for your Navidrome server
How it works:
Note: Last.fm credentials must be configured in Navidrome, not here.
Theme: Choose between blue and violet color schemes
Dark Mode: Automatically follows your system preferences
Sample Song Title
Sample Artist