Skip to content

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

fix: many fixes to the note tagging system

thecodrr55b4287fa8b1
diff --git a/apps/web/src/common/dialogcontroller.js b/apps/web/src/common/dialogcontroller.js
index 207b7cf7d..a6c111c18 100644
--- a/apps/web/src/common/dialogcontroller.js
+++ b/apps/web/src/common/dialogcontroller.js
@@ -6,6 +6,8 @@ import { qclone } from "qclone";
import { store as notebookStore } from "../stores/notebook-store";
import { store as tagStore } from "../stores/tag-store";
import { store as appStore } from "../stores/app-store";
+import { store as editorStore } from "../stores/editor-store";
+import { store as noteStore } from "../stores/note-store";
import { db } from "./db";
import { showToast } from "../utils/toast";
import { Flex, Text } from "rebass";
@@ -487,6 +489,8 @@ export function showEditTagDialog(tagId) {
await db.tags.rename(tagId, title);
showToast("success", "Tag edited!");
tagStore.refresh();
+ editorStore.refreshTags();
+ noteStore.refresh();
perform(true);
}}
/>
diff --git a/apps/web/src/common/list-profiles.js b/apps/web/src/common/list-profiles.js
index 57f000de5..1c1734baa 100644
--- a/apps/web/src/common/list-profiles.js
+++ b/apps/web/src/common/list-profiles.js
@@ -11,22 +11,28 @@ import {
getNoteHeight,
MAX_HEIGHTS,
} from "./height-calculator";
+import { db } from "./db";
function createProfile(item, itemHeight, estimatedItemHeight) {
return { item, itemHeight, estimatedItemHeight };
}
const NotesProfile = createProfile(
- (index, item, context) => (
- <Note
- index={index}
- pinnable={!context}
- item={item}
- tags={item.tags?.slice() || []}
- notebooks={item.notebooks?.slice() || []}
- context={context}
- />
- ),
+ (index, item, context) => {
+ let tags = item.tags;
+ if (tags) tags = tags.map((t) => db.tags.tag(t)).slice(0, 2);
+
+ return (
+ <Note
+ index={index}
+ pinnable={!context}
+ item={item}
+ tags={tags || []}
+ notebooks={item.notebooks?.slice() || []}
+ context={context}
+ />
+ );
+ },
getNoteHeight,
MAX_HEIGHTS.note
);
diff --git a/apps/web/src/components/editor/header.js b/apps/web/src/components/editor/header.js
index fdbd09209..c105deef5 100644
--- a/apps/web/src/components/editor/header.js
+++ b/apps/web/src/components/editor/header.js
@@ -32,15 +32,14 @@ function Header() {
<IconTag
testId={`tag-${tag}`}
key={tag}
- text={tag}
+ text={db.tags.alias(tag)}
icon={Icon.Tag}
title={`Click to remove`}
onClick={() => setTag(tag)}
- styles={{ text: { fontSize: "body" } }}
+ styles={{ container: { mr: 1 }, text: { fontSize: "body" } }}
/>
))}
<Autosuggest
- sx={{ ml: 1 }}
getData={() => db.tags.all}
getFields={(item) => [db.tags.alias(item.id)]}
limit={10}
@@ -115,16 +114,19 @@ function Autosuggest({
setFiltered([]);
return;
}
- const filtered = getData().filter((d) => {
+ let filtered = getData().filter((d) => {
const fields = getFields(d);
return (
fields.some((field) => {
- return field.startsWith(value.toLowerCase());
+ return field.toLowerCase().startsWith(value.toLowerCase());
}) &&
(!customFilter || customFilter(d))
);
});
- setFiltered(filtered.slice(0, limit));
+ filtered = filtered.slice(0, limit);
+ setFiltered(filtered);
+ if (filtered.length > 0) setSelectedIndex(0);
+ else setSelectedIndex(-1);
}}
onKeyDown={(e) => {
if (e.key === "Enter") {
diff --git a/apps/web/src/components/note/index.js b/apps/web/src/components/note/index.js
index c5b06a13b..794e7e0ac 100644
--- a/apps/web/src/components/note/index.js
+++ b/apps/web/src/components/note/index.js
@@ -77,17 +77,15 @@ function Note(props) {
icon={Icon.Notebook}
/>
)}
- {tags?.slice(0, 2).map((tag) => {
- const tagItem = db.tags.tag(tag);
- if (!tagItem) return null;
+ {tags.map((tag) => {
return (
<IconTag
- key={tagItem.id}
- text={db.tags.alias(tagItem.id)}
+ key={tag.id}
+ text={tag.alias}
icon={Icon.Tag}
onClick={() => {
- if (!tagItem.id) return showToast("Tag not found.");
- navigate(`/tags/${tagItem.id}`);
+ if (!tag.id) return showToast("Tag not found.");
+ navigate(`/tags/${tag.id}`);
}}
/>
);
diff --git a/apps/web/src/stores/editor-store.js b/apps/web/src/stores/editor-store.js
index 5eb95be7e..c3e25ee9b 100644
--- a/apps/web/src/stores/editor-store.js
+++ b/apps/web/src/stores/editor-store.js
@@ -52,6 +52,12 @@ class EditorStore extends BaseStore {
await this.openSession(id, true);
};
+ refreshTags = () => {
+ this.set((state) => {
+ state.session.tags = state.session.tags.slice();
+ });
+ };
+
openLockedSession = async (note) => {
this.set((state) => {
state.session = {
@@ -245,6 +251,7 @@ class EditorStore extends BaseStore {
};
async _setTag(value) {
+ value = db.tags.sanitize(value);
if (!value) return;
const { tags, id } = this.get().session;
@@ -253,11 +260,6 @@ class EditorStore extends BaseStore {
let index = tags.indexOf(value);
- this.setSession((state) => {
- if (index <= -1) state.session.tags.push(value);
- else state.session.tags.splice(index, 1);
- });
-
if (index > -1) {
await note.untag(value);
appStore.refreshMenuPins();
@@ -265,6 +267,10 @@ class EditorStore extends BaseStore {
await note.tag(value);
}
+ this.set((state) => {
+ state.session.tags = db.notes.note(id).tags.slice();
+ });
+
tagStore.refresh();
noteStore.refresh();
}