Skip to content

Commit 2073625

Browse files
committed
fix: reqs
1 parent 288b8a8 commit 2073625

3 files changed

Lines changed: 50 additions & 12 deletions

File tree

src/components/ColorPicker.tsx

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,28 @@ export function ColorPicker({ username, onColorChange }: ColorPickerProps) {
1717
const { t } = useTranslation();
1818
const [isSaving, setIsSaving] = useState(false);
1919
const [customColor, setCustomColor] = useState(accentColor);
20+
const [isLoading, setIsLoading] = useState(true);
21+
22+
// Load user's actual accent color on mount
23+
useEffect(() => {
24+
const loadUserColor = async () => {
25+
try {
26+
const userColor = await getUserAccentColor(username);
27+
setAccentColor(userColor);
28+
setCustomColor(userColor);
29+
} catch (error) {
30+
// Keep default color on error
31+
} finally {
32+
setIsLoading(false);
33+
}
34+
};
35+
loadUserColor();
36+
}, [username, setAccentColor]);
37+
38+
// Keep customColor in sync with accentColor
39+
useEffect(() => {
40+
setCustomColor(accentColor);
41+
}, [accentColor]);
2042

2143
const handleColorSelect = async (color: string) => {
2244
// Apply color immediately for instant feedback
@@ -66,12 +88,12 @@ export function ColorPicker({ username, onColorChange }: ColorPickerProps) {
6688
<button
6789
key={color}
6890
onClick={() => handleColorSelect(color)}
69-
disabled={isSaving}
91+
disabled={isSaving || isLoading}
7092
className={`relative w-12 h-12 rounded-lg border-2 transition-all hover:scale-110 ${
7193
accentColor === color
7294
? 'border-gray-900 dark:border-gray-100 shadow-lg'
7395
: 'border-gray-300 dark:border-gray-600'
74-
}`}
96+
} ${isLoading || isSaving ? 'opacity-50 cursor-not-allowed' : ''}`}
7597
style={{ backgroundColor: color }}
7698
title={color}
7799
>
@@ -92,18 +114,20 @@ export function ColorPicker({ username, onColorChange }: ColorPickerProps) {
92114
type="color"
93115
value={customColor}
94116
onChange={(e) => handleCustomColorChange(e.target.value)}
95-
className="w-12 h-10 rounded border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700"
117+
disabled={isSaving || isLoading}
118+
className="w-12 h-10 rounded border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 disabled:opacity-50"
96119
/>
97120
<input
98121
type="text"
99122
value={customColor}
100123
onChange={(e) => handleCustomColorChange(e.target.value)}
101124
placeholder="rgb(59, 130, 246)"
102-
className="flex-1 px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100"
125+
disabled={isSaving || isLoading}
126+
className="flex-1 px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 disabled:opacity-50"
103127
/>
104128
<button
105129
onClick={handleCustomColorApply}
106-
disabled={isSaving || customColor === accentColor}
130+
disabled={isSaving || isLoading || customColor === accentColor}
107131
className="px-4 py-2 btn-accent hover:opacity-90 disabled:opacity-50 text-white rounded-md transition-colors"
108132
>
109133
{isSaving ? t('savingColor') : t('apply')}

src/lib/github.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,11 @@ sha?: string)
126126
if (sha) body.sha = sha;
127127

128128
const sendRequest = async (requestBody: any) => {
129+
// Create fresh headers for each request to allow Service Worker to add authorization
130+
const requestHeaders = new Headers(headers);
129131
const res = await fetch(`${BASE}/repos/${owner}/${repo}/contents/${path}`, {
130132
method: 'PUT',
131-
headers,
133+
headers: requestHeaders,
132134
body: JSON.stringify(requestBody)
133135
});
134136
return res;

src/lib/theme.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,27 @@ export function ThemeProvider({ children, username }: { children: React.ReactNod
2020
});
2121

2222
const [accentColor, setAccentColorState] = useState<string>(DEFAULT_ACCENT_COLOR);
23+
const [isLoadingColor, setIsLoadingColor] = useState(!!username);
2324

24-
// Load user's accent color on mount
25+
// Load user's accent color on mount or when username changes
2526
useEffect(() => {
2627
if (username) {
27-
getUserAccentColor(username).then(color => {
28-
setAccentColorState(color);
29-
}).catch(() => {
30-
// Keep default color on error
31-
});
28+
setIsLoadingColor(true);
29+
getUserAccentColor(username)
30+
.then(color => {
31+
setAccentColorState(color);
32+
applyAccentColor(color);
33+
})
34+
.catch(() => {
35+
// Keep default color on error
36+
applyAccentColor(DEFAULT_ACCENT_COLOR);
37+
})
38+
.finally(() => {
39+
setIsLoadingColor(false);
40+
});
41+
} else {
42+
setIsLoadingColor(false);
43+
applyAccentColor(DEFAULT_ACCENT_COLOR);
3244
}
3345
}, [username]);
3446

0 commit comments

Comments
 (0)