Skip to content

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

feat: add colors to note context menu (#125)

Muhammad Ali6de64a10300a
diff --git a/apps/web/src/components/menu/colors.js b/apps/web/src/components/menu/colors.js
new file mode 100644
index 000000000..203d92dcf
--- /dev/null
+++ b/apps/web/src/components/menu/colors.js
@@ -0,0 +1,43 @@
+import React from "react";
+import { COLORS } from "../../common";
+import * as Icon from "../icons/index";
+import { objectMap } from "../../utils/object";
+import { useStore } from "../../stores/note-store";
+import { Flex } from "rebass";
+
+function Colors(props) {
+ const { id, colors } = props.data;
+ const setColor = useStore((store) => store.setColor);
+
+ return (
+ <Flex flexWrap="wrap">
+ {objectMap(COLORS, (label, code) => (
+ <Flex
+ sx={{ position: "relative" }}
+ onClick={() => setColor(id, label)}
+ key={label}
+ >
+ <Icon.Circle
+ size={25}
+ style={{ cursor: "pointer" }}
+ color={code}
+ strokeWidth={0}
+ />
+ {colors.includes(label) && (
+ <Icon.Checkmark
+ sx={{
+ position: "absolute",
+ top: "4px",
+ left: "5px",
+ cursor: "pointer",
+ }}
+ color="static"
+ size={14}
+ />
+ )}
+ </Flex>
+ ))}
+ </Flex>
+ );
+}
+export default Colors;
diff --git a/apps/web/src/components/menu/index.js b/apps/web/src/components/menu/index.js
index d9cf6e4ab..fe70ea70e 100644
--- a/apps/web/src/components/menu/index.js
+++ b/apps/web/src/components/menu/index.js
@@ -31,7 +31,7 @@ function Menu(props) {
</Text>
{props.menuItems.map(
(item) =>
- !item.invisible && (
+ !item.visible && (
<Flex
key={item.title}
onClick={(e) => {
@@ -55,9 +55,13 @@ function Menu(props) {
},
}}
>
- <Text as="span" fontFamily="body" fontSize="menu">
- {item.title}
- </Text>
+ {item.component ? (
+ <item.component data={props.data} />
+ ) : (
+ <Text as="span" fontFamily="body" fontSize="menu">
+ {item.title}
+ </Text>
+ )}
</Flex>
)
)}
diff --git a/apps/web/src/components/note/index.js b/apps/web/src/components/note/index.js
index bb707129d..4f827840a 100644
--- a/apps/web/src/components/note/index.js
+++ b/apps/web/src/components/note/index.js
@@ -10,10 +10,12 @@ import { store as editorStore } from "../../stores/editor-store";
import { showPasswordDialog } from "../dialogs/passworddialog";
import { db, COLORS } from "../../common";
import { useTheme } from "emotion-theming";
+import Colors from "../menu/colors";
const dropdownRefs = [];
function menuItems(note, context) {
return [
+ { component: Colors },
{
title: note.notebook ? "Move" : "Add to",
onClick: async () => {
@@ -43,7 +45,7 @@ function menuItems(note, context) {
},
},
{
- invisible: context ? (context.type === "topic" ? false : true) : true,
+ visible: context ? (context.type === "topic" ? true : false) : false,
title: "Remove",
onClick: async () => {
confirm(
diff --git a/apps/web/src/stores/note-store.js b/apps/web/src/stores/note-store.js
index b4752cc37..b926e6069 100644
--- a/apps/web/src/stores/note-store.js
+++ b/apps/web/src/stores/note-store.js
@@ -81,6 +81,18 @@ class NoteStore extends BaseStore {
await Vault.lockNote(id, () => this._setValue(id, "locked", true));
};
+ setColor = async (id, color) => {
+ const note = db.notes.note(id);
+ if (!note) return;
+ let index = note.data.colors.indexOf(color);
+ if (index > -1) {
+ await note.uncolor(color);
+ } else {
+ await note.color(color);
+ }
+ this._setValue(id, "colors", db.notes.note(id).data.colors);
+ };
+
/**
* @private
*/
@@ -92,17 +104,17 @@ class NoteStore extends BaseStore {
if (index < 0) return;
arr[index][prop] = value;
- this._syncEditor(noteId, prop);
+ this._syncEditor(noteId, prop, value);
});
};
/**
* @private
*/
- _syncEditor = (noteId, action) => {
+ _syncEditor = (noteId, action, value) => {
const { session, setSession } = editorStore.get();
if (session.id === noteId) {
- setSession((state) => (state.session[action] = !state.session[action]));
+ setSession((state) => (state.session[action] = value));
}
};
}
diff --git a/apps/web/yarn.lock b/apps/web/yarn.lock
index a657d9599..97ced67a2 100644
--- a/apps/web/yarn.lock
+++ b/apps/web/yarn.lock
@@ -7253,7 +7253,7 @@ normalize-url@^3.0.0, normalize-url@^3.0.1:
"notes-core@git+ssh://[email protected]:streetwriters/notesnook-core.git":
version "1.3.0"
- resolved "git+ssh://[email protected]:streetwriters/notesnook-core.git#9168dd22b467caf873bcdd00171693912d2b672a"
+ resolved "git+ssh://[email protected]:streetwriters/notesnook-core.git#f19e76f63dfdf2b9b9914d19ebf139a93dba63c1"
dependencies:
fast-sort "^2.0.1"
fuzzysearch "^1.0.3"