Skip to content

Commit 24a9fcc

Browse files
authored
feat: sync button indicates in-progress synchronization (#8)
The sync button is disabled during the ongoing synchronization of bookmarks. This prevents certain race conditions during the update of bookmarks, which resulted in duplicates. Additionally, this helps indicate to the user that the process is ongoing in case of a slow network.
1 parent 07f0852 commit 24a9fcc

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "bookmarksync",
33
"description": "Synchronize browser bookmarks from a GitHub repository",
44
"private": true,
5-
"version": "0.9.0",
5+
"version": "0.9.1",
66
"license": "MIT",
77
"type": "module",
88
"scripts": {

src/entrypoints/popup/popup.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ button:focus-visible {
8383
outline: 4px auto -webkit-focus-ring-color;
8484
}
8585

86+
button:disabled {
87+
background-color: #757575;
88+
color: #ccc;
89+
cursor: not-allowed;
90+
border: 1px solid #606060;
91+
opacity: 0.7;
92+
}
8693
@media (prefers-color-scheme: light) {
8794
:root {
8895
color: #213547;

src/entrypoints/popup/popup.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,19 @@ import {getSyncBookmarks} from '@/utils/bookmarksync.js';
55
const syncBookmarks = getSyncBookmarks();
66

77
document.querySelector('#bookmarksync-logo').src = logo;
8-
document.querySelector('#sync-now').addEventListener('click', () => {
8+
9+
const syncButton = document.querySelector('#sync-now');
10+
syncButton.addEventListener('click', async () => {
11+
console.log('Manual sync triggered');
12+
const originalText = syncButton.textContent;
13+
syncButton.textContent = 'Synchronizing...';
14+
syncButton.disabled = true;
915
try {
10-
console.log('Manual sync triggered');
11-
syncBookmarks(true);
16+
await syncBookmarks(true);
1217
} catch (error) {
1318
console.error('Error triggering manual bookmark sync:', error);
19+
} finally {
20+
syncButton.disabled = false;
21+
syncButton.textContent = originalText;
1422
}
1523
});

0 commit comments

Comments
 (0)