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
mobile: migrate to db.shortcuts
ammarahm-ed45c4381537e2
diff --git a/apps/mobile/app/components/list-items/headers/notebook-header.js b/apps/mobile/app/components/list-items/headers/notebook-header.jsindex 8d77cedf1..854d69678 100644--- a/apps/mobile/app/components/list-items/headers/notebook-header.js+++ b/apps/mobile/app/components/list-items/headers/notebook-header.js@@ -33,7 +33,7 @@ import Paragraph from "../../ui/typography/paragraph";export const NotebookHeader = ({ notebook, onEditNotebook }) => {const colors = useThemeStore((state) => state.colors);const [isPinnedToMenu, setIsPinnedToMenu] = useState(- db.settings.isPinned(notebook.id)+ db.shortcuts.exists(notebook.id));const setMenuPins = useMenuStore((state) => state.setMenuPins);const totalNotes = getTotalNotes(notebook);@@ -42,15 +42,20 @@ export const NotebookHeader = ({ notebook, onEditNotebook }) => {const onPinNotebook = async () => {try {if (isPinnedToMenu) {- await db.settings.unpin(notebook.id);+ await db.shortcuts.remove(notebook.id);} else {- await db.settings.pin(notebook.type, { id: notebook.id });+ await db.shortcuts.add({+ item: {+ id: notebook.id,+ type: "notebook"+ }+ });ToastEvent.show({heading: "Shortcut created",type: "success"});}- setIsPinnedToMenu(db.settings.isPinned(notebook.id));+ setIsPinnedToMenu(db.shortcuts.exists(notebook.id));setMenuPins();} catch (e) {console.error(e);diff --git a/apps/mobile/app/components/list-items/selection-wrapper/action-strip.js b/apps/mobile/app/components/list-items/selection-wrapper/action-strip.jsindex baf4c8986..023738a7b 100644--- a/apps/mobile/app/components/list-items/selection-wrapper/action-strip.js+++ b/apps/mobile/app/components/list-items/selection-wrapper/action-strip.js@@ -47,7 +47,7 @@ export const ActionStrip = ({ note, setActionStrip }) => {const [width, setWidth] = useState(dWidth - 16);useEffect(() => {if (note.type === "note") return;- setIsPinnedToMenu(db.settings.isPinned(note.id));+ setIsPinnedToMenu(db.shortcuts.exists(note.id));}, [note.id, note.type]);const updateNotes = () => {@@ -117,26 +117,34 @@ export const ActionStrip = ({ note, setActionStrip }) => {onPress: async () => {try {if (isPinnedToMenu) {- await db.settings.unpin(note.id);+ await db.shortcuts.remove(note.id);ToastEvent.show({heading: "Shortcut removed from menu",type: "success"});} else {if (note.type === "topic") {- await db.settings.pin(note.type, {- id: note.id,- notebookId: note.notebookId+ await db.shortcuts.add({+ item: {+ type: "topic",+ id: note.id,+ notebookId: note.notebookId+ }});} else {- await db.settings.pin(note.type, { id: note.id });+ await db.shortcuts.add({+ item: {+ type: "notebook",+ id: note.id+ }+ });}ToastEvent.show({heading: "Shortcut added to menu",type: "success"});}- setIsPinnedToMenu(db.settings.isPinned(note.id));+ setIsPinnedToMenu(db.shortcuts.exists(note.id));setMenuPins();setActionStrip(false);diff --git a/apps/mobile/app/components/side-menu/pinned-section.js b/apps/mobile/app/components/side-menu/pinned-section.jsindex 50307e999..ebba3716d 100644--- a/apps/mobile/app/components/side-menu/pinned-section.js+++ b/apps/mobile/app/components/side-menu/pinned-section.js@@ -158,7 +158,7 @@ export const PinItem = React.memo(title="Remove Shortcut"type="error"onPress={async () => {- await db.settings.unpin(item.id);+ await db.shortcuts.remove(item.id);setVisible(false);setMenuPins();}}diff --git a/apps/mobile/app/hooks/use-actions.js b/apps/mobile/app/hooks/use-actions.jsindex af947cfa6..598a54449 100644--- a/apps/mobile/app/hooks/use-actions.js+++ b/apps/mobile/app/hooks/use-actions.js@@ -64,7 +64,7 @@ export const useActions = ({ close = () => null, item }) => {const setSelectedItem = useSelectionStore((state) => state.setSelectedItem);const setMenuPins = useMenuStore((state) => state.setMenuPins);const [isPinnedToMenu, setIsPinnedToMenu] = useState(- db.settings.isPinned(item.id)+ db.shortcuts.exists(item.id));const user = useUserStore((state) => state.user);const [notifPinned, setNotifPinned] = useState(null);@@ -77,7 +77,7 @@ export const useActions = ({ close = () => null, item }) => {if (item.id === null) return;checkNotifPinned();if (item.type !== "note") {- setIsPinnedToMenu(db.settings.isPinned(item.id));+ setIsPinnedToMenu(db.shortcuts.exists(item.id));}}, [checkNotifPinned, item]);@@ -366,21 +366,29 @@ export const useActions = ({ close = () => null, item }) => {close();try {if (isPinnedToMenu) {- await db.settings.unpin(item.id);+ await db.shortcuts.remove(item.id);} else {if (item.type === "topic") {- await db.settings.pin(item.type, {- id: item.id,- notebookId: item.notebookId+ await db.shortcuts.add({+ item: {+ type: "topic",+ id: item.id,+ notebookId: item.notebookId+ }});} else {- await db.settings.pin(item.type, { id: item.id });+ await db.shortcuts.add({+ item: {+ type: item.type,+ id: item.id+ }+ });}}- setIsPinnedToMenu(db.settings.isPinned(item.id));+ setIsPinnedToMenu(db.shortcuts.exists(item.id));setMenuPins();} catch (e) {- console.error(e);+ console.error("error", e);}}diff --git a/apps/mobile/app/stores/use-menu-store.ts b/apps/mobile/app/stores/use-menu-store.tsindex 9fab5916c..de14a9149 100644--- a/apps/mobile/app/stores/use-menu-store.ts+++ b/apps/mobile/app/stores/use-menu-store.ts@@ -34,11 +34,11 @@ export const useMenuStore = create<MenuStore>((set) => ({colorNotes: [],setMenuPins: () => {try {- set({ menuPins: db.settings?.pins || [] });+ set({ menuPins: [...(db.shortcuts?.resolved as [])] });} catch (e) {setTimeout(() => {try {- set({ menuPins: db.settings?.pins || [] });+ set({ menuPins: [...(db.shortcuts?.resolved as [])] });} catch (e) {console.error(e);}