Skip to content

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

feat: add tags (#13)

Waqar Ahmedea68dc1ab819
diff --git a/apps/web/src/components/editor/index.js b/apps/web/src/components/editor/index.js
index 2b5b5d903..36618dfb5 100644
--- a/apps/web/src/components/editor/index.js
+++ b/apps/web/src/components/editor/index.js
@@ -134,10 +134,12 @@ export default class Editor extends React.Component {
this.titleRef.value = note.title;
this.pinned = note.pinned;
this.favorite = note.favorite;
+ this.tags = note.tags;
this.setState({
pinned: this.pinned,
favorite: this.favorite,
- colors: note.colors
+ colors: note.colors,
+ tags: note.tags
});
let delta = await dbNote.delta();
this.quill.setContents(delta);
@@ -156,10 +158,10 @@ export default class Editor extends React.Component {
content,
title: this.title,
id: this.id,
- favorite: this.state.favorite,
- pinned: this.state.pinned,
- colors: this.state.colors
- //TODO add tags once the database is done
+ favorite: this.favorite,
+ pinned: this.pinned,
+ colors: this.state.colors,
+ //tags: this.state.tags
};
return await db.notes.add(note);
}
@@ -234,7 +236,7 @@ export default class Editor extends React.Component {
this.setState({ colors });
}}
tags={this.state.tags}
- addTag={tag => {
+ addTag={async tag => {
let tags = [...this.state.tags];
if (tags.includes(tag)) {
tags.splice(tags.indexOf(tag), 1);
@@ -242,6 +244,8 @@ export default class Editor extends React.Component {
tags[this.state.tags.length] = tag;
}
this.setState({ tags });
+ if (this.id)
+ await db.notes.note(this.id).tag(tag);
}}
onLocked={state => {}}
/>
diff --git a/apps/web/src/components/list-item/index.js b/apps/web/src/components/list-item/index.js
index 822342797..b489e3da4 100644
--- a/apps/web/src/components/list-item/index.js
+++ b/apps/web/src/components/list-item/index.js
@@ -67,7 +67,7 @@ const ListItem = props => (
}}
>
<Flex flexDirection="row" justifyContent="space-between">
- <Text fontFamily="heading" fontSize="title" fontWeight="bold">
+ <Text fontFamily={"heading"} fontSize="title" fontWeight={"bold"}>
{props.title}
</Text>
</Flex>
diff --git a/apps/web/src/components/properties/index.js b/apps/web/src/components/properties/index.js
index c171740a8..e4e8e007a 100644
--- a/apps/web/src/components/properties/index.js
+++ b/apps/web/src/components/properties/index.js
@@ -92,7 +92,9 @@ const Properties = props => {
event.key === " " ||
event.key === ","
) {
- props.addTag && props.addTag(event.target.value);
+ props.addTag &&
+ event.target.value &&
+ props.addTag(event.target.value);
event.target.value = "";
}
}}
diff --git a/apps/web/src/navigation/navigators/index.js b/apps/web/src/navigation/navigators/index.js
index 09f5d9fbc..a31df07b9 100644
--- a/apps/web/src/navigation/navigators/index.js
+++ b/apps/web/src/navigation/navigators/index.js
@@ -1,3 +1,4 @@
export const NotebookNavigator = require("./nbnavigator").default;
export const RootNavigator = require("./rootnavigator").default;
export const SettingsNavigator = require("./settingnavigator").default;
+export const TagNavigator = require("./tagnavigator").default;
diff --git a/apps/web/src/navigation/navigators/rootnavigator.js b/apps/web/src/navigation/navigators/rootnavigator.js
index ec34de42a..ced8cc685 100644
--- a/apps/web/src/navigation/navigators/rootnavigator.js
+++ b/apps/web/src/navigation/navigators/rootnavigator.js
@@ -3,7 +3,8 @@ import {
SettingsContainer,
Favorites,
Trash,
- NotebooksContainer
+ NotebooksContainer,
+ TagsContainer
} from "../../views";
import * as Icon from "react-feather";
import {
@@ -50,6 +51,7 @@ const routes = {
}),
...createNormalRoute("favorites", Favorites, Icon.Star),
...createNormalRoute("trash", Trash, Icon.Trash2),
+ ...createRoute("tags", TagsContainer, { icon: Icon.Tag }),
...colorRoutes,
...bottomRoutes
};
diff --git a/apps/web/src/navigation/navigators/tagnavigator.js b/apps/web/src/navigation/navigators/tagnavigator.js
new file mode 100644
index 000000000..1dd507db5
--- /dev/null
+++ b/apps/web/src/navigation/navigators/tagnavigator.js
@@ -0,0 +1,12 @@
+import { Notes, Tags } from "../../views";
+import Navigator from "../index";
+import { createRoute } from "../routes";
+
+const routes = {
+ ...createRoute("tags", Tags, { title: "Tags" }),
+ ...createRoute("notes", Notes)
+};
+const TagNavigator = new Navigator("TagNavigator", routes, {
+ backButtonEnabled: true
+});
+export default TagNavigator;
diff --git a/apps/web/src/views/Tags.js b/apps/web/src/views/Tags.js
new file mode 100644
index 000000000..c22f58310
--- /dev/null
+++ b/apps/web/src/views/Tags.js
@@ -0,0 +1,53 @@
+import React, { useEffect } from "react";
+import { Flex, Text } from "rebass";
+import ListContainer from "../components/list-container";
+import ListItem from "../components/list-item";
+import { db } from "../common";
+
+const TagNode = ({ title }) => (
+ <Text as="span" fontFamily={"body"} fontSize="title" fontWeight={"body"}>
+ <Text as="span" color="primary">
+ {"#"}
+ </Text>
+ {title}
+ </Text>
+);
+
+const Tags = props => {
+ const tags = db.tags.all;
+ return (
+ <ListContainer
+ itemsLength={tags.length}
+ item={index => (
+ <ListItem
+ isTag
+ dropdownRefs={[]}
+ menuItems={[]}
+ index={index}
+ title={<TagNode title={tags[index].title} />}
+ onClick={() => {
+ const notesOfTag = db.notes.tagged(tags[index].title);
+ props.navigator.navigate("notes", {
+ notes: notesOfTag
+ });
+ }}
+ />
+ )}
+ />
+ );
+};
+
+const TagsContainer = () => {
+ useEffect(() => {
+ const TagNavigator = require("../navigation/navigators/tagnavigator")
+ .default;
+ if (!TagNavigator.restore()) {
+ TagNavigator.navigate("tags");
+ }
+ }, []);
+ return (
+ <Flex className="TagNavigator" flexDirection="column" flex="1 1 auto" />
+ );
+};
+
+export { Tags, TagsContainer };
diff --git a/apps/web/src/views/index.js b/apps/web/src/views/index.js
index a56716eb3..e154ca716 100644
--- a/apps/web/src/views/index.js
+++ b/apps/web/src/views/index.js
@@ -10,3 +10,5 @@ export const Account = require("./Account").default;
export const SettingsContainer = require("./Settings").SettingsContainer;
export const General = require("./General").default;
export const TOS = require("./TOS").default;
+export const Tags = require("./Tags").Tags;
+export const TagsContainer = require("./Tags").TagsContainer;
diff --git a/apps/web/yarn.lock b/apps/web/yarn.lock
index 83d27f8e7..0a35a5c06 100644
--- a/apps/web/yarn.lock
+++ b/apps/web/yarn.lock
@@ -7020,7 +7020,7 @@ normalize-url@^3.0.0, normalize-url@^3.0.1:
"notes-core@https://github.com/thecodrr/notes-core.git":
version "1.1.0"
- resolved "https://github.com/thecodrr/notes-core.git#e591bdeff6852a104ff0db86a0235a95dfbd1fa3"
+ resolved "https://github.com/thecodrr/notes-core.git#5fe97a7017c58d6cbba29cbfb59876be72c53e8b"
dependencies:
fast-sort "^2.0.1"
fuzzysearch "^1.0.3"