From 4bc4de43295e52c7d7bb9fe2db4e440204138130 Mon Sep 17 00:00:00 2001 From: thecodrr Date: Sat, 14 Mar 2020 09:25:12 +0500 Subject: [PATCH] fix: #107 --- apps/web/src/stores/editor-store.js | 5 ++++- apps/web/src/stores/tag-store.js | 18 ++++++++++++++++++ apps/web/src/views/Tags.js | 10 +++++++--- 3 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 apps/web/src/stores/tag-store.js diff --git a/apps/web/src/stores/editor-store.js b/apps/web/src/stores/editor-store.js index dc15d072a..da481ed7a 100644 --- a/apps/web/src/stores/editor-store.js +++ b/apps/web/src/stores/editor-store.js @@ -1,6 +1,7 @@ import createStore from "../common/store"; import { store as noteStore, LIST_TYPES } from "./note-store"; import { store as appStore } from "./app-store"; +import { store as tagStore } from "./tag-store"; import { db } from "../common"; import { showPasswordDialog } from "../components/dialogs/passworddialog"; @@ -205,11 +206,13 @@ function updateContext(key, array) { // update notes if the selected context (the current view in the navigator) is a tag or color const notesState = noteStore.getState(); const context = notesState.selectedContext; - console.log(context); if (context.type === type) { const isValue = array.some(value => value === context.value); if (isValue) noteStore.getState().setSelectedContext(context); } + if (type === "tag") { + tagStore.getState().refreshTags(); + } } const [useStore, store] = createStore(editorStore); diff --git a/apps/web/src/stores/tag-store.js b/apps/web/src/stores/tag-store.js new file mode 100644 index 000000000..7d8ff986d --- /dev/null +++ b/apps/web/src/stores/tag-store.js @@ -0,0 +1,18 @@ +import createStore from "../common/store"; +import { db } from "../common"; +import { showPasswordDialog } from "../components/dialogs/passworddialog"; + +function tagStore(set, get) { + return { + tags: [], + refreshTags: function() { + set(state => { + state.tags = db.tags.all; + }); + } + }; +} + +const [useStore, store] = createStore(tagStore); + +export { useStore, store }; diff --git a/apps/web/src/views/Tags.js b/apps/web/src/views/Tags.js index 6f70cd418..b7dd8cba6 100644 --- a/apps/web/src/views/Tags.js +++ b/apps/web/src/views/Tags.js @@ -3,7 +3,8 @@ import { Flex, Text } from "rebass"; import ListContainer from "../components/list-container"; import ListItem from "../components/list-item"; import { db } from "../common"; -import { useStore } from "../stores/note-store"; +import { useStore as useNotesStore } from "../stores/note-store"; +import { useStore, store } from "../stores/tag-store"; import TagsPlaceholder from "../components/placeholders/tags-placeholder"; const TagNode = ({ title }) => ( @@ -16,8 +17,11 @@ const TagNode = ({ title }) => ( ); const Tags = props => { - const setSelectedContext = useStore(store => store.setSelectedContext); - const tags = db.tags.all; + const setSelectedContext = useNotesStore(store => store.setSelectedContext); + const tags = useStore(store => store.tags); + useEffect(() => { + store.getState().refreshTags(); + }, []); return (