fix: crash when removing last note from a tag

This commit is contained in:
thecodrr
2021-12-08 23:24:37 +05:00
parent 284f46ad02
commit b73b8a3d36
5 changed files with 45 additions and 11 deletions

View File

@@ -48,13 +48,15 @@ async function checkTagPresence(title) {
async function createNoteAndCheckPresence(title) {
await createNote(NOTE, "notes");
await checkNotePresence("notes");
const noteSelector = await checkNotePresence("notes");
expect(
await page.isVisible(
new List("note").view("notes").grouped().atIndex(0).tag(title).build()
)
).toBe(true);
return noteSelector;
}
async function createTagAndCheckPresence(title) {
@@ -199,3 +201,27 @@ test("delete a shortcut of a tag", async ({ page }) => {
await page.isVisible(new Menu("navitem").item("helloworld").build())
).toBe(false);
});
test.only("delete the last note of a tag that is also a shortcut", async ({
page,
}) => {
const tagSelector = await createTagAndCheckPresence("helloworld");
await useContextMenu(tagSelector.build(), async () => {
await clickMenuItem("createshortcut");
});
await page.click(tagSelector.build());
const noteSelector = await createNoteAndCheckPresence("helloworld");
await useContextMenu(noteSelector, async () => {
await clickMenuItem("movetotrash");
});
expect(await page.isVisible(noteSelector)).toBe(false);
await navigateTo("notes");
expect(await page.inputValue(getTestId("routeHeader"))).toBe("Notes");
});

View File

@@ -76,7 +76,12 @@ export default Profiles;
function getTags(item) {
let tags = item.tags;
if (tags) tags = tags.map((t) => db.tags.tag(t)).slice(0, 3);
if (tags)
tags = tags.slice(0, 3).reduce((prev, curr) => {
const tag = db.tags.tag(curr);
if (tag) prev.push(tag);
return prev;
}, []);
return tags || [];
}

View File

@@ -199,7 +199,7 @@ function Editor({ noteId, nonce }) {
onSave={saveSession}
sessionId={sessionId}
onChange={(content, editor) => {
if (!content || content === "<p><br></pr>") return;
if (!content || content === "<p><br></p>") return;
editorstore.get().setSessionContent({
type: "tiny",

View File

@@ -124,7 +124,7 @@ const plugins = {
pro: "textpattern picker",
};
const changeEvents = "change keyup input compositionend paste";
const changeEvents = "change input compositionend paste";
function TinyMCE(props) {
const {
@@ -236,6 +236,7 @@ function TinyMCE(props) {
}
const onEditorChange = debounce((e) => {
console.log("onEditorChange", e);
if (!editor.getHTML) return;
editor.getHTML().then((html) => {
onChange(html, editor);

View File

@@ -69,14 +69,16 @@ class NoteStore extends BaseStore {
};
delete = async (id) => {
await db.notes.delete(id);
this.refreshContext();
this.refresh();
appStore.refreshColors();
const { session } = editorStore.get();
if (session.id === id) {
hashNavigate("/notes/create", { addNonce: true });
const { session, clearSession } = editorStore.get();
if (session && session.id === id) {
await clearSession();
}
await db.notes.delete(id);
this.refresh();
appStore.refreshMenuPins();
appStore.refreshColors();
};
pin = async (id) => {