Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

fix: remove unnecessary calls to getState()

thecodrr23c73f24130d
diff --git a/apps/web/src/common/selectionoptions.js b/apps/web/src/common/selectionoptions.js
index ec5c2e564..12490683d 100644
--- a/apps/web/src/common/selectionoptions.js
+++ b/apps/web/src/common/selectionoptions.js
@@ -1,5 +1,5 @@
import * as Icon from "../components/icons";
-import { store as selectionStore } from "../stores/app-store";
+import { store as selectionStore } from "../stores/selection-store";
import { store as notesStore } from "../stores/note-store";
import { store as nbStore } from "../stores/notebook-store";
import { store as editorStore } from "../stores/editor-store";
@@ -12,8 +12,8 @@ function createOption(icon, onClick) {
return {
icon,
onClick: async () => {
- await onClick.call(this, selectionStore.getState());
- selectionStore.getState().toggleSelectionMode(false);
+ await onClick.call(this, selectionStore);
+ selectionStore.toggleSelectionMode(false);
}
};
}
@@ -29,23 +29,22 @@ const DeleteOption = createOption(Icon.Trash, async function(state) {
return;
const item = state.selectedItems[0];
var isAnyNoteOpened = false;
- const editorState = editorStore.getState();
const items = state.selectedItems.map(item => {
- if (item.id === editorState.session.id) isAnyNoteOpened = true;
+ if (item.id === editorStore.session.id) isAnyNoteOpened = true;
if (item.locked) return 0;
return item.id;
});
if (isAnyNoteOpened) {
- editorState.newSession();
+ editorStore.newSession();
}
if (item.type === "note") {
await db.notes.delete(...items);
- notesStore.getState().refresh();
+ notesStore.refresh();
} else if (item.type === "notebook") {
await db.notebooks.delete(...items);
- nbStore.getState().refresh();
+ nbStore.refresh();
} else if (item.notebookId) {
// its a topic
await db.notebooks.notebook(item.notebookId).topics.delete(...items);
@@ -59,7 +58,7 @@ const FavoriteOption = createOption(Icon.Star, function(state) {
if (item.favorite) return;
await db.notes.note(item.id).favorite();
});
- notesStore.getState().refresh();
+ notesStore.refresh();
});
const UnfavoriteOption = createOption(Icon.Star, function(state) {
@@ -68,7 +67,7 @@ const UnfavoriteOption = createOption(Icon.Star, function(state) {
if (!item.favorite) return;
await db.notes.note(item.id).favorite();
});
- notesStore.getState().setContext({ type: "favorites" });
+ notesStore.setContext({ type: "favorites" });
});
const AddToNotebookOption = createOption(Icon.Plus, async function(state) {
@@ -82,7 +81,7 @@ const AddToNotebookOption = createOption(Icon.Plus, async function(state) {
const RestoreOption = createOption(Icon.Restore, async function(state) {
const items = state.selectedItems.map(item => item.id);
await db.trash.restore(...items);
- trashStore.getState().refresh();
+ trashStore.refresh();
});
const NotesOptions = createOptions([AddToNotebookOption, FavoriteOption]);
diff --git a/apps/web/src/components/dialogs/add-notebook-dialog.js b/apps/web/src/components/dialogs/add-notebook-dialog.js
index 6557a0e7f..d807ebaad 100644
--- a/apps/web/src/components/dialogs/add-notebook-dialog.js
+++ b/apps/web/src/components/dialogs/add-notebook-dialog.js
@@ -186,7 +186,7 @@ export function showEditNoteDialog(notebook) {
notebook={notebook}
edit={true}
onDone={async nb => {
- await store.getState().add(nb);
+ await store.add(nb);
perform(false);
}}
close={() => {
diff --git a/apps/web/src/components/dialogs/topicdialog.js b/apps/web/src/components/dialogs/topicdialog.js
index 5b5e92f71..b0c0dbc1e 100644
--- a/apps/web/src/components/dialogs/topicdialog.js
+++ b/apps/web/src/components/dialogs/topicdialog.js
@@ -43,7 +43,7 @@ export function showTopicDialog(notebook) {
onYes={async topic => {
if (!topic) return;
await db.notebooks.notebook(notebook).topics.add(topic);
- store.getState().setSelectedNotebookTopics(notebook);
+ store.setSelectedNotebookTopics(notebook);
perform(true);
}}
/>
diff --git a/apps/web/src/components/editor/titlebox.js b/apps/web/src/components/editor/titlebox.js
index ea39c1f34..92dafa139 100644
--- a/apps/web/src/components/editor/titlebox.js
+++ b/apps/web/src/components/editor/titlebox.js
@@ -50,7 +50,7 @@ class TitleBox extends React.Component {
alignItems="center"
pr={3}
onClick={() => {
- appStore.getState().toggleFocusMode();
+ appStore.toggleFocusMode();
this.setState({ isFocusMode: !this.state.isFocusMode });
}}
>
diff --git a/apps/web/src/components/list-item/index.js b/apps/web/src/components/list-item/index.js
index 66ca47ad1..2ddf20d32 100644
--- a/apps/web/src/components/list-item/index.js
+++ b/apps/web/src/components/list-item/index.js
@@ -25,7 +25,7 @@ function selectMenuItem(isSelected, toggleSelection) {
return {
title: isSelected ? "Unselect" : "Select",
onClick: () => {
- const appState = appStore.getState();
+ const appState = appStore;
if (!appState.isSelectionMode) {
appState.enterSelectionMode();
toggleSelection();
diff --git a/apps/web/src/components/note/index.js b/apps/web/src/components/note/index.js
index d186da8ea..2710a341e 100644
--- a/apps/web/src/components/note/index.js
+++ b/apps/web/src/components/note/index.js
@@ -1,5 +1,5 @@
import React from "react";
-import { Flex, Box } from "rebass";
+import { Flex, Box, Text } from "rebass";
import * as Icon from "../icons";
import TimeAgo from "timeago-react";
import ListItem from "../list-item";
@@ -24,17 +24,17 @@ function menuItems(note, context) {
},
{
title: note.pinned ? "Unpin" : "Pin",
- onClick: () => store.getState().pin(note)
+ onClick: () => store.pin(note)
},
{
title: note.favorite ? "Unfavorite" : "Favorite",
- onClick: () => store.getState().favorite(note)
+ onClick: () => store.favorite(note)
},
- { title: "Edit", onClick: () => editorStore.getState().openSession(note) },
+ { title: "Edit", onClick: () => editorStore.openSession(note) },
{
title: note.locked ? "Unlock" : "Lock",
onClick: async () => {
- const { unlock, lock } = store.getState();
+ const { unlock, lock } = store;
if (!note.locked) {
lock(note.id);
} else {
@@ -56,7 +56,7 @@ function menuItems(note, context) {
.notebook(context.notebook.id)
.topics.topic(context.value)
.delete(note.id);
- await store.getState().setContext(context);
+ await store.setContext(context);
}
});
}
@@ -80,7 +80,7 @@ function menuItems(note, context) {
"Are you sure you want to delete this note?"
).then(async res => {
if (res) {
- await store.getState().delete(note.id);
+ await store.delete(note.id);
}
});
}
@@ -104,33 +104,50 @@ function Note(props) {
id={note.id}
index={index}
onClick={async () => {
- await editorStore.getState().openSession(note);
+ await editorStore.openSession(note);
}}
info={
- <Flex variant="rowCenter">
- {note.colors.map((item, index) => (
- <Box
- key={item}
- style={{
- width: 13,
- marginLeft: index ? -8 : 0,
- marginRight: index === note.colors.length - 1 ? 5 : 0,
- height: 13,
- backgroundColor: item,
- borderRadius: 100
- }}
- />
- ))}
- <TimeAgo datetime={note.dateCreated} />
- {note.locked && (
- <Icon.Lock
- size={13}
- color={theme.colors.fontTertiary}
- sx={{ ml: 1 }}
- />
- )}
- {note.favorite && (
- <Icon.Star color={theme.colors.favorite} size={13} sx={{ ml: 1 }} />
+ <Flex flex="1 1 auto" justifyContent="space-between">
+ <Flex variant="rowCenter">
+ {note.colors.map((item, index) => (
+ <Box
+ key={item}
+ style={{
+ width: 13,
+ marginLeft: index ? -8 : 0,
+ marginRight: index === note.colors.length - 1 ? 5 : 0,
+ height: 13,
+ backgroundColor: item,
+ borderRadius: 100
+ }}
+ />
+ ))}
+ <TimeAgo datetime={note.dateCreated} />
+ {note.locked && (
+ <Icon.Lock
+ size={13}
+ color={theme.colors.fontTertiary}
+ sx={{ ml: 1 }}
+ />
+ )}
+ {note.favorite && (
+ <Icon.Star
+ color={theme.colors.favorite}
+ size={13}
+ sx={{ ml: 1 }}
+ />
+ )}
+ </Flex>
+ {note.conflicted && (
+ <Text
+ ml={1}
+ p={1}
+ bg="error"
+ color="static"
+ sx={{ borderRadius: "default" }}
+ >
+ CONFLICT
+ </Text>
)}
</Flex>
}
@@ -151,6 +168,7 @@ export default React.memo(Note, function(prevProps, nextProps) {
prevItem.headline === nextItem.headline &&
prevItem.title === nextItem.title &&
prevItem.locked === nextItem.locked &&
+ prevItem.conflicted === nextItem.conflicted &&
JSON.stringify(prevItem.colors) === JSON.stringify(nextItem.colors)
);
});
diff --git a/apps/web/src/components/notebook/index.js b/apps/web/src/components/notebook/index.js
index 5af56f2a5..0494ab1f0 100644
--- a/apps/web/src/components/notebook/index.js
+++ b/apps/web/src/components/notebook/index.js
@@ -9,7 +9,7 @@ function menuItems(notebook, index) {
return [
{
title: notebook.pinned ? "Unpin" : "Pin",
- onClick: () => store.getState().pin(notebook, index)
+ onClick: () => store.pin(notebook, index)
},
{
title: "Edit",
@@ -18,7 +18,7 @@ function menuItems(notebook, index) {
{
title: "Delete",
color: "red",
- onClick: () => store.getState().delete(notebook.id, index)
+ onClick: () => store.delete(notebook.id, index)
}
];
}
diff --git a/apps/web/src/navigation/index.js b/apps/web/src/navigation/index.js
index 67560dff5..4483b43fe 100644
--- a/apps/web/src/navigation/index.js
+++ b/apps/web/src/navigation/index.js
@@ -48,7 +48,7 @@ class Navigator {
return false;
}
// exit selection mode on navigate
- selectionStore.getState().toggleSelectionMode(false);
+ selectionStore.toggleSelectionMode(false);
ReactDOM.render(
<AnimatePresence exitBeforeEnter={true}>
<Animated.Flex
diff --git a/apps/web/src/navigation/navigators/rootnavigator.js b/apps/web/src/navigation/navigators/rootnavigator.js
index c6894a71f..21dc6425f 100644
--- a/apps/web/src/navigation/navigators/rootnavigator.js
+++ b/apps/web/src/navigation/navigators/rootnavigator.js
@@ -18,15 +18,15 @@ import { showLogInDialog } from "../../components/dialogs/logindialog";
export const bottomRoutes = {
...createDeadRoute("nightmode", Icon.Theme, {
- onClick: () => themeStore.getState().toggleNightMode()
+ onClick: () => themeStore.toggleNightMode()
}),
...createDeadRoute("sync", Icon.Sync, {
- onClick: async () => userStore.getState().sync(),
+ onClick: async () => userStore.sync(),
animatable: true
}),
...createNormalRoute("account", Account, Icon.User, {
onClick: async () => {
- if (!userStore.getState().isLoggedIn) {
+ if (!userStore.isLoggedIn) {
await showLogInDialog();
return false;
} else return RootNavigator.navigate("account");
diff --git a/apps/web/src/views/Home.js b/apps/web/src/views/Home.js
index 3640fb687..dc93b09a7 100644
--- a/apps/web/src/views/Home.js
+++ b/apps/web/src/views/Home.js
@@ -8,7 +8,7 @@ import ListContainer from "../components/list-container";
import NotesPlaceholder from "../components/placeholders/notesplacholder";
function Home() {
- useEffect(() => store.getState().refresh(), []);
+ useEffect(() => store.refresh(), []);
const notes = useStore(store => store.notes);
const newSession = useEditorStore(store => store.newSession);
return (
diff --git a/apps/web/src/views/Notebooks.js b/apps/web/src/views/Notebooks.js
index e64ff7712..ebdb0cde2 100644
--- a/apps/web/src/views/Notebooks.js
+++ b/apps/web/src/views/Notebooks.js
@@ -9,7 +9,7 @@ import NotebooksPlaceholder from "../components/placeholders/notebooks-placehold
function Notebooks(props) {
const [open, setOpen] = useState(false);
- useEffect(() => store.getState().refresh(), []);
+ useEffect(() => store.refresh(), []);
const notebooks = useStore(state => state.notebooks);
const add = useStore(state => state.add);
return (
diff --git a/apps/web/src/views/Tags.js b/apps/web/src/views/Tags.js
index 994c00537..f1719526a 100644
--- a/apps/web/src/views/Tags.js
+++ b/apps/web/src/views/Tags.js
@@ -21,7 +21,7 @@ function Tags(props) {
const setContext = useNotesStore(store => store.setContext);
const tags = useStore(store => store.tags);
useEffect(() => {
- store.getState().refreshTags();
+ store.refreshTags();
}, []);
return (
<ListContainer
diff --git a/apps/web/src/views/Trash.js b/apps/web/src/views/Trash.js
index f52aef88d..3ea63170f 100644
--- a/apps/web/src/views/Trash.js
+++ b/apps/web/src/views/Trash.js
@@ -13,7 +13,7 @@ function menuItems(item, index) {
return [
{
title: "Restore",
- onClick: () => store.getState().restore(item.id, index)
+ onClick: () => store.restore(item.id, index)
},
{
title: "Delete",
@@ -25,7 +25,7 @@ function menuItems(item, index) {
`Are you sure you want to permanently delete this item?`
).then(async res => {
if (res) {
- await store.getState().delete(item.id, index);
+ await store.delete(item.id, index);
}
});
}
@@ -34,7 +34,7 @@ function menuItems(item, index) {
}
function Trash() {
- useEffect(() => store.getState().refresh(), []);
+ useEffect(() => store.refresh(), []);
const items = useStore(store => store.trash);
const clearTrash = useStore(store => store.clear);
return (