Skip to content

Commit e72b9c9

Browse files
committed
fix: th
1 parent 7edbec8 commit e72b9c9

2 files changed

Lines changed: 23 additions & 11 deletions

File tree

src/components/ColorPicker.tsx

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
import React, { useState, useEffect } from 'react';
44
import { Palette, Check } from 'lucide-react';
5-
import { DEFAULT_ACCENT_COLORS, updateUserAccentColor } from '../lib/userSettings';
5+
import { DEFAULT_ACCENT_COLORS, updateUserAccentColor, getUserAccentColor } from '../lib/userSettings';
66
import { useTheme } from '../lib/theme';
7+
import { useTranslation } from '../lib/i18n';
78
import { safeLogError } from '../lib/utils';
89

910
interface ColorPickerProps {
@@ -13,18 +14,25 @@ interface ColorPickerProps {
1314

1415
export 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>

src/lib/i18n.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ const translations = {
3535
apply: 'Apply',
3636
currentColor: 'Current',
3737
colorAppliedTo: 'This color is applied to buttons, links, and interactive elements',
38+
savingColor: 'Saving color...',
39+
colorSaveError: 'Failed to save color preference. Color reverted to previous setting.',
3840
retry: 'Retry',
3941
by: 'by',
4042
joined: 'Joined',
@@ -126,7 +128,9 @@ const translations = {
126128
customColor: 'Пользовательский цвет',
127129
apply: 'Применить',
128130
currentColor: 'Текущий',
129-
colorAppliedTo: 'Этот цвет применяется к кнопкам, ссылкам и интерактивным элементам'
131+
colorAppliedTo: 'Этот цвет применяется к кнопкам, ссылкам и интерактивным элементам',
132+
savingColor: 'Сохранение цвета...',
133+
colorSaveError: 'Не удалось сохранить цвет. Цвет возвращен к предыдущей настройке.'
130134
}
131135
};
132136

0 commit comments

Comments
 (0)