This commit is contained in:
thecodrr
2020-03-14 09:25:12 +05:00
parent 4b84e363f4
commit 4bc4de4329
3 changed files with 29 additions and 4 deletions

View File

@@ -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);

View File

@@ -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 };

View File

@@ -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 (
<ListContainer
type="tags"