Skip to content

Commit e79d5dc

Browse files
feat: add saving indicator
1 parent b2a20f1 commit e79d5dc

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/pages/options.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,33 @@ const App = (): JSX.Element => {
99
const [currentEngine, setCurrentEngine] = useState('');
1010
const [luckyUrl, setLuckyUrl] = useState('');
1111
const [backend, setBackend] = useState('');
12+
const [savedText, setSavedText] = useState('Save');
1213

1314
const engineSelectionRef = useRef<HTMLSelectElement>(null);
1415
const backendSelectionRef = useRef<HTMLSelectElement>(null);
1516
const luckyUrlRef = useRef<HTMLInputElement>(null);
1617
const onSave = async (): Promise<void> => {
18+
setSavedText('Saving...');
19+
1720
if (currentEngine !== engineSelectionRef.current!.value) {
1821
setCurrentEngine(engineSelectionRef.current!.value);
19-
updateEngine(engineSelectionRef.current!.value);
22+
await updateEngine(engineSelectionRef.current!.value);
2023
}
2124

2225
if (luckyUrl !== luckyUrlRef.current!.value) {
2326
setLuckyUrl(luckyUrlRef.current!.value);
24-
updateLuckyBangUrl(luckyUrlRef.current!.value);
27+
await updateLuckyBangUrl(luckyUrlRef.current!.value);
2528
}
2629

2730
if (backend !== backendSelectionRef.current!.value) {
2831
setBackend(backendSelectionRef.current!.value);
29-
updateBackend(backendSelectionRef.current!.value as BackendId);
32+
await updateBackend(backendSelectionRef.current!.value as BackendId);
3033
}
34+
35+
setSavedText('Saved!');
36+
setTimeout(() => {
37+
setSavedText('Save');
38+
}, 500);
3139
};
3240

3341
useEffect(() => {
@@ -61,7 +69,7 @@ const App = (): JSX.Element => {
6169
<label htmlFor='lucky-url-input'>Lucky bang (!) url:</label>
6270
<input id='lucky-url-input' type='text' value={luckyUrl} ref={luckyUrlRef}/>
6371
</div>
64-
<button className='save-button' onClick={onSave}>Save</button>
72+
<button className='save-button' onClick={onSave}>{savedText}</button>
6573
</>
6674
: <p className='loading'>Loading list of engines...</p>
6775
}

0 commit comments

Comments
 (0)