22
33import React , { useState , useEffect } from 'react' ;
44import { Palette , Check } from 'lucide-react' ;
5- import { DEFAULT_ACCENT_COLORS , updateUserAccentColor } from '../lib/userSettings' ;
5+ import { DEFAULT_ACCENT_COLORS , updateUserAccentColor , getUserAccentColor } from '../lib/userSettings' ;
66import { useTheme } from '../lib/theme' ;
7+ import { useTranslation } from '../lib/i18n' ;
78import { safeLogError } from '../lib/utils' ;
89
910interface ColorPickerProps {
@@ -13,18 +14,25 @@ interface ColorPickerProps {
1314
1415export function ColorPicker ( { username, onColorChange } : ColorPickerProps ) {
1516 const { accentColor, setAccentColor } = useTheme ( ) ;
17+ const { t } = useTranslation ( ) ;
1618 const [ isSaving , setIsSaving ] = useState ( false ) ;
1719 const [ customColor , setCustomColor ] = useState ( accentColor ) ;
1820
1921 const handleColorSelect = async ( color : string ) => {
22+ // Apply color immediately for instant feedback
23+ setAccentColor ( color ) ;
24+ onColorChange ?.( color ) ;
25+
2026 setIsSaving ( true ) ;
2127 try {
2228 await updateUserAccentColor ( username , color ) ;
23- setAccentColor ( color ) ;
24- onColorChange ?.( color ) ;
2529 } catch ( error ) {
2630 safeLogError ( 'Error saving accent color:' , error ) ;
27- alert ( 'Failed to save color preference. Please try again.' ) ;
31+ // Revert color back to previous if save failed
32+ const previousColor = await getUserAccentColor ( username ) ;
33+ setAccentColor ( previousColor ) ;
34+ onColorChange ?.( previousColor ) ;
35+ alert ( t ( 'colorSaveError' ) ) ;
2836 } finally {
2937 setIsSaving ( false ) ;
3038 }
@@ -43,13 +51,13 @@ export function ColorPicker({ username, onColorChange }: ColorPickerProps) {
4351 < div className = "flex items-center gap-2" >
4452 < Palette className = "w-5 h-5 text-gray-600 dark:text-gray-400" />
4553 < h3 className = "text-lg font-medium text-gray-900 dark:text-gray-100" >
46- Accent Color
54+ { t ( 'accentColor' ) }
4755 </ h3 >
4856 </ div >
4957
5058 < div className = "space-y-3" >
5159 < p className = "text-sm text-gray-600 dark:text-gray-400" >
52- Choose your accent color that will be applied throughout the interface.
60+ { t ( 'accentColorDescription' ) }
5361 </ p >
5462
5563 { /* Preset colors */ }
@@ -77,7 +85,7 @@ export function ColorPicker({ username, onColorChange }: ColorPickerProps) {
7785 { /* Custom color picker */ }
7886 < div className = "space-y-2" >
7987 < label className = "text-sm font-medium text-gray-700 dark:text-gray-300" >
80- Custom Color
88+ { t ( 'customColor' ) }
8189 </ label >
8290 < div className = "flex items-center gap-3" >
8391 < input
@@ -98,7 +106,7 @@ export function ColorPicker({ username, onColorChange }: ColorPickerProps) {
98106 disabled = { isSaving || customColor === accentColor }
99107 className = "px-4 py-2 btn-accent hover:opacity-90 disabled:opacity-50 text-white rounded-md transition-colors"
100108 >
101- { isSaving ? 'Saving...' : 'Apply' }
109+ { isSaving ? t ( 'savingColor' ) : t ( 'apply' ) }
102110 </ button >
103111 </ div >
104112 </ div >
@@ -111,10 +119,10 @@ export function ColorPicker({ username, onColorChange }: ColorPickerProps) {
111119 />
112120 < div >
113121 < p className = "text-sm font-medium text-gray-900 dark:text-gray-100" >
114- Current : { accentColor }
122+ { t ( 'currentColor' ) } : { accentColor }
115123 </ p >
116124 < p className = "text-xs text-gray-600 dark:text-gray-400" >
117- This color is applied to buttons, links, and interactive elements
125+ { t ( 'colorAppliedTo' ) }
118126 </ p >
119127 </ div >
120128 </ div >
0 commit comments