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
refactor: cleanup context logic
thecodrra7b568d10835
diff --git a/apps/web/src/components/navigation-menu/index.js b/apps/web/src/components/navigation-menu/index.jsindex 9a38a7b13..190537c50 100644--- a/apps/web/src/components/navigation-menu/index.js+++ b/apps/web/src/components/navigation-menu/index.js@@ -76,7 +76,6 @@ function NavigationMenu(props) {title: toTitleCase(color.title),context: {type: "color",- colors: [color.title],value: color.title,},});diff --git a/apps/web/src/navigation/navigators/rootnavigator.js b/apps/web/src/navigation/navigators/rootnavigator.jsindex a1d564fb0..b5abb14be 100644--- a/apps/web/src/navigation/navigators/rootnavigator.js+++ b/apps/web/src/navigation/navigators/rootnavigator.js@@ -54,7 +54,7 @@ export const routes = {options: SelectionModeOptions.FavoritesOptions,},{- context: { type: "favorites", favorite: true },+ context: { type: "favorites" },}),...createNormalRoute("trash", Trash, Icon.Trash, {diff --git a/apps/web/src/stores/editor-store.js b/apps/web/src/stores/editor-store.jsindex 3a219a2b0..ec18b8a78 100644--- a/apps/web/src/stores/editor-store.js+++ b/apps/web/src/stores/editor-store.js@@ -20,6 +20,7 @@ const DEFAULT_SESSION = {favorite: false,locked: false,tags: [],+ context: undefined,colors: [],dateEdited: 0,content: {@@ -75,16 +76,19 @@ class EditorStore extends BaseStore {saveSession = (oldSession) => {this.set((state) => (state.session.isSaving = true));this._saveFn()(this.get().session).then(async (id) => {- if (oldSession) {+ storeSync: if (oldSession) {if (oldSession.tags.length !== this.get().session.tags.length)tagStore.refresh();+if (oldSession.colors.length !== this.get().session.colors.length)appStore.refreshColors();- if (oldSession.notebook)- if (oldSession.state === "new" && oldSession.notebook.topic) {- await db.notes.move(oldSession.notebook, id);- }+ if (oldSession.state !== "new" || !oldSession.context) break storeSync;++ const { type, value } = oldSession.context;+ if (type === "topic") await db.notes.move(value, id);+ else if (type === "color") await db.notes.note(id).color(value);+ else if (type === "tag") await db.notes.note(id).tag(value);}if (!this.get().session.id) {@@ -108,7 +112,7 @@ class EditorStore extends BaseStore {this.set(function (state) {state.session = {...DEFAULT_SESSION,- ...context,+ context,state: SESSION_STATES.new,};});@@ -124,10 +128,8 @@ class EditorStore extends BaseStore {state.session.timeout = setTimeout(() => {+ this.set((state) => (state.session.state = SESSION_STATES.stale));this.session = this.get().session;- this.set((state) => {- state.session.state = SESSION_STATES.stale;- });this.saveSession(oldSession);},immediate ? 0 : 500diff --git a/apps/web/src/stores/note-store.js b/apps/web/src/stores/note-store.jsindex 405c45c79..6c61543cc 100644--- a/apps/web/src/stores/note-store.js+++ b/apps/web/src/stores/note-store.js@@ -36,12 +36,11 @@ class NoteStore extends BaseStore {break;case "color":notes = db.notes.colored(context.value);- //console.log(context.value, " I am in notesStore");break;case "topic":notes = db.notebooks- .notebook(context.notebook.id)- .topics.topic(context.value).all;+ .notebook(context.value.id)+ .topics.topic(context.value.topic).all;break;case "favorites":notes = db.notes.favorites;diff --git a/apps/web/src/views/Home.js b/apps/web/src/views/Home.jsindex 76dbdb19a..94b0d8102 100644--- a/apps/web/src/views/Home.js+++ b/apps/web/src/views/Home.js@@ -11,7 +11,6 @@ function Home() {useEffect(() => store.refresh(), []);const notes = useStore((store) => store.notes);const newSession = useEditorStore((store) => store.newSession);- console.log(notes);return (<ListContaineritems={notes.items}diff --git a/apps/web/src/views/Notes.js b/apps/web/src/views/Notes.jsindex b403908be..7614280a7 100644--- a/apps/web/src/views/Notes.js+++ b/apps/web/src/views/Notes.js@@ -16,7 +16,6 @@ function Notes(props) {}}, [props.context, setContext]);- console.log(context);if (!context) return null;return (<ListContainer@@ -27,11 +26,7 @@ function Notes(props) {)}button={{content: "Make a new note",- onClick: () =>- newSession({- ...DEFAULT_CONTEXT,- ...props.context,- }),+ onClick: () => newSession(props.context),}}/>);diff --git a/apps/web/src/views/Tags.js b/apps/web/src/views/Tags.jsindex cf53de167..fccec54c6 100644--- a/apps/web/src/views/Tags.js+++ b/apps/web/src/views/Tags.js@@ -2,7 +2,6 @@ import React, { useEffect } from "react";import { Flex, Text } from "rebass";import ListContainer from "../components/list-container";import ListItem from "../components/list-item";-import { useStore as useNotesStore } from "../stores/note-store";import { useStore, store } from "../stores/tag-store";import TagsPlaceholder from "../components/placeholders/tags-placeholder";@@ -18,7 +17,6 @@ function TagNode({ title }) {}function Tags(props) {- const setContext = useNotesStore((store) => store.setContext);const tags = useStore((store) => store.tags);useEffect(() => {store.refresh();@@ -37,10 +35,9 @@ function Tags(props) {title={<TagNode title={title} />}info={`${noteIds.length} notes`}onClick={() => {- setContext({ type: "tag", value: title });props.navigator.navigate("notes", {title: "#" + title,- context: { tags: [title] },+ context: { type: "tag", value: title },});}}/>diff --git a/apps/web/src/views/Topics.js b/apps/web/src/views/Topics.jsindex bf44a5c27..c24069731 100644--- a/apps/web/src/views/Topics.js+++ b/apps/web/src/views/Topics.js@@ -2,12 +2,10 @@ import React, { useState, useEffect } from "react";import Topic from "../components/topic";import { Flex } from "rebass";import ListContainer from "../components/list-container";-import { useStore as useNoteStore } from "../stores/note-store";import { useStore as useNbStore } from "../stores/notebook-store";import { showTopicDialog } from "../components/dialogs/topicdialog";function Topics(props) {- const setContext = useNoteStore((store) => store.setContext);const setSelectedNotebookTopics = useNbStore((store) => store.setSelectedNotebookTopics);@@ -34,16 +32,12 @@ function Topics(props) {item={item}onClick={() => {let topic = item;- setContext({- type: "topic",- value: topic.title,- notebook: props.notebook,- });props.navigator.navigate("notes", {title: props.notebook.title,subtitle: topic.title,context: {- notebook: { id: props.notebook.id, topic: topic.title },+ type: "topic",+ value: { id: props.notebook.id, topic: topic.title },},});}}