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
web: replace force sync with force push/pull
Abdullah Atta9a866a552ad5
diff --git a/apps/web/src/components/announcements/body.jsx b/apps/web/src/components/announcements/body.jsxindex 65895e414..fc7906c44 100644--- a/apps/web/src/components/announcements/body.jsx+++ b/apps/web/src/components/announcements/body.jsx@@ -303,7 +303,7 @@ function CalltoAction({ action, variant, sx, dismissAnnouncement }) {break;}case "force-sync": {- await appStore.sync(true, true);+ await appStore.sync({ type: "full", force: true });break;}case "backup": {diff --git a/apps/web/src/dialogs/settings/sync-settings.ts b/apps/web/src/dialogs/settings/sync-settings.tsindex 76e5172a1..b6f6714ae 100644--- a/apps/web/src/dialogs/settings/sync-settings.ts+++ b/apps/web/src/dialogs/settings/sync-settings.ts@@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.import { SettingsGroup } from "./types";import { useStore as useAppStore } from "../../stores/app-store";+import { confirm } from "../../common/dialog-controller";export const SyncSettings: SettingsGroup[] = [{@@ -78,14 +79,56 @@ export const SyncSettings: SettingsGroup[] = [{key: "force-sync",title: "Having problems with sync?",- description: "Try force sync to resolve issues with syncing.",+ description: `Force push:+Use this if some changes from this device are not appearing on other devices.This will push everything on this device and overwrite whatever is one the server.++Force pull:+Use this if some changes are not appearing on this device from other devices. This will pull everything from the server and overwrite with whatever is one this device.++**These must only be used for troubleshooting. Using them regularly for sync is not recommended and will lead to unexpected data loss and other issues. If you are having persistent issues with sync, please report them to us at [email protected].**`,keywords: ["force sync", "sync troubleshoot"],components: [{type: "button",- title: "Force sync",+ title: "Force push",+ variant: "error",+ action: () =>+ confirm({+ title: "Are you sure?",+ message:+ "This must only be used for troubleshooting. Using them regularly for sync is **not recommended** and will lead to **unexpected data loss** and other issues. If you are having persistent issues with sync, please report them to us at [email protected].",+ checks: {+ accept: { text: "I understand.", default: false }+ },+ positiveButtonText: "Proceed",+ negativeButtonText: "Cancel"+ }).then((result) => {+ if (!result || !result.accept) return;+ return useAppStore+ .getState()+ .sync({ force: true, type: "send" });+ })+ },+ {+ type: "button",+ title: "Force pull",variant: "error",- action: () => useAppStore.getState().sync(true, true)+ action: () =>+ confirm({+ title: "Are you sure?",+ message:+ "This must only be used for troubleshooting. Using them regularly for sync is **not recommended** and will lead to **unexpected data loss** and other issues. If you are having persistent issues with sync, please report them to us at [email protected].",+ checks: {+ accept: { text: "I understand.", default: false }+ },+ positiveButtonText: "Proceed",+ negativeButtonText: "Cancel"+ }).then((result) => {+ if (!result || !result.accept) return;+ return useAppStore+ .getState()+ .sync({ force: true, type: "fetch" });+ })}]}diff --git a/apps/web/src/stores/app-store.ts b/apps/web/src/stores/app-store.tsindex 35e9464ce..1b8882803 100644--- a/apps/web/src/stores/app-store.ts+++ b/apps/web/src/stores/app-store.ts@@ -41,6 +41,7 @@ import {} from "../utils/page-visibility";import { NetworkCheck } from "../utils/network-check";import { Color, Notebook, Tag } from "@notesnook/core";+import { SyncOptions } from "@notesnook/core/dist/api/sync";type SyncState =| "synced"@@ -57,7 +58,7 @@ type SyncStatus = {};const networkCheck = new NetworkCheck();let syncStatusTimeout = 0;-let pendingSync: { full: boolean } | undefined = undefined;+let pendingSync: SyncOptions | undefined = undefined;class AppStore extends BaseStore<AppStore> {// default state@@ -115,9 +116,9 @@ class AppStore extends BaseStore<AppStore> {db.eventManager.subscribe(EVENTS.databaseSyncRequested,- async (full, force, lastSynced) => {+ async (full, force) => {if (!this.get().isAutoSyncEnabled) return;- await this.get().sync(full, force, lastSynced);+ await this.get().sync({ type: full ? "full" : "send", force });});@@ -268,7 +269,7 @@ class AppStore extends BaseStore<AppStore> {this.set((state) => (state.lastSynced = lastSynced));};- sync = async (full = true, force = false, lastSynced?: number) => {+ sync = async (options: SyncOptions = { type: "full", force: false }) => {if (this.isSyncing() ||!this.get().isSyncEnabled ||@@ -276,14 +277,12 @@ class AppStore extends BaseStore<AppStore> {!(await networkCheck.waitForInternet())) {logger.info("Ignoring duplicate sync", {- full,- force,- lastSynced,+ options,syncing: this.isSyncing(),syncDisabled: !this.get().isSyncEnabled,offline: !navigator.onLine});- if (this.isSyncing()) pendingSync = { full };+ if (this.isSyncing()) pendingSync = options;return;}@@ -292,10 +291,7 @@ class AppStore extends BaseStore<AppStore> {this.updateSyncStatus("syncing");try {- const result = await db.sync({- type: full ? "full" : "send",- force- });+ const result = await db.sync(options);if (!result) return this.updateSyncStatus("failed");this.updateSyncStatus("completed", true);@@ -304,9 +300,9 @@ class AppStore extends BaseStore<AppStore> {if (pendingSync) {logger.info("Running pending sync", pendingSync);- const isFullSync = pendingSync.full;+ const syncOptions = { ...pendingSync };pendingSync = undefined;- await this.get().sync(isFullSync, false);+ await this.get().sync(syncOptions);}} catch (err) {if (!(err instanceof Error)) {@@ -316,9 +312,6 @@ class AppStore extends BaseStore<AppStore> {logger.error(err);if (err.cause === "MERGE_CONFLICT") {- // TODO: reopen conflicted note- // const sessionId = editorstore.get().session.id;- // if (sessionId) await editorstore.openSession(sessionId, true);await this.refresh();this.updateSyncStatus("conflicts");} else {