Skip to content

Commit

Permalink
feat: sync button indicates in-progress synchronization
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
frederikb committed Jan 4, 2024
1 parent 07f0852 commit 8e99d64
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "bookmarksync",
"description": "Synchronize browser bookmarks from a GitHub repository",
"private": true,
"version": "0.9.0",
"version": "0.9.1",
"license": "MIT",
"type": "module",
"scripts": {
Expand Down
7 changes: 7 additions & 0 deletions src/entrypoints/popup/popup.css
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ button:focus-visible {
outline: 4px auto -webkit-focus-ring-color;
}

button:disabled {
background-color: #757575;
color: #ccc;
cursor: not-allowed;
border: 1px solid #606060;
opacity: 0.7;
}
@media (prefers-color-scheme: light) {
:root {
color: #213547;
Expand Down
14 changes: 11 additions & 3 deletions src/entrypoints/popup/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,19 @@ import {getSyncBookmarks} from '@/utils/bookmarksync.js';
const syncBookmarks = getSyncBookmarks();

document.querySelector('#bookmarksync-logo').src = logo;
document.querySelector('#sync-now').addEventListener('click', () => {

const syncButton = document.querySelector('#sync-now');
syncButton.addEventListener('click', async () => {
console.log('Manual sync triggered');
const originalText = syncButton.textContent;
syncButton.textContent = 'Synchronizing...';
syncButton.disabled = true;
try {
console.log('Manual sync triggered');
syncBookmarks(true);
await syncBookmarks(true);
} catch (error) {
console.error('Error triggering manual bookmark sync:', error);
} finally {
syncButton.disabled = false;
syncButton.textContent = originalText;
}
});

0 comments on commit 8e99d64

Please sign in to comment.