A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
feat: much better sync statuses
thecodrrfbd2031cd2f4
diff --git a/apps/web/src/components/editor/plugins/picker.js b/apps/web/src/components/editor/plugins/picker.jsindex 387557557..06c1b645b 100644--- a/apps/web/src/components/editor/plugins/picker.js+++ b/apps/web/src/components/editor/plugins/picker.js@@ -94,7 +94,7 @@ async function pickFile() {};},});- if (!result.hash) throw new Error("Could not add attachment.");+ if (result instanceof Error) throw result;return result;} catch (e) {showToast("error", `${e.message}`);@@ -138,10 +138,7 @@ async function pickImage() {dataurl,};} catch (e) {- showToast(- "error",- `${e.message} You need internet access to attach an image.`- );+ showToast("error", e.message);}}diff --git a/apps/web/src/components/icons/index.js b/apps/web/src/components/icons/index.jsindex a9fc14e95..e9c41bc91 100644--- a/apps/web/src/components/icons/index.js+++ b/apps/web/src/components/icons/index.js@@ -93,6 +93,7 @@ import {mdiFileOutline,mdiImage,mdiNoteOutline,+ mdiSyncAlert,} from "@mdi/js";import { useTheme } from "emotion-theming";import { AnimatedFlex } from "../animated";@@ -183,6 +184,7 @@ export const Settings = createIcon(mdiCogOutline);export const Home = createIcon(mdiHomeOutline);export const Restore = createIcon(mdiRecycle);export const Sync = createIcon(mdiSync);+export const SyncError = createIcon(mdiSyncAlert);export const Loading = createIcon(mdiLoading, true);export const Export = createIcon(mdiExportVariant);export const AddToNotebook = createIcon(mdiBookPlusMultipleOutline);diff --git a/apps/web/src/components/status-bar/index.js b/apps/web/src/components/status-bar/index.jsindex a4ebe6055..0abfb0ac3 100644--- a/apps/web/src/components/status-bar/index.js+++ b/apps/web/src/components/status-bar/index.js@@ -1,7 +1,6 @@-import React from "react";import { Box, Button, Flex, Text } from "rebass";import EditorFooter from "../editor/footer";-import { Circle, Sync, Loading, Update } from "../icons";+import { Circle, Sync, Loading, Update, SyncError, Checkmark } from "../icons";import { useStore as useUserStore } from "../../stores/user-store";import { useStore as useAppStore } from "../../stores/app-store";import TimeAgo from "timeago-react";@@ -14,9 +13,7 @@ import checkForUpdate from "../../commands/check-for-update";function StatusBar() {const user = useUserStore((state) => state.user);const sync = useAppStore((state) => state.sync);- const lastSynced = useAppStore((state) => state.lastSynced);const isLoggedIn = useUserStore((state) => state.isLoggedIn);- const isSyncing = useAppStore((state) => state.isSyncing);const processingStatuses = useAppStore((state) =>Object.values(state.processingStatuses));@@ -58,15 +55,7 @@ function StatusBar() {onClick={sync}sx={{ alignItems: "center", justifyContent: "center" }}>- <Sync size={10} rotate={isSyncing} />- <Text variant="subBody" ml={1}>- {"Synced "}- {lastSynced ? (- <TimeAgo live={true} datetime={lastSynced} />- ) : (- "never"- )}- </Text>+ <SyncStatus /></Button></>) : (@@ -146,3 +135,51 @@ function statusToInfoText(status) {? `v${version} available`: "";}++function SyncStatus() {+ const syncStatus = useAppStore((state) => state.syncStatus);+ const lastSynced = useAppStore((state) => state.lastSynced);++ switch (syncStatus) {+ case "synced":+ return (+ <>+ <Sync size={10} />+ <Text variant="subBody" ml={1}>+ {"Synced "}+ <TimeAgo live={true} datetime={lastSynced} />+ </Text>+ </>+ );+ case "syncing":+ return (+ <>+ <Sync size={10} rotate={syncStatus === "syncing"} />+ <Text variant="subBody" ml={1}>+ Syncing+ </Text>+ </>+ );+ case "failed":+ case "conflicts":+ return (+ <>+ <SyncError size={10} />+ <Text variant="subBody" ml={1}>+ {syncStatus === "failed" ? "Sync failed" : "Merge conflicts"}+ </Text>+ </>+ );+ case "completed":+ return (+ <>+ <Checkmark size={10} />+ <Text variant="subBody" ml={1}>+ Sync completed+ </Text>+ </>+ );+ default:+ return null;+ }+}diff --git a/apps/web/src/stores/app-store.js b/apps/web/src/stores/app-store.jsindex ef8524332..af1a56fb2 100644--- a/apps/web/src/stores/app-store.js+++ b/apps/web/src/stores/app-store.js@@ -12,11 +12,11 @@ import { resetReminders } from "../common/reminders";class AppStore extends BaseStore {// default stateisSideMenuOpen = false;- isSyncing = false;isFocusMode = false;isEditorOpen = false;isVaultCreated = false;processingStatuses = {};+ syncStatus = "synced";colors = [];globalMenu = { items: [], data: {} };reminders = [];@@ -142,13 +142,14 @@ class AppStore extends BaseStore {sync = async (full = true, force = false) => {this.updateLastSynced();this.set((state) => (state.isSyncing = true));++ this.set((state) => (state.syncStatus = "syncing"));return db.sync(full, force).then(async (result) => {if (!result) return;-- showToast("success", "Sync completed.");await this.updateLastSynced();+ this.set((state) => (state.syncStatus = "completed"));return await this.refresh();}).catch(async (err) => {@@ -158,10 +159,15 @@ class AppStore extends BaseStore {if (editorstore.get().session.id)editorstore.openSession(editorstore.get().session.id, true);await this.refresh();+ this.set((state) => (state.syncStatus = "conflicts"));+ } else {+ this.set((state) => (state.syncStatus = "failed"));}}).finally(() => {- this.set((state) => (state.isSyncing = false));+ setTimeout(() => {+ this.set((state) => (state.syncStatus = "synced"));+ }, 5000);});};}