Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

refactor: improve sync status

thecodrrcb3e5dfcfddd
diff --git a/apps/web/src/components/icons/index.js b/apps/web/src/components/icons/index.js
index 90f662d97..441210d99 100644
--- a/apps/web/src/components/icons/index.js
+++ b/apps/web/src/components/icons/index.js
@@ -89,7 +89,6 @@ import {
mdiNoteOutline,
mdiSyncAlert,
mdiAlertOutline,
- mdiAlertOctagramOutline,
mdiEyeOutline,
mdiEyeOffOutline,
mdiAttachment,
@@ -136,6 +135,8 @@ import {
mdiContentSaveCheckOutline,
mdiContentSaveAlertOutline,
mdiCurrencyUsd,
+ mdiAlertOctagonOutline,
+ mdiGithub,
} from "@mdi/js";
import { useTheme } from "emotion-theming";
import { AnimatedFlex } from "../animated";
@@ -201,7 +202,7 @@ export const ArrowRight = createIcon(mdiArrowRight);
export const ArrowDown = createIcon(mdiArrowDown);
export const Move = createIcon(mdiBookPlusMultipleOutline);
export const Topic = createIcon(mdiBookmarkOutline);
-export const Alert = createIcon(mdiAlertOctagramOutline);
+export const Alert = createIcon(mdiAlertOctagonOutline);
export const Vault = createIcon(mdiShieldOutline);
export const Unlock = createIcon(mdiLockOpenOutline);
export const Lock = createIcon(mdiLockOutline);
@@ -292,6 +293,7 @@ export const DetailedView = createIcon(mdiViewSequentialOutline);
export const MailCheck = createIcon(mdiEmailCheckOutline);
export const Discord = createIcon(mdiDiscord);
export const Twitter = createIcon(mdiTwitter);
+export const Github = createIcon(mdiGithub);
export const Reddit = createIcon(mdiReddit);
export const Dismiss = createIcon(mdiClose);
export const File = createIcon(mdiFileOutline);
diff --git a/apps/web/src/components/status-bar/index.js b/apps/web/src/components/status-bar/index.js
index 46a96e1bc..14151da11 100644
--- a/apps/web/src/components/status-bar/index.js
+++ b/apps/web/src/components/status-bar/index.js
@@ -26,7 +26,6 @@ import { getIconFromAlias } from "../icons/resolver";
function StatusBar() {
const user = useUserStore((state) => state.user);
- const sync = useAppStore((state) => state.sync);
const isLoggedIn = useUserStore((state) => state.isLoggedIn);
const statuses = useStatus();
const updateStatus = useAutoUpdater();
@@ -62,14 +61,7 @@ function StatusBar() {
</Text>
</Button>
- <Button
- variant="statusitem"
- display="flex"
- onClick={sync}
- sx={{ alignItems: "center", justifyContent: "center" }}
- >
- <SyncStatus />
- </Button>
+ <SyncStatus />
</>
) : (
<Button
@@ -167,56 +159,90 @@ function statusToInfoText(status) {
function SyncStatus() {
const syncStatus = useAppStore((state) => state.syncStatus);
const lastSynced = useAppStore((state) => state.lastSynced);
+ const sync = useAppStore((state) => state.sync);
+ const user = useUserStore((state) => state.user);
- if (!lastSynced && syncStatus === "synced") return null;
- switch (syncStatus) {
- case "synced":
- return (
- <>
- <Sync size={12} />
- <Text variant="subBody" ml={1}>
- {"Synced "}
- <TimeAgo live={true} datetime={lastSynced} />
- </Text>
- </>
- );
- case "syncing":
- return (
- <>
- <Sync size={12} rotate={syncStatus === "syncing"} />
- <Text variant="subBody" ml={1}>
- Syncing
- </Text>
- </>
- );
- case "failed":
- return (
- <>
- <SyncError size={12} />
- <Text variant="subBody" ml={1}>
- Sync failed
- </Text>
- </>
- );
- case "completed":
- return (
- <>
- <Checkmark size={12} color="success" />
- <Text data-test-id="sync-status-success" variant="subBody" ml={1}>
- Sync completed
- </Text>
- </>
- );
- case "conflicts":
- return (
- <>
- <Alert size={12} color="error" />
- <Text variant="subBody" ml={1}>
- Merge conflicts
- </Text>
- </>
- );
- default:
- return null;
- }
+ const status = syncStatusFilters.find((f) =>
+ f.check(syncStatus, user, lastSynced)
+ );
+
+ return (
+ <Button
+ variant="statusitem"
+ display="flex"
+ onClick={sync}
+ sx={{ alignItems: "center", justifyContent: "center" }}
+ title={status.tooltip}
+ >
+ <status.icon size={12} color={status.iconColor} rotate={status.loading} />
+ <Text variant="subBody" ml={1}>
+ {typeof status.text === "string" ? (
+ status.text
+ ) : (
+ <status.text lastSynced={lastSynced} />
+ )}
+ </Text>
+ </Button>
+ );
}
+
+const syncStatusFilters = [
+ {
+ key: "emailNotConfirmed",
+ check: (_syncStatus, user) => !user.isEmailConfirmed,
+ icon: Alert,
+ iconColor: "warn",
+ text: "Sync disabled",
+ tooltip: "Please confirm your email to start syncing.",
+ },
+ {
+ key: "neverSynced",
+ check: (_syncStatus, _user, lastSynced) => !lastSynced,
+ icon: Sync,
+ text: "Synced never",
+ tooltip: "Click to sync your notes.",
+ },
+ {
+ key: "failed",
+ check: (syncStatus) => syncStatus === "failed",
+ icon: SyncError,
+ color: "error",
+ text: "Sync failed",
+ tooltip: "Sync failed to completed. Please try again.",
+ },
+ {
+ key: "synced",
+ check: (syncStatus) => syncStatus === "synced",
+ icon: Sync,
+ text: ({ lastSynced }) => (
+ <>
+ {"Synced "}
+ <TimeAgo live={true} datetime={lastSynced} />
+ </>
+ ),
+ tooltip: "All changes are synced.",
+ },
+ {
+ key: "syncing",
+ check: (syncStatus) => syncStatus === "syncing",
+ icon: Sync,
+ loading: true,
+ text: "Syncing",
+ tooltip: "Syncing your notes...",
+ },
+ {
+ key: "completed",
+ check: (syncStatus) => syncStatus === "completed",
+ icon: Checkmark,
+ iconColor: "success",
+ text: "Sync completed",
+ },
+ {
+ key: "conflicts",
+ check: (syncStatus) => syncStatus === "conflicts",
+ icon: Alert,
+ iconColor: "error",
+ text: "Merge conflicts",
+ tooltip: "Please resolve all merge conflicts and run the sync again.",
+ },
+];