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: add support for disabling item sync
thecodrr9d04d4f48c3d
diff --git a/apps/web/src/common/constants.js b/apps/web/src/common/constants.jsindex 18c44b5b9..2e21146ed 100644--- a/apps/web/src/common/constants.js+++ b/apps/web/src/common/constants.js@@ -1,11 +1,11 @@export const COLORS = [- "Red",- "Orange",- "Yellow",- "Green",- "Blue",- "Purple",- "Gray",+ "red",+ "orange",+ "yellow",+ "green",+ "blue",+ "purple",+ "gray",];export const SUBSCRIPTION_STATUS = {diff --git a/apps/web/src/components/icons/index.js b/apps/web/src/components/icons/index.jsindex 35752f3c8..75ed585c9 100644--- a/apps/web/src/components/icons/index.js+++ b/apps/web/src/components/icons/index.js@@ -34,6 +34,7 @@ import {mdiHomeOutline,mdiRecycle,mdiSync,+ mdiSyncOff,mdiLoading,mdiExportVariant,mdiArrowExpandDown,@@ -237,6 +238,7 @@ export const Settings = createIcon(mdiCogOutline);export const Home = createIcon(mdiHomeOutline);export const Restore = createIcon(mdiRecycle);export const Sync = createIcon(mdiSync);+export const SyncOff = createIcon(mdiSyncOff);export const SyncError = createIcon(mdiSyncAlert);export const Loading = createIcon(mdiLoading, true);export const Export = createIcon(mdiExportVariant);diff --git a/apps/web/src/components/note/index.js b/apps/web/src/components/note/index.jsindex 129cf5754..1fa6b8f11 100644--- a/apps/web/src/components/note/index.js+++ b/apps/web/src/components/note/index.js@@ -124,6 +124,8 @@ function Note(props) {<Icon.Alert size={15} color="error" sx={{ mr: 1 }} />)}+ {note.localOnly && <Icon.SyncOff size={13} sx={{ mr: 1 }} />}+<TimeAgosx={{ flexShrink: 0 }}locale="en_short"@@ -202,6 +204,7 @@ export default React.memo(Note, function (prevProps, nextProps) {prevProps.date === nextProps.date &&prevItem.pinned === nextItem.pinned &&prevItem.favorite === nextItem.favorite &&+ prevItem.localOnly === nextItem.localOnly &&prevItem.headline === nextItem.headline &&prevItem.title === nextItem.title &&prevItem.locked === nextItem.locked &&@@ -349,6 +352,24 @@ const menuItems = [},isPro: true,},+ {+ key: "sync-disable",+ title: ({ note }) => (note.localOnly ? "Enable sync" : "Disable sync"),+ icon: ({ note }) => (note.localOnly ? Icon.Sync : Icon.SyncOff),+ onClick: async ({ note }) => {+ if (+ note.localOnly ||+ (await confirm({+ title: "Disable sync for this item?",+ message:+ "Turning sync off for this item will automatically delete it from all other devices. Are you sure you want to continue?",+ yesText: "Yes",+ noText: "No",+ }))+ )+ await store.get().localOnly(note.id);+ },+ },{key: "movetotrash",title: "Move to trash",diff --git a/apps/web/src/components/properties/index.js b/apps/web/src/components/properties/index.jsindex 14c853d75..1e2ecd6a2 100644--- a/apps/web/src/components/properties/index.js+++ b/apps/web/src/components/properties/index.js@@ -1,11 +1,12 @@import React, { useCallback, useEffect, useState } from "react";import * as Icon from "../icons";import { Flex, Text } from "rebass";-import { useStore } from "../../stores/editor-store";+import { useStore, store } from "../../stores/editor-store";import { COLORS } from "../../common/constants";import { db } from "../../common/db";import { useStore as useAppStore } from "../../stores/app-store";import { useStore as useAttachmentStore } from "../../stores/attachment-store";+import { store as noteStore } from "../../stores/note-store";import { AnimatedFlex } from "../animated";import Toggle from "./toggle";import { navigate } from "../../navigation";@@ -27,6 +28,7 @@ const tools = [},{ key: "locked", icon: Icon.Unlock, label: "Lock" },{ key: "readonly", icon: Icon.Readonly, label: "Readonly" },+ { key: "localOnly", icon: Icon.SyncOff, label: "Disable sync" },];const metadataItems = [@@ -45,11 +47,7 @@ const metadataItems = [function Properties() {const [versionHistory, setVersionHistory] = useState([]);- const toggleLocked = useStore((store) => store.toggleLocked);- const toggleReadonly = useStore((store) => store.toggleReadonly);- const setSession = useStore((store) => store.setSession);const openPreviewSession = useStore((store) => store.openPreviewSession);- const setColor = useStore((store) => store.setColor);const toggleProperties = useStore((store) => store.toggleProperties);const isFocusMode = useAppStore((store) => store.isFocusMode);const session = useStore((store) => store.session);@@ -61,20 +59,24 @@ function Properties() {const changeState = useCallback(function changeState(prop, value) {- if (prop === "locked") {- toggleLocked();- return;- }-- setSession((state) => {- state.session[prop] = value;- });-- if (prop === "readonly") {- toggleReadonly();+ switch (prop) {+ case "locked":+ return store.get().session.locked+ ? noteStore.unlock(sessionId)+ : noteStore.lock(sessionId);+ case "readonly":+ return noteStore.readonly(sessionId);+ case "localOnly":+ return noteStore.localOnly(sessionId);+ case "pinned":+ return noteStore.pin(sessionId);+ case "favorite":+ return noteStore.favorite(sessionId);+ default:+ return;}},- [setSession, toggleLocked]+ [sessionId]);useEffect(() => {@@ -130,7 +132,7 @@ function Properties() {>{!isPreviewMode && (<>- {tools.map((tool, _) => (+ {tools.map((tool) => (<Toggle{...tool}key={tool.key}@@ -179,7 +181,7 @@ function Properties() {key={label}justifyContent="space-between"alignItems="center"- onClick={() => setColor(label)}+ onClick={() => noteStore.get().setColor(sessionId, label)}sx={{cursor: "pointer",position: "relative",diff --git a/apps/web/src/stores/editor-store.js b/apps/web/src/stores/editor-store.jsindex ac07a7fcb..eede77568 100644--- a/apps/web/src/stores/editor-store.js+++ b/apps/web/src/stores/editor-store.js@@ -30,6 +30,7 @@ const getDefaultSession = (sessionId = Date.now()) => {title: "",id: undefined,pinned: false,+ localOnly: false,favorite: false,locked: false,tags: [],@@ -274,20 +275,6 @@ class EditorStore extends BaseStore {}};- toggleLocked = () => {- if (this.get().session.locked) noteStore.unlock(this.get().session.id);- else noteStore.lock(this.get().session.id);- };-- toggleReadonly = () => {- noteStore.readonly(this.get().session.id);- };-- setColor = (color) => {- //this._setTagOrColor("color", color);- return noteStore.setColor(this.get().session.id, color);- };-setTag = (tag) => {return this._setTag(tag);};diff --git a/apps/web/src/stores/note-store.js b/apps/web/src/stores/note-store.jsindex 2ec9d4db4..e8e80c7e1 100644--- a/apps/web/src/stores/note-store.js+++ b/apps/web/src/stores/note-store.js@@ -129,6 +129,13 @@ class NoteStore extends BaseStore {return id;};+ localOnly = async (id) => {+ const note = db.notes.note(id);+ await note.localOnly();+ this._syncEditor(note.id, "localOnly", !note.data.localOnly);+ this.refresh();+ };+setColor = async (id, color) => {try {let note = db.notes.note(id);