Skip to content

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

web: fix all tests & improve notebook/topic deletion

Abdullah Atta765fcafc38d9
diff --git a/apps/web/__e2e__/models/app.model.ts b/apps/web/__e2e__/models/app.model.ts
index dc8283de8..92c86f37e 100644
--- a/apps/web/__e2e__/models/app.model.ts
+++ b/apps/web/__e2e__/models/app.model.ts
@@ -132,7 +132,7 @@ export class AppModel {
.waitFor({ state: "visible" });
}
- async search(query: string) {
+ async search(query: string, type: string) {
const searchinput = this.page.locator(getTestId("search-input"));
const searchButton = this.page.locator(getTestId("search-button"));
const openSearch = this.page.locator(getTestId("open-search"));
@@ -140,6 +140,6 @@ export class AppModel {
await openSearch.click();
await searchinput.fill(query);
await searchButton.click();
- return new SearchViewModel(this.page);
+ return new SearchViewModel(this.page, type);
}
}
diff --git a/apps/web/__e2e__/models/base-view.model.ts b/apps/web/__e2e__/models/base-view.model.ts
index 4efacd346..676a0f3b6 100644
--- a/apps/web/__e2e__/models/base-view.model.ts
+++ b/apps/web/__e2e__/models/base-view.model.ts
@@ -29,14 +29,17 @@ export class BaseViewModel {
private readonly listPlaceholder: Locator;
private readonly sortByButton: Locator;
- constructor(page: Page, pageId: string) {
+ constructor(page: Page, pageId: string, listType: string) {
this.page = page;
- this.list = page.locator(`#${pageId} >> ${getTestId("note-list")}`);
+ this.list = page.locator(`#${pageId} >> ${getTestId(`${listType}-list`)}`);
this.listPlaceholder = page.locator(
`#${pageId} >> ${getTestId("list-placeholder")}`
);
- this.sortByButton = this.list.locator(getTestId("sort-icon-button"));
+ this.sortByButton = this.page.locator(
+ // TODO:
+ getTestId(`${pageId === "notebook" ? "notes" : pageId}-sort-button`)
+ );
}
async findGroup(groupName: string) {
@@ -103,13 +106,15 @@ export class BaseViewModel {
async sort(sort: SortOptions) {
const contextMenu: ContextMenuModel = new ContextMenuModel(this.page);
- await contextMenu.open(this.sortByButton, "left");
- await contextMenu.clickOnItem("groupBy");
- if (!(await contextMenu.hasItem(sort.groupBy))) {
- await contextMenu.close();
- return false;
+ if (sort.groupBy) {
+ await contextMenu.open(this.sortByButton, "left");
+ await contextMenu.clickOnItem("groupBy");
+ if (!(await contextMenu.hasItem(sort.groupBy))) {
+ await contextMenu.close();
+ return false;
+ }
+ await contextMenu.clickOnItem(sort.groupBy);
}
- await contextMenu.clickOnItem(sort.groupBy);
await contextMenu.open(this.sortByButton, "left");
await contextMenu.clickOnItem("sortDirection");
@@ -131,7 +136,10 @@ export class BaseViewModel {
}
async isEmpty() {
- const totalItems = await this.list.locator(getTestId("list-item")).count();
+ const items = this.list.locator(
+ `${getTestId(`virtuoso-item-list`)} >> ${getTestId("list-item")}`
+ );
+ const totalItems = await items.count();
return totalItems <= 0;
}
}
diff --git a/apps/web/__e2e__/models/item.model.ts b/apps/web/__e2e__/models/item.model.ts
index dd51608e4..3b9371abd 100644
--- a/apps/web/__e2e__/models/item.model.ts
+++ b/apps/web/__e2e__/models/item.model.ts
@@ -22,18 +22,21 @@ import { BaseItemModel } from "./base-item.model";
import { ContextMenuModel } from "./context-menu.model";
import { NotesViewModel } from "./notes-view.model";
import { Item } from "./types";
-import { confirmDialog, denyDialog, fillItemDialog } from "./utils";
+import { confirmDialog, fillItemDialog } from "./utils";
export class ItemModel extends BaseItemModel {
private readonly contextMenu: ContextMenuModel;
- constructor(locator: Locator) {
+ constructor(locator: Locator, private readonly id: "topic" | "tag") {
super(locator);
this.contextMenu = new ContextMenuModel(this.page);
}
async open() {
await this.locator.click();
- return new NotesViewModel(this.page, "notes");
+ return new NotesViewModel(
+ this.page,
+ this.id === "topic" ? "notebook" : "notes"
+ );
}
async delete() {
@@ -47,9 +50,10 @@ export class ItemModel extends BaseItemModel {
await this.contextMenu.open(this.locator);
await this.contextMenu.clickOnItem("delete");
- if (deleteContainedNotes) await confirmDialog(this.page);
- else await denyDialog(this.page);
+ if (deleteContainedNotes)
+ await this.page.locator("#deleteContainingNotes").check({ force: true });
+ await confirmDialog(this.page);
await this.waitFor("detached");
}
diff --git a/apps/web/__e2e__/models/items-view.model.ts b/apps/web/__e2e__/models/items-view.model.ts
index 071899a83..91c696472 100644
--- a/apps/web/__e2e__/models/items-view.model.ts
+++ b/apps/web/__e2e__/models/items-view.model.ts
@@ -28,7 +28,7 @@ export class ItemsViewModel extends BaseViewModel {
private readonly createButton: Locator;
constructor(page: Page, private readonly id: "topics" | "tags") {
- super(page, id);
+ super(page, id, id);
this.createButton = page.locator(getTestId(`${id}-action-button`));
}
@@ -45,7 +45,11 @@ export class ItemsViewModel extends BaseViewModel {
async findItem(item: Item) {
const titleToCompare = this.id === "tags" ? `#${item.title}` : item.title;
for await (const _item of this.iterateItems()) {
- const itemModel = new ItemModel(_item);
+ const itemModel = new ItemModel(
+ _item,
+ // TODO:
+ this.id === "topics" ? "topic" : "tag"
+ );
const title = await itemModel.getTitle();
if (title === titleToCompare) return itemModel;
}
diff --git a/apps/web/__e2e__/models/notebook-item.model.ts b/apps/web/__e2e__/models/notebook-item.model.ts
index 82d3cc305..288d2b7eb 100644
--- a/apps/web/__e2e__/models/notebook-item.model.ts
+++ b/apps/web/__e2e__/models/notebook-item.model.ts
@@ -23,7 +23,8 @@ import { ContextMenuModel } from "./context-menu.model";
import { ToggleModel } from "./toggle.model";
import { ItemsViewModel } from "./items-view.model";
import { Notebook } from "./types";
-import { confirmDialog, denyDialog, fillNotebookDialog } from "./utils";
+import { confirmDialog, fillNotebookDialog } from "./utils";
+import { NotesViewModel } from "./notes-view.model";
export class NotebookItemModel extends BaseItemModel {
private readonly contextMenu: ContextMenuModel;
@@ -34,7 +35,10 @@ export class NotebookItemModel extends BaseItemModel {
async openNotebook() {
await this.locator.click();
- return new ItemsViewModel(this.page, "topics");
+ return {
+ topics: new ItemsViewModel(this.page, "topics"),
+ notes: new NotesViewModel(this.page, "notebook")
+ };
}
async editNotebook(notebook: Notebook) {
@@ -48,9 +52,10 @@ export class NotebookItemModel extends BaseItemModel {
await this.contextMenu.open(this.locator);
await this.contextMenu.clickOnItem("movetotrash");
- if (deleteContainedNotes) await confirmDialog(this.page);
- else await denyDialog(this.page);
+ if (deleteContainedNotes)
+ await this.page.locator("#deleteContainingNotes").check({ force: true });
+ await confirmDialog(this.page);
await this.waitFor("detached");
}
diff --git a/apps/web/__e2e__/models/notebooks-view.model.ts b/apps/web/__e2e__/models/notebooks-view.model.ts
index 145841734..0367149b4 100644
--- a/apps/web/__e2e__/models/notebooks-view.model.ts
+++ b/apps/web/__e2e__/models/notebooks-view.model.ts
@@ -28,7 +28,7 @@ export class NotebooksViewModel extends BaseViewModel {
private readonly createButton: Locator;
constructor(page: Page) {
- super(page, "notebooks");
+ super(page, "notebooks", "notebooks");
this.createButton = page
.locator(getTestId("notebooks-action-button"))
.first();
diff --git a/apps/web/__e2e__/models/notes-view.model.ts b/apps/web/__e2e__/models/notes-view.model.ts
index ae90ba1f3..9fc671fc1 100644
--- a/apps/web/__e2e__/models/notes-view.model.ts
+++ b/apps/web/__e2e__/models/notes-view.model.ts
@@ -32,9 +32,12 @@ export class NotesViewModel extends BaseViewModel {
private readonly createButton: Locator;
readonly editor: EditorModel;
- constructor(page: Page, pageId: "home" | "notes") {
- super(page, pageId);
- this.createButton = page.locator(getTestId("notes-action-button"));
+ constructor(page: Page, pageId: "home" | "notes" | "notebook") {
+ super(page, pageId, pageId === "home" ? "home" : "notes");
+ this.createButton = page.locator(
+ // TODO:
+ getTestId(`${pageId === "notebook" ? "notebook" : "notes"}-action-button`)
+ );
this.editor = new EditorModel(page);
}
diff --git a/apps/web/__e2e__/models/reminders-view.model.ts b/apps/web/__e2e__/models/reminders-view.model.ts
index 61a61704a..4585b7abf 100644
--- a/apps/web/__e2e__/models/reminders-view.model.ts
+++ b/apps/web/__e2e__/models/reminders-view.model.ts
@@ -28,7 +28,7 @@ export class RemindersViewModel extends BaseViewModel {
private readonly createButton: Locator;
constructor(page: Page) {
- super(page, "reminders");
+ super(page, "reminders", "reminders");
this.createButton = page
.locator(getTestId("reminders-action-button"))
.first();
diff --git a/apps/web/__e2e__/models/search-view-model.ts b/apps/web/__e2e__/models/search-view-model.ts
index c50576803..120cc5617 100644
--- a/apps/web/__e2e__/models/search-view-model.ts
+++ b/apps/web/__e2e__/models/search-view-model.ts
@@ -23,8 +23,8 @@ import { ItemModel } from "./item.model";
import { Item } from "./types";
export class SearchViewModel extends BaseViewModel {
- constructor(page: Page) {
- super(page, "general");
+ constructor(page: Page, type: string) {
+ super(page, "general", type);
}
async findItem(item: Item) {
diff --git a/apps/web/__e2e__/models/trash-view.model.ts b/apps/web/__e2e__/models/trash-view.model.ts
index ab7be6eaf..06388e0a8 100644
--- a/apps/web/__e2e__/models/trash-view.model.ts
+++ b/apps/web/__e2e__/models/trash-view.model.ts
@@ -24,7 +24,7 @@ import { TrashItemModel } from "./trash-item.model";
export class TrashViewModel extends BaseViewModel {
constructor(page: Page) {
- super(page, "trash");
+ super(page, "trash", "trash");
}
async findItem(title: string) {
diff --git a/apps/web/__e2e__/models/types.ts b/apps/web/__e2e__/models/types.ts
index 355e9e3a0..eb8520681 100644
--- a/apps/web/__e2e__/models/types.ts
+++ b/apps/web/__e2e__/models/types.ts
@@ -45,7 +45,7 @@ export type GroupByOptions =
| "week";
export type SortOptions = {
- groupBy: GroupByOptions;
+ groupBy?: GroupByOptions;
sortBy: SortByOptions;
orderBy: OrderByOptions;
};
diff --git a/apps/web/__e2e__/notebooks.test.ts b/apps/web/__e2e__/notebooks.test.ts
index c4c460035..353b1047e 100644
--- a/apps/web/__e2e__/notebooks.test.ts
+++ b/apps/web/__e2e__/notebooks.test.ts
@@ -43,7 +43,19 @@ test("create a note inside a notebook", async ({ page }) => {
await app.goto();
const notebooks = await app.goToNotebooks();
const notebook = await notebooks.createNotebook(NOTEBOOK);
- const topics = await notebook?.openNotebook();
+ const { notes } = (await notebook?.openNotebook()) || {};
+
+ const note = await notes?.createNote(NOTE);
+
+ expect(note).toBeDefined();
+});
+
+test("create a note inside a topic", async ({ page }) => {
+ const app = new AppModel(page);
+ await app.goto();
+ const notebooks = await app.goToNotebooks();
+ const notebook = await notebooks.createNotebook(NOTEBOOK);
+ const { topics } = (await notebook?.openNotebook()) || {};
const topic = await topics?.findItem({ title: NOTEBOOK.topics[0] });
const notes = await topic?.open();
@@ -170,7 +182,27 @@ test("delete all notes within a notebook", async ({ page }) => {
await app.goto();
const notebooks = await app.goToNotebooks();
const notebook = await notebooks.createNotebook(NOTEBOOK);
- const topics = await notebook?.openNotebook();
+ let { notes } = (await notebook?.openNotebook()) || {};
+ for (let i = 0; i < 2; ++i) {
+ await notes?.createNote({
+ title: `Note ${i}`,
+ content: NOTE.content
+ });
+ }
+ await app.goBack();
+
+ await notebook?.moveToTrash(true);
+
+ notes = await app.goToNotes();
+ expect(await notes.isEmpty()).toBe(true);
+});
+
+test("delete all notes within a topic", async ({ page }) => {
+ const app = new AppModel(page);
+ await app.goto();
+ const notebooks = await app.goToNotebooks();
+ const notebook = await notebooks.createNotebook(NOTEBOOK);
+ const { topics } = (await notebook?.openNotebook()) || {};
const topic = await topics?.findItem({ title: NOTEBOOK.topics[0] });
let notes = await topic?.open();
for (let i = 0; i < 2; ++i) {
diff --git a/apps/web/__e2e__/notes.test.ts b/apps/web/__e2e__/notes.test.ts
index 7aa5fe7d4..3d6d8c2fc 100644
--- a/apps/web/__e2e__/notes.test.ts
+++ b/apps/web/__e2e__/notes.test.ts
@@ -96,9 +96,7 @@ test("add a note to notebook", async ({ page }) => {
});
expect(
- await app.toasts.waitForToast(
- "1 note added to 4 topics & removed from 0 topics."
- )
+ await app.toasts.waitForToast("1 note added to Hello and 3 others.")
).toBe(true);
});
diff --git a/apps/web/__e2e__/topics.test.ts b/apps/web/__e2e__/topics.test.ts
index 7b30ff6eb..9fdeb2f6b 100644
--- a/apps/web/__e2e__/topics.test.ts
+++ b/apps/web/__e2e__/topics.test.ts
@@ -20,20 +20,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import { test, expect } from "@playwright/test";
import { AppModel } from "./models/app.model";
import { Item } from "./models/types";
-import {
- groupByOptions,
- NOTEBOOK,
- sortByOptions,
- orderByOptions,
- NOTE
-} from "./utils";
+import { NOTEBOOK, sortByOptions, orderByOptions, NOTE } from "./utils";
test("create shortcut of a topic", async ({ page }) => {
const app = new AppModel(page);
await app.goto();
const notebooks = await app.goToNotebooks();
const notebook = await notebooks.createNotebook(NOTEBOOK);
- const topics = await notebook?.openNotebook();
+ const { topics } = (await notebook?.openNotebook()) || {};
const topic = await topics?.findItem({ title: NOTEBOOK.topics[0] });
await topic?.createShortcut();
@@ -48,7 +42,7 @@ test("remove shortcut of a topic", async ({ page }) => {
await app.goto();
const notebooks = await app.goToNotebooks();
const notebook = await notebooks.createNotebook(NOTEBOOK);
- const topics = await notebook?.openNotebook();
+ const { topics } = (await notebook?.openNotebook()) || {};
const topic = await topics?.findItem({ title: NOTEBOOK.topics[0] });
await topic?.createShortcut();
@@ -64,7 +58,7 @@ test("delete a topic", async ({ page }) => {
await app.goto();
const notebooks = await app.goToNotebooks();
const notebook = await notebooks.createNotebook(NOTEBOOK);
- const topics = await notebook?.openNotebook();
+ const { topics } = (await notebook?.openNotebook()) || {};
const topic = await topics?.findItem({ title: NOTEBOOK.topics[0] });
await topic?.deleteWithNotes();
@@ -78,7 +72,7 @@ test("edit topics individually", async ({ page }) => {
await app.goto();
const notebooks = await app.goToNotebooks();
const notebook = await notebooks.createNotebook(NOTEBOOK);
- const topics = await notebook?.openNotebook();
+ const { topics } = (await notebook?.openNotebook()) || {};
const editedTopics: Item[] = [];
for (const title of NOTEBOOK.topics) {
@@ -98,7 +92,7 @@ test("delete all notes within a topic", async ({ page }) => {
await app.goto();
const notebooks = await app.goToNotebooks();
const notebook = await notebooks.createNotebook(NOTEBOOK);
- const topics = await notebook?.openNotebook();
+ const { topics } = (await notebook?.openNotebook()) || {};
const topic = await topics?.findItem({ title: NOTEBOOK.topics[0] });
let notes = await topic?.open();
for (let i = 0; i < 2; ++i) {
@@ -116,7 +110,7 @@ test("delete all notes within a topic", async ({ page }) => {
});
test(`sort topics`, async ({ page }, info) => {
- info.setTimeout(2 * 60 * 1000);
+ info.setTimeout(1 * 60 * 1000);
const app = new AppModel(page);
await app.goto();
@@ -125,27 +119,24 @@ test(`sort topics`, async ({ page }, info) => {
...NOTEBOOK,
topics: ["title1", "title2", "title3", "title4", "title5"]
});
- const topics = await notebook?.openNotebook();
-
- for (const groupBy of groupByOptions) {
- for (const sortBy of sortByOptions) {
- for (const orderBy of orderByOptions) {
- await test.step(`group by ${groupBy}, sort by ${sortBy}, order by ${orderBy}`, async () => {
- const sortResult = await topics?.sort({
- groupBy,
- orderBy,
- sortBy
- });
- if (!sortResult) return;
-
- expect(await topics?.isEmpty()).toBeFalsy();
+ const { topics } = (await notebook?.openNotebook()) || {};
+
+ for (const sortBy of sortByOptions) {
+ for (const orderBy of orderByOptions) {
+ await test.step(`sort by ${sortBy}, order by ${orderBy}`, async () => {
+ const sortResult = await topics?.sort({
+ orderBy,
+ sortBy
});
- }
+ if (!sortResult) return;
+
+ expect(await topics?.isEmpty()).toBeFalsy();
+ });
}
}
});
-test("search topics", async ({ page }) => {
+test.skip("search topics", async ({ page }) => {
const app = new AppModel(page);
await app.goto();
const notebooks = await app.goToNotebooks();
@@ -155,7 +146,7 @@ test("search topics", async ({ page }) => {
});
await notebook?.openNotebook();
- const search = await app.search("1");
+ const search = await app.search("1", "topics");
const topic = await search?.findItem({ title: "title1" });
expect((await topic?.getTitle()) === "title1").toBeTruthy();
diff --git a/apps/web/src/assets/note2.svg b/apps/web/src/assets/note2.svg
new file mode 100644
index 000000000..f1c1fa674
--- /dev/null
+++ b/apps/web/src/assets/note2.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" data-name="Layer 1" viewBox="0 0 485.83 483.5"><path fill="#e6e6e6" d="M320.46 128.1h-79.74a11.48 11.48 0 0 1-9.07-4.4 11.62 11.62 0 0 1-2.17-9.96 201.63 201.63 0 0 0 0-93.65 11.62 11.62 0 0 1 2.17-9.97 11.48 11.48 0 0 1 9.07-4.4h79.74a11.62 11.62 0 0 1 11.44 9.76 337.96 337.96 0 0 1 0 102.86 11.62 11.62 0 0 1-11.44 9.76Z"/><path fill="#fff" d="M240.72 11.73a5.51 5.51 0 0 0-4.36 2.1 5.66 5.66 0 0 0-1.05 4.86 207.66 207.66 0 0 1 0 96.45 5.66 5.66 0 0 0 1.05 4.85 5.51 5.51 0 0 0 4.36 2.1h79.74a5.58 5.58 0 0 0 5.5-4.66 331.99 331.99 0 0 0 0-101.04 5.58 5.58 0 0 0-5.5-4.66Z"/><path fill="#e6e6e6" d="M303.06 40.58H261.2a6 6 0 0 1-6-6v-2.35a6 6 0 0 1 6-6h41.85a6 6 0 0 1 6 6v2.35a6 6 0 0 1-6 6Zm0 29.62H261.2a6 6 0 0 1-6-6v-2.34a6 6 0 0 1 6-6h41.85a6 6 0 0 1 6 6v2.34a6 6 0 0 1-6 6Zm0 29.63H261.2a6 6 0 0 1-6-6V91.5a6 6 0 0 1 6-6h41.85a6 6 0 0 1 6 6v2.34a6 6 0 0 1-6 6Zm167.4 104.27h-79.74a11.48 11.48 0 0 1-9.07-4.4 11.62 11.62 0 0 1-2.17-9.96 201.63 201.63 0 0 0 0-93.65 11.62 11.62 0 0 1 2.17-9.97 11.48 11.48 0 0 1 9.07-4.4h79.74a11.62 11.62 0 0 1 11.44 9.76 337.96 337.96 0 0 1 0 102.86 11.62 11.62 0 0 1-11.44 9.76Z"/><path fill="#fff" d="M390.72 87.73a5.51 5.51 0 0 0-4.36 2.1 5.66 5.66 0 0 0-1.05 4.86 207.66 207.66 0 0 1 0 96.45 5.66 5.66 0 0 0 1.05 4.85 5.51 5.51 0 0 0 4.36 2.1h79.74a5.58 5.58 0 0 0 5.5-4.66 331.99 331.99 0 0 0 0-101.04 5.58 5.58 0 0 0-5.5-4.66Z"/><path fill="#f2f2f2" d="M311.46 290.6h-79.74a11.98 11.98 0 0 1-9.46-4.59 12.12 12.12 0 0 1-2.27-10.4 201.13 201.13 0 0 0 0-93.4 12.12 12.12 0 0 1 2.27-10.4 11.98 11.98 0 0 1 9.46-4.58h79.74a12.13 12.13 0 0 1 11.93 10.18 338.46 338.46 0 0 1 0 103 12.13 12.13 0 0 1-11.93 10.19Z"/><path fill="#e6e6e6" d="M453.06 131.58H411.2a6 6 0 0 1-6-6v-2.35a6 6 0 0 1 6-6h41.85a6 6 0 0 1 6 6v2.35a6 6 0 0 1-6 6Zm0 29.62H411.2a6 6 0 0 1-6-6v-2.34a6 6 0 0 1 6-6h41.85a6 6 0 0 1 6 6v2.34a6 6 0 0 1-6 6Z"/><circle cx="271.81" cy="228.5" r="23" fill="#fff"/><path fill="#e6e6e6" d="M282.81 225.5h-8v-8a3 3 0 0 0-6 0v8h-8a3 3 0 0 0 0 6h8v8a3 3 0 0 0 6 0v-8h8a3 3 0 0 0 0-6Z"/><path fill="#ccc" d="M300.81 17h-42a4.5 4.5 0 0 1-4.5-4.5v-8a4.5 4.5 0 0 1 4.5-4.5h42a4.5 4.5 0 0 1 4.5 4.5v8a4.5 4.5 0 0 1-4.5 4.5Zm152 77h-42a4.5 4.5 0 0 1-4.5-4.5v-8a4.5 4.5 0 0 1 4.5-4.5h42a4.5 4.5 0 0 1 4.5 4.5v8a4.5 4.5 0 0 1-4.5 4.5Z"/><path fill="#ffb8b8" d="M88.6 471.06h12.26l3.83-47.29h-16.1l.01 47.29z"/><path fill="#2f2e41" d="M85.47 467.06h24.14A15.39 15.39 0 0 1 125 482.44v.5H85.47Z"/><path fill="#ffb8b8" d="M22.6 471.06h12.26l5.83-47.29h-18.1l.01 47.29z"/><path fill="#2f2e41" d="M19.47 467.06H43.6A15.39 15.39 0 0 1 59 482.44v.5H19.47Zm5.3-10.94a4.98 4.98 0 0 1-3.37-1.32 4.96 4.96 0 0 1-1.62-3.53l-4.92-176.22 69.82 17.46 21.53 64.61a70.46 70.46 0 0 1 3.55 25.83l-2.67 62.63a5 5 0 0 1-5 4.76H90.4a5.02 5.02 0 0 1-4.96-4.33l-8.37-69.14a37.82 37.82 0 0 0-5.53-15.16l-16.47-26.08a1 1 0 0 0-1.84.41L40.29 451.13a5 5 0 0 1-4.68 4.4l-10.55.58-.29.01Z"/><circle cx="73.06" cy="136.41" r="24.56" fill="#ffb8b8"/><path fill="#e5e5e5" d="M84.34 299.67a5.08 5.08 0 0 1-1.25-.16l-69.27-17.76a5 5 0 0 1-3.66-5.81l15.9-85.7a31.21 31.21 0 0 1 18.26-22.53 30.11 30.11 0 0 1 28.26 2.07c.97.6 1.95 1.27 2.9 1.96a30.96 30.96 0 0 1 12.58 24.53l1.27 98.33a5 5 0 0 1-4.99 5.07Z"/><path fill="#ffb8b8" d="M20.95 300.68a10.06 10.06 0 0 1 4.21-14.83l-3.08-35.6 16.33 8.84.42 32.46a10.11 10.11 0 0 1-17.88 9.13Z"/><path fill="#e5e5e5" d="M26.78 281.14a5.53 5.53 0 0 1-1.36-.17 5.5 5.5 0 0 1-3.98-3.99l-8.02-31.88a47.37 47.37 0 0 1 3.76-33.14L34 179.08a15.54 15.54 0 0 1 18.8-11.02 15.36 15.36 0 0 1 9.48 7.1 15.57 15.57 0 0 1 1.66 11.91L40 240.58l.28 32.04a5.52 5.52 0 0 1-3.58 5.2l-8 2.97a5.48 5.48 0 0 1-1.92.35Z"/><path fill="#ffb8b8" d="M141.32 287.58a10.06 10.06 0 0 1-8.5-12.86l-28.99-20.9 17.36-6.6 24.87 20.85a10.11 10.11 0 0 1-4.74 19.51Z"/><path fill="#e5e5e5" d="M126.14 272.33a5.52 5.52 0 0 1-2.46-.58l-29.4-14.72a47.38 47.38 0 0 1-22.66-24.46l-13.96-34.2a15.54 15.54 0 0 1 3.92-21.44 15.35 15.35 0 0 1 11.59-2.54 15.57 15.57 0 0 1 10.08 6.51l24.94 53.04 24.47 20.68a5.52 5.52 0 0 1 1.6 6.11l-2.96 8.01a5.47 5.47 0 0 1-2.01 2.6 5.5 5.5 0 0 1-3.15 1Z"/><path fill="#2f2e41" d="M67.9 161.34c1.3.57 3.98-9.82 2.78-11.9-1.78-3.1-1.67-3.07-2.86-5.12s-1.44-4.85.09-6.65 5.07-1.56 5.77.7c-.45-4.3 3.79-7.74 8-8.7s8.62-.37 12.85-1.24c4.9-1 10-5.1 8.05-10.5a7.6 7.6 0 0 0-1.49-2.43c-2.26-2.54-5.42-3.63-8.5-4.67-6.44-2.19-13.04-4.4-19.83-4.16a28.8 28.8 0 0 0-25.45 18.61 26.16 26.16 0 0 0-1.08 4.03c-2.33 12.52 4.94 24.88 16.76 29.65Z"/><path d="m38.9 273.34.56-32.93 17.44-35.07-14 36-4 32z" opacity=".2"/><path fill="#e6e6e6" d="m197.08 355.98-73.64-30.6a11.48 11.48 0 0 1-6.69-7.53 11.62 11.62 0 0 1 1.82-10.04 201.63 201.63 0 0 0 35.93-86.48 11.62 11.62 0 0 1 5.83-8.37 11.48 11.48 0 0 1 10.06-.58l73.64 30.6a11.62 11.62 0 0 1 6.82 13.4 337.96 337.96 0 0 1-39.47 94.98 11.62 11.62 0 0 1-14.3 4.62Z"/><path fill="#fff" d="M168.09 217.92a5.51 5.51 0 0 0-4.83.28 5.66 5.66 0 0 0-2.84 4.08 207.66 207.66 0 0 1-37 89.06 5.66 5.66 0 0 0-.9 4.89 5.51 5.51 0 0 0 3.22 3.62l73.64 30.6a5.58 5.58 0 0 0 6.88-2.2 331.99 331.99 0 0 0 38.76-93.3 5.58 5.58 0 0 0-3.3-6.43Z"/><path fill="#e5e5e5" d="m207.3 286.03-38.65-16.05a6 6 0 0 1-3.23-7.85l.9-2.16a6 6 0 0 1 7.84-3.24l38.64 16.06a6 6 0 0 1 3.24 7.84l-.9 2.16a6 6 0 0 1-7.84 3.24Zm-11.37 27.36-38.64-16.06a6 6 0 0 1-3.24-7.84l.9-2.16a6 6 0 0 1 7.84-3.24l38.64 16.05a6 6 0 0 1 3.24 7.85l-.9 2.16a6 6 0 0 1-7.84 3.24Z"/><path fill="#ccc" d="M222.78 247.58a4.49 4.49 0 0 1-1.69-.33l-38.93-15.74a4.5 4.5 0 0 1-2.49-5.86l3-7.42a4.5 4.5 0 0 1 5.86-2.48l38.94 15.74a4.5 4.5 0 0 1 2.48 5.86l-3 7.42a4.51 4.51 0 0 1-4.17 2.81ZM141 483.5H1a1 1 0 1 1 0-2h140a1 1 0 0 1 0 2Z"/></svg>
\ No newline at end of file
diff --git a/apps/web/src/common/dialog-controller.tsx b/apps/web/src/common/dialog-controller.tsx
index cfe7a5d3f..7e37a145f 100644
--- a/apps/web/src/common/dialog-controller.tsx
+++ b/apps/web/src/common/dialog-controller.tsx
@@ -19,7 +19,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import ReactDOM from "react-dom";
import { Dialogs } from "../components/dialogs";
-import { hardNavigate } from "../navigation";
import ThemeProvider from "../components/theme-provider";
import qclone from "qclone";
import { store as notebookStore } from "../stores/notebook-store";
@@ -29,7 +28,7 @@ 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 "@theme-ui/components";
+import { Text } from "@theme-ui/components";
import * as Icon from "../components/icons";
import Config from "../utils/config";
import { formatDate } from "@notesnook/core/utils/date";
@@ -41,10 +40,11 @@ import { FeatureKeys } from "../components/dialogs/feature-dialog";
import { AuthenticatorType } from "../components/dialogs/mfa/types";
import { Suspense } from "react";
import { Reminder } from "@notesnook/core/collections/reminders";
+import { ConfirmDialogProps } from "../components/dialogs/confirm";
type DialogTypes = typeof Dialogs;
type DialogIds = keyof DialogTypes;
-export type Perform = (result: boolean) => void;
+export type Perform<T = boolean> = (result: T) => void;
type RenderDialog<TId extends DialogIds, TReturnType> = (
dialog: DialogTypes[TId],
perform: (result: TReturnType) => void
@@ -154,26 +154,15 @@ export function showBuyDialog(plan?: Period, couponCode?: string) {
));
}
-type ConfirmDialogProps = {
- title?: string;
- subtitle?: string;
- message?: string | JSX.Element;
- yesText?: string;
- noText?: string;
- yesAction?: () => void;
- width?: string;
-};
-export function confirm(props: ConfirmDialogProps) {
- return showDialog("Confirm", (Dialog, perform) => (
- <Dialog
- {...props}
- onNo={() => perform(false)}
- onYes={() => {
- if (props.yesAction) props.yesAction();
- perform(true);
- }}
- />
- ));
+export function confirm<TCheckId extends string>(
+ props: Omit<ConfirmDialogProps<TCheckId>, "onClose">
+) {
+ return showDialog<"Confirm", false | Record<TCheckId, boolean>>(
+ "Confirm",
+ (Dialog, perform) => (
+ <Dialog {...props} onClose={(result) => perform(result)} />
+ )
+ );
}
export function showPromptDialog(props: {
@@ -214,41 +203,26 @@ export function showToolbarConfigDialog() {
}
export function showError(title: string, message: string) {
- return confirm({ title, message, yesText: "Okay" });
+ return confirm({ title, message, positiveButtonText: "Okay" });
}
export function showMultiDeleteConfirmation(length: number) {
return confirm({
title: `Delete ${length} items?`,
- message: (
- <Text as="span">
- These items will be{" "}
- <Text as="span" sx={{ color: "primary" }}>
- kept in your Trash for 7 days
- </Text>{" "}
- after which they will be permanently removed.
- </Text>
- ),
- yesText: `Delete selected`,
- noText: "Cancel"
+ message:
+ "These items will be **kept in your Trash for 7 days** after which they will be permanently deleted.",
+ positiveButtonText: "Yes",
+ negativeButtonText: "No"
});
}
export function showMultiPermanentDeleteConfirmation(length: number) {
return confirm({
title: `Permanently delete ${length} items?`,
- message: (
- <Text as="span">
- These items will be{" "}
- <Text as="span" sx={{ color: "primary" }}>
- permanently deleted
- </Text>
- {". "}
- This action is IRREVERSIBLE.
- </Text>
- ),
- yesText: `Permanently delete selected`,
- noText: "Cancel"
+ message:
+ "These items will be **permanently deleted**. This is IRREVERSIBLE.",
+ positiveButtonText: "Yes",
+ negativeButtonText: "No"
});
}
@@ -257,8 +231,8 @@ export function showLogoutConfirmation() {
title: `Logout?`,
message:
"Logging out will delete all local data and reset the app. Make sure you have synced your data before logging out.",
- yesText: `Yes`,
- noText: "No"
+ positiveButtonText: "Yes",
+ negativeButtonText: "No"
});
}
@@ -267,8 +241,8 @@ export function showClearSessionsConfirmation() {
title: `Logout from other devices?`,
message:
"All other logged-in devices will be forced to logout stopping sync. Use with care lest you lose important notes.",
- yesText: `Yes`,
- noText: "No"
+ positiveButtonText: "Yes",
+ negativeButtonText: "No"
});
}
@@ -276,9 +250,7 @@ export function showAccountLoggedOutNotice(reason?: string) {
return confirm({
title: "You were logged out",
message: reason,
- noText: "Okay",
- yesText: `Relogin`,
- yesAction: () => hardNavigate("/login")
+ negativeButtonText: "Okay"
});
}
@@ -287,24 +259,13 @@ export function showAppUpdatedNotice(
) {
return confirm({
title: `Welcome to v${version.formatted}`,
- message: (
- <Flex
- bg="bgSecondary"
- p={1}
- sx={{ borderRadius: "default", flexDirection: "column" }}
- >
- <Text variant="title">Changelog:</Text>
- <Text
- as="pre"
- variant="body"
- mt={1}
- sx={{ fontFamily: "monospace", overflow: "auto" }}
- >
- {version.changelog || "No change log."}
- </Text>
- </Flex>
- ),
- yesText: `Yay!`
+ message: `## Changelog:
+
+\`\`\`
+${version.changelog || "No change log."}
+\`\`\`
+`,
+ positiveButtonText: `Continue`
});
}
@@ -706,32 +667,29 @@ export function showOnboardingDialog(type: string) {
));
}
-export function showInvalidSystemTimeDialog({
+export async function showInvalidSystemTimeDialog({
serverTime,
localTime
}: {
serverTime: number;
localTime: number;
}) {
- return confirm({
+ const result = await confirm({
title: "Your system clock is out of sync",
subtitle:
"Please correct your system date & time and reload the app to avoid syncing issues.",
- message: (
- <>
- Server time:{" "}
- {formatDate(serverTime, { dateStyle: "medium", timeStyle: "medium" })}
- <br />
- Local time:{" "}
- {formatDate(localTime, { dateStyle: "medium", timeStyle: "medium" })}
- <br />
- Please sync your system time with{" "}
- <a href="https://time.is">https://time.is/</a>.
- </>
- ),
- yesText: "Reload app",
- yesAction: () => window.location.reload()
+ message: `Server time: ${formatDate(serverTime, {
+ dateStyle: "medium",
+ timeStyle: "medium"
+ })}
+Local time: ${formatDate(localTime, {
+ dateStyle: "medium",
+ timeStyle: "medium"
+ })}
+Please sync your system time with [https://time.is](https://time.is).`,
+ positiveButtonText: "Reload app"
});
+ if (result) window.location.reload();
}
export async function showUpdateAvailableNotice({
@@ -771,37 +729,18 @@ type UpdateDialogProps = {
onClick: () => void;
};
};
-function showUpdateDialog({
+async function showUpdateDialog({
title,
subtitle,
changelog,
action
}: UpdateDialogProps) {
- return confirm({
+ const result = await confirm({
title,
subtitle,
- message: changelog && (
- <Flex sx={{ borderRadius: "default", flexDirection: "column" }}>
- <Text
- as="div"
- variant="body"
- sx={{ overflow: "auto", fontFamily: "body" }}
- css={`
- h2 {
- font-size: 1.2em;
- font-weight: 600;
- }
- h3 {
- font-size: 1em;
- font-weight: 600;
- }
- `}
- dangerouslySetInnerHTML={{ __html: changelog }}
- ></Text>
- </Flex>
- ),
- width: "500px",
- yesText: action.text,
- yesAction: action.onClick
+ message: changelog,
+ width: 500,
+ positiveButtonText: action.text
});
+ if (result && action.onClick) action.onClick();
}
diff --git a/apps/web/src/components/dialogs/confirm.js b/apps/web/src/components/dialogs/confirm.js
deleted file mode 100644
index fbb6b97ac..000000000
--- a/apps/web/src/components/dialogs/confirm.js
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
-This file is part of the Notesnook project (https://notesnook.com/)
-
-Copyright (C) 2023 Streetwriters (Private) Limited
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-import { Box, Text } from "@theme-ui/components";
-import Dialog from "./dialog";
-
-function Confirm(props) {
- return (
- <Dialog
- isOpen={true}
- title={props.title}
- icon={props.icon}
- width={props.width}
- description={props.subtitle}
- onClose={() => props.onNo(false)}
- positiveButton={
- props.yesText && {
- text: props.yesText,
- onClick: () => props.onYes(true),
- autoFocus: !!props.yesText
- }
- }
- negativeButton={
- props.noText && { text: props.noText, onClick: () => props.onNo(false) }
- }
- >
- <Box pb={!props.noText && !props.yesText ? 2 : 0}>
- <Text as="span" variant="body">
- {props.message}
- </Text>
- </Box>
- </Dialog>
- );
-}
-
-export default Confirm;
diff --git a/apps/web/src/components/dialogs/confirm.tsx b/apps/web/src/components/dialogs/confirm.tsx
new file mode 100644
index 000000000..d60f1dc91
--- /dev/null
+++ b/apps/web/src/components/dialogs/confirm.tsx
@@ -0,0 +1,120 @@
+/*
+This file is part of the Notesnook project (https://notesnook.com/)
+
+Copyright (C) 2023 Streetwriters (Private) Limited
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+import { Box, Checkbox, Label, Text } from "@theme-ui/components";
+import { useRef } from "react";
+import { Perform } from "../../common/dialog-controller";
+import { mdToHtml } from "../../utils/md";
+import Dialog from "./dialog";
+
+type Check = { text: string; default?: boolean };
+export type ConfirmDialogProps<TCheckId extends string> = {
+ title: string;
+ subtitle?: string;
+ onClose: Perform<false | Record<TCheckId, boolean>>;
+ width?: number;
+ positiveButtonText?: string;
+ negativeButtonText?: string;
+ message?: string;
+ checks?: Partial<Record<TCheckId, Check>>;
+};
+
+function ConfirmDialog<TCheckId extends string>(
+ props: ConfirmDialogProps<TCheckId>
+) {
+ const {
+ onClose,
+ title,
+ subtitle,
+ width,
+ negativeButtonText,
+ positiveButtonText,
+ message,
+ checks
+ } = props;
+ const checkedItems = useRef<Record<TCheckId, boolean>>({} as any);
+
+ return (
+ <Dialog
+ isOpen={true}
+ title={title}
+ width={width}
+ description={subtitle}
+ onClose={() => onClose(false)}
+ positiveButton={
+ positiveButtonText
+ ? {
+ text: positiveButtonText,
+ onClick: () => onClose(checkedItems.current),
+ autoFocus: !!positiveButtonText
+ }
+ : undefined
+ }
+ negativeButton={
+ negativeButtonText
+ ? {
+ text: negativeButtonText,
+ onClick: () => onClose(false)
+ }
+ : undefined
+ }
+ >
+ <Box
+ sx={{
+ pb: !negativeButtonText && !positiveButtonText ? 2 : 0,
+ p: { m: 0 }
+ }}
+ >
+ {message ? (
+ <Text
+ as="span"
+ variant="body"
+ dangerouslySetInnerHTML={{ __html: mdToHtml(message) }}
+ />
+ ) : null}
+ {checks
+ ? Object.entries<Check | undefined>(checks).map(
+ ([id, check]) =>
+ check && (
+ <Label
+ key={id}
+ id={id}
+ variant="text.body"
+ sx={{ alignItems: "center" }}
+ >
+ <Checkbox
+ name={id}
+ defaultChecked={check.default}
+ sx={{ mr: "small", width: 18, height: 18 }}
+ onChange={(e) =>
+ (checkedItems.current[id as TCheckId] =
+ e.currentTarget.checked)
+ }
+ />
+ {check.text}{" "}
+ </Label>
+ )
+ )
+ : null}
+ </Box>
+ </Dialog>
+ );
+}
+
+export default ConfirmDialog;
diff --git a/apps/web/src/components/dialogs/issue-dialog.tsx b/apps/web/src/components/dialogs/issue-dialog.tsx
index 7eddd259f..6c6a44d13 100644
--- a/apps/web/src/components/dialogs/issue-dialog.tsx
+++ b/apps/web/src/components/dialogs/issue-dialog.tsx
@@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-import { Flex, Link, Text } from "@theme-ui/components";
+import { Flex, Text } from "@theme-ui/components";
import { appVersion } from "../../utils/version";
import Field from "../field";
import Dialog from "./dialog";
@@ -152,33 +152,14 @@ export default IssueDialog;
function showIssueReportedDialog({ url }: { url: string }) {
return confirm({
title: "Thank you for reporting!",
- yesAction: () => clipboard.writeText(url),
- yesText: "Copy link",
- message: (
- <>
- <p>
- You can track your bug report at{" "}
- <Link target="_blank" href={url} sx={{ lineBreak: "anywhere" }}>
- {url}
- </Link>
- .
- </p>
- <p>
- Please note that we will respond to your bug report on the link above.{" "}
- <b>
- We recommended that you save the above link for later reference.
- </b>
- </p>
- <p>
- If your issue is critical (e.g. notes not syncing, crashes etc.),
- please{" "}
- <a href="https://discord.com/invite/zQBK97EE22">
- join our Discord community
- </a>{" "}
- for one-to-one support.
- </p>
- </>
- )
+ positiveButtonText: "Copy link",
+ message: `You can track your bug report at [${url}](${url}).
+
+ Please note that we will respond to your bug report on the link above. **We recommended that you save the above link for later reference.**
+
+ If your issue is critical (e.g. notes not syncing, crashes etc.), please [join our Discord community](https://discord.com/invite/zQBK97EE22) for one-to-one support.`
+ }).then((result) => {
+ result && clipboard.writeText(url);
});
}
diff --git a/apps/web/src/components/dialogs/move-note-dialog.tsx b/apps/web/src/components/dialogs/move-note-dialog.tsx
index 46b715df6..440fbd05c 100644
--- a/apps/web/src/components/dialogs/move-note-dialog.tsx
+++ b/apps/web/src/components/dialogs/move-note-dialog.tsx
@@ -145,7 +145,9 @@ function MoveDialog({ onClose, noteIds }: MoveDialogProps) {
if (stringified) {
showToast(
"success",
- stringified.replace("Add", "Added").replace("remove", "removed")
+ `${pluralize(noteIds.length, "note", "notes")} ${stringified
+ .replace("Add", "added")
+ .replace("remove", "removed")}`
);
}
@@ -635,12 +637,12 @@ function stringifySelected(suggestion: NotebookReference[]) {
if (added.length > 1) parts.push(`and ${added.length - 1} others`);
if (removed.length >= 1) {
- parts.push("remove from");
+ parts.push("& remove from");
parts.push(removed[0]);
}
if (removed.length > 1) parts.push(`and ${removed.length - 1} others`);
- return parts.join(" ");
+ return parts.join(" ") + ".";
}
function resolve(ref: NotebookReference) {
diff --git a/apps/web/src/components/group-header/index.js b/apps/web/src/components/group-header/index.js
index e4d124390..3c113d99e 100644
--- a/apps/web/src/components/group-header/index.js
+++ b/apps/web/src/components/group-header/index.js
@@ -21,7 +21,7 @@ import * as Icon from "../icons";
import { useEffect, useMemo, useRef, useState } from "react";
import { Button, Flex, Text } from "@theme-ui/components";
import { db } from "../../common/db";
-import { useMenuTrigger } from "../../hooks/use-menu";
+import { Menu, useMenuTrigger } from "../../hooks/use-menu";
import { useStore as useNoteStore } from "../../stores/note-store";
import { useStore as useNotebookStore } from "../../stores/notebook-store";
import useMobile from "../../hooks/use-mobile";
@@ -36,84 +36,97 @@ const groupByToTitleMap = {
month: "Month"
};
-const menuItems = [
- {
- key: "sortDirection",
- title: "Order by",
- icon: ({ groupOptions }) =>
- groupOptions.sortDirection === "asc"
- ? groupOptions.sortBy === "title"
- ? Icon.OrderAtoZ
- : Icon.OrderOldestNewest
- : groupOptions.sortBy === "title"
- ? Icon.OrderZtoA
- : Icon.OrderNewestOldest,
- items: map([
- {
- key: "asc",
- title: ({ groupOptions }) =>
- groupOptions.sortBy === "title" ? "A - Z" : "Oldest - newest"
- },
- {
- key: "desc",
- title: ({ groupOptions }) =>
- groupOptions.sortBy === "title" ? "Z - A" : "Newest - oldest"
- }
- ])
- },
- {
- key: "sortBy",
- title: "Sort by",
- icon: Icon.SortBy,
- items: map([
- {
- key: "dateCreated",
- title: "Date created",
- hidden: ({ type }) => type === "trash"
- },
- {
- key: "dateEdited",
- title: "Date edited",
- hidden: ({ type }) => type === "trash" || type === "tags"
- },
- {
- key: "dateDeleted",
- title: "Date deleted",
- hidden: ({ type }) => type !== "trash"
- },
- {
- key: "dateModified",
- title: "Date modified",
- hidden: ({ type }) => type !== "tags"
- },
- {
- key: "title",
- title: "Title",
- hidden: ({ groupOptions, parent }, item) => {
- return (
- parent?.key === "sortBy" &&
- item.key === "title" &&
- groupOptions.groupBy !== "abc" &&
- groupOptions.groupBy !== "none"
- );
- }
+const groupByMenu = {
+ key: "groupBy",
+ title: "Group by",
+ icon: Icon.GroupBy,
+ items: map([
+ { key: "none", title: "None" },
+ { key: "default", title: "Default" },
+ { key: "year", title: "Year" },
+ { key: "month", title: "Month" },
+ { key: "week", title: "Week" },
+ { key: "abc", title: "A - Z" }
+ ])
+};
+
+const orderByMenu = {
+ key: "sortDirection",
+ title: "Order by",
+ icon: ({ groupOptions }) =>
+ groupOptions.sortDirection === "asc"
+ ? groupOptions.sortBy === "title"
+ ? Icon.OrderAtoZ
+ : Icon.OrderOldestNewest
+ : groupOptions.sortBy === "title"
+ ? Icon.OrderZtoA
+ : Icon.OrderNewestOldest,
+ items: map([
+ {
+ key: "asc",
+ title: ({ groupOptions }) =>
+ groupOptions.sortBy === "title" ? "A - Z" : "Oldest - newest"
+ },
+ {
+ key: "desc",
+ title: ({ groupOptions }) =>
+ groupOptions.sortBy === "title" ? "Z - A" : "Newest - oldest"
+ }
+ ])
+};
+
+const sortByMenu = {
+ key: "sortBy",
+ title: "Sort by",
+ icon: Icon.SortBy,
+ items: map([
+ {
+ key: "dateCreated",
+ title: "Date created",
+ hidden: ({ type }) => type === "trash"
+ },
+ {
+ key: "dateEdited",
+ title: "Date edited",
+ hidden: ({ type }) => type === "trash" || type === "tags"
+ },
+ {
+ key: "dateDeleted",
+ title: "Date deleted",
+ hidden: ({ type }) => type !== "trash"
+ },
+ {
+ key: "dateModified",
+ title: "Date modified",
+ hidden: ({ type }) => type !== "tags"
+ },
+ {
+ key: "title",
+ title: "Title",
+ hidden: ({ groupOptions, parent, isUngrouped }, item) => {
+ if (isUngrouped) return false;
+
+ return (
+ parent?.key === "sortBy" &&
+ item.key === "title" &&
+ groupOptions.groupBy !== "abc" &&
+ groupOptions.groupBy !== "none"
+ );
}
- ])
- },
- {
- key: "groupBy",
- title: "Group by",
- icon: Icon.GroupBy,
- items: map([
- { key: "none", title: "None" },
- { key: "default", title: "Default" },
- { key: "year", title: "Year" },
- { key: "month", title: "Month" },
- { key: "week", title: "Week" },
- { key: "abc", title: "A - Z" }
- ])
- }
-];
+ }
+ ])
+};
+
+export function showSortMenu(type, refresh) {
+ const groupOptions = db.settings.getGroupOptions(type);
+ Menu.openMenu([orderByMenu, sortByMenu], {
+ title: "Sort",
+ groupOptions,
+ refresh,
+ type,
+ isUngrouped: true
+ });
+}
function changeGroupOptions({ groupOptions, type, refresh, parent }, item) {
if (!parent) return false;
@@ -132,19 +145,10 @@ function isChecked({ groupOptions, parent }, item) {
return groupOptions[parent.key] === item.key;
}
-function isDisabled({ groupOptions, parent }, item) {
- return (
- parent?.key === "sortBy" &&
- item.key === "title" &&
- groupOptions.groupBy === "abc"
- );
-}
-
function map(items) {
return items.map((item) => {
item.checked = isChecked;
item.onClick = changeGroupOptions;
- item.disabled = isDisabled;
return item;
}, []);
}
@@ -248,7 +252,7 @@ function GroupHeader(props) {
<Flex mr={1}>
{type && (
<IconButton
- testId="sort-icon-button"
+ testId={`${type}-sort-button`}
icon={
groupOptions.sortDirection === "asc"
? Icon.SortAsc
@@ -259,7 +263,7 @@ function GroupHeader(props) {
const groupOptions = db.settings.getGroupOptions(type);
setGroupOptions(groupOptions);
- openMenu(menuItems, {
+ openMenu([orderByMenu, sortByMenu, groupByMenu], {
title: "Group & sort",
groupOptions,
refresh,
diff --git a/apps/web/src/components/list-container/index.tsx b/apps/web/src/components/list-container/index.tsx
index 8c66d645f..a43e35802 100644
--- a/apps/web/src/components/list-container/index.tsx
+++ b/apps/web/src/components/list-container/index.tsx
@@ -154,7 +154,7 @@ function ListContainer(props: ListContainerProps) {
transition={{ duration: 0.2, delay: 0.1, ease: "easeInOut" }}
ref={listContainerRef}
variant="columnFill"
- data-test-id="note-list"
+ data-test-id={`${type}-list`}
>
<Virtuoso
ref={listRef}
@@ -187,6 +187,7 @@ function ListContainer(props: ListContainerProps) {
switch (item.type) {
case "header":
+ if (!groupType) return null;
return (
<GroupHeader
type={groupType}
diff --git a/apps/web/src/components/note/index.js b/apps/web/src/components/note/index.js
index 18568ca5e..193a96931 100644
--- a/apps/web/src/components/note/index.js
+++ b/apps/web/src/components/note/index.js
@@ -431,8 +431,8 @@ const menuItems = [
await confirm({
title: "Open duplicated note?",
message: "Do you want to open the duplicated note?",
- noText: "No",
- yesText: "Yes"
+ negativeButtonText: "No",
+ positiveButtonText: "Yes"
})
) {
hashNavigate(`/notes/${id}/edit`, { replace: true });
@@ -455,8 +455,8 @@ const menuItems = [
title: "Prevent this item from syncing?",
message:
"Turning sync off for this item will automatically delete it from all other devices & any future changes to this item won't get synced. Are you sure you want to continue?",
- yesText: "Yes",
- noText: "No"
+ positiveButtonText: "Yes",
+ negativeButtonText: "No"
}))
)
await store.get().localOnly(note.id);
diff --git a/apps/web/src/components/notebook/index.js b/apps/web/src/components/notebook/index.js
index 9ffb07cdf..e6249b461 100644
--- a/apps/web/src/components/notebook/index.js
+++ b/apps/web/src/components/notebook/index.js
@@ -155,25 +155,31 @@ const menuItems = [
iconColor: "error",
icon: Icon.Trash,
onClick: async ({ items }) => {
- const phrase = items.length > 1 ? "this notebook" : "these notebooks";
- const shouldDeleteNotes = await confirm({
- title: `Delete notes in ${phrase}?`,
- message: `These notes will be moved to trash and permanently deleted after 7 days.`,
- yesText: `Yes`,
- noText: "No"
+ const result = await confirm({
+ title: `Delete ${pluralize(items.length, "notebook", "notebooks")}?`,
+ positiveButtonText: `Yes`,
+ negativeButtonText: "No",
+ checks: {
+ deleteContainingNotes: {
+ text: `Delete all containing notes`
+ }
+ }
});
- if (shouldDeleteNotes) {
- const notes = [];
- for (const item of items) {
- const topics = db.notebooks.notebook(item.id).topics;
- for (const topic of topics.all) {
- notes.push(...topics.topic(topic.id).all);
+ if (result) {
+ if (result.deleteContainingNotes) {
+ const notes = [];
+ for (const item of items) {
+ notes.push(...db.relations.from(item, "note"));
+ const topics = db.notebooks.notebook(item.id).topics;
+ for (const topic of topics.all) {
+ notes.push(...topics.topic(topic.id).all);
+ }
}
+ await Multiselect.moveNotesToTrash(notes, false);
}
- await Multiselect.moveNotesToTrash(notes, false);
+ await Multiselect.moveNotebooksToTrash(items);
}
- await Multiselect.moveNotebooksToTrash(items);
},
multiSelect: true
}
diff --git a/apps/web/src/components/reminder/index.tsx b/apps/web/src/components/reminder/index.tsx
index 7f483fc77..f44a2b9aa 100644
--- a/apps/web/src/components/reminder/index.tsx
+++ b/apps/web/src/components/reminder/index.tsx
@@ -19,7 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import React from "react";
import ListItem from "../list-item";
-import { Flex, Text } from "@theme-ui/components";
+import { Flex } from "@theme-ui/components";
import * as Icon from "../icons";
import IconTag from "../icon-tag";
import {
@@ -164,15 +164,11 @@ const menuItems: MenuItem[] = [
onClick: async ({ items }) => {
confirm({
title: `Delete ${pluralize(items.length, "reminder", "reminders")}`,
- message: (
- <Text>
- Are you sure you want to proceed?
- <Text sx={{ color: "error" }}> This action is IRREVERSIBLE.</Text>
- </Text>
- ),
- yesText: "Yes",
- noText: "No",
- yesAction: () => Multiselect.moveRemindersToTrash(items)
+ message: `Are you sure you want to proceed? **This action is IRREVERSIBLE**.`,
+ positiveButtonText: "Yes",
+ negativeButtonText: "No"
+ }).then((result) => {
+ result && Multiselect.moveRemindersToTrash(items);
});
},
multiSelect: true
diff --git a/apps/web/src/components/topic/index.js b/apps/web/src/components/topic/index.js
index 4de13cbd7..41f4e06b3 100644
--- a/apps/web/src/components/topic/index.js
+++ b/apps/web/src/components/topic/index.js
@@ -27,6 +27,7 @@ import * as Icon from "../icons";
import { Multiselect } from "../../common/multi-select";
import { confirm } from "../../common/dialog-controller";
import { useStore as useNotesStore } from "../../stores/note-store";
+import { pluralize } from "../../utils/string";
function Topic({ item, index, onClick }) {
const { id, notebookId } = item;
@@ -36,7 +37,7 @@ function Topic({ item, index, onClick }) {
);
const totalNotes = useMemo(() => {
- return db.notebooks.notebook(notebookId)?.topics.topic(id).totalNotes;
+ return db.notebooks.notebook(notebookId)?.topics.topic(id)?.totalNotes || 0;
}, [id, notebookId]);
return (
@@ -94,23 +95,30 @@ const menuItems = [
color: "error",
iconColor: "error",
onClick: async ({ items, notebookId }) => {
- const phrase = items.length > 1 ? "this topic" : "these topics";
- const shouldDeleteNotes = await confirm({
- title: `Delete notes in ${phrase}?`,
- message: `These notes will be moved to trash and permanently deleted after 7 days.`,
- yesText: `Yes`,
- noText: "No"
+ const result = await confirm({
+ title: `Delete ${pluralize(items.length, "topic", "topics")}?`,
+ positiveButtonText: `Yes`,
+ negativeButtonText: "No",
+ checks: {
+ deleteContainingNotes: {
+ text: `Delete all containing notes`
+ }
+ }
});
- if (shouldDeleteNotes) {
- const notes = [];
- for (const item of items) {
- const topic = db.notebooks.notebook(notebookId).topics.topic(item.id);
- notes.push(...topic.all);
+ if (result) {
+ if (result.deleteContainingNotes) {
+ const notes = [];
+ for (const item of items) {
+ const topic = db.notebooks
+ .notebook(notebookId)
+ .topics.topic(item.id);
+ notes.push(...topic.all);
+ }
+ await Multiselect.moveNotesToTrash(notes, false);
}
- await Multiselect.moveNotesToTrash(notes, false);
+ await Multiselect.deleteTopics(notebookId, items);
}
- await Multiselect.deleteTopics(notebookId, items);
},
multiSelect: true
}
diff --git a/apps/web/src/hooks/use-menu.js b/apps/web/src/hooks/use-menu.js
index ff5ca44e0..f2e357280 100644
--- a/apps/web/src/hooks/use-menu.js
+++ b/apps/web/src/hooks/use-menu.js
@@ -62,6 +62,13 @@ export function useMenuTrigger() {
};
}
+export const Menu = {
+ openMenu: (items, data) => useMenuStore.getState().open(items, data),
+ closeMenu: () => useMenuStore.getState().close(),
+ isOpen: () => useMenuStore.getState().isOpen,
+ target: () => useMenuStore.getState().target
+};
+
export function useMenu() {
const [items, data] = useMenuStore((store) => [store.items, store.data]);
return { items, data };
diff --git a/apps/web/src/navigation/routes.js b/apps/web/src/navigation/routes.js
index 88ab6f727..7bc738637 100644
--- a/apps/web/src/navigation/routes.js
+++ b/apps/web/src/navigation/routes.js
@@ -87,7 +87,7 @@ const routes = {
value: { id: notebookId, topic: topicId }
});
return {
- key: "topic",
+ key: "notebook",
type: "notebook",
title: topic.title,
component: <Topics />,
diff --git a/apps/web/src/stores/notebook-store.js b/apps/web/src/stores/notebook-store.js
index 2b26e4e01..254dd99c5 100644
--- a/apps/web/src/stores/notebook-store.js
+++ b/apps/web/src/stores/notebook-store.js
@@ -27,7 +27,8 @@ import Config from "../utils/config";
class NotebookStore extends BaseStore {
notebooks = [];
- selectedNotebookId = 0;
+ selectedNotebook = undefined;
+ selectedNotebookTopics = [];
viewMode = Config.get("notebooks:viewMode", "detailed");
setViewMode = (viewMode) => {
@@ -42,7 +43,7 @@ class NotebookStore extends BaseStore {
db.settings.getGroupOptions("notebooks")
);
});
- this.setSelectedNotebook(this.get().selectedNotebookId);
+ this.setSelectedNotebook(this.get().selectedNotebook?.id);
};
delete = async (...ids) => {
@@ -59,8 +60,16 @@ class NotebookStore extends BaseStore {
};
setSelectedNotebook = (id) => {
+ if (!id) return;
+ const notebook = db.notebooks?.notebook(id)?.data;
+ if (!notebook) return;
+
this.set((state) => {
- state.selectedNotebookId = id;
+ state.selectedNotebook = notebook;
+ state.selectedNotebookTopics = groupArray(
+ notebook.topics,
+ db.settings.getGroupOptions("topics")
+ );
});
};
}
diff --git a/apps/web/src/utils/changelog.ts b/apps/web/src/utils/changelog.ts
index 8ab313aba..ebc935c89 100644
--- a/apps/web/src/utils/changelog.ts
+++ b/apps/web/src/utils/changelog.ts
@@ -17,38 +17,6 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-import { marked } from "marked";
-
-const emoji: marked.TokenizerExtension & marked.RendererExtension = {
- name: "emoji",
- level: "inline",
- start(src) {
- return src.indexOf(":");
- },
- tokenizer(src, _tokens) {
- const rule = /^:(\w+):/;
- const match = rule.exec(src);
- if (match) {
- return {
- type: "emoji",
- raw: match[0],
- emoji: match[1]
- };
- }
- },
- renderer(token) {
- return `<span className="emoji ${token}" />`;
- }
-};
-
-const renderer = new marked.Renderer();
-renderer.link = function (href, title, text) {
- return `<a target="_blank" rel="noopener noreferrer" href="${href}" ${
- title ? `title=${title}` : ""
- }>${text}</a>`;
-};
-marked.use({ extensions: [emoji] });
-
export async function getChangelog(tag: string) {
try {
if (!tag) return "No changelog found.";
@@ -63,7 +31,7 @@ export async function getChangelog(tag: string) {
if (!release || !release.body) return "No changelog found.";
const { body } = release;
- return await marked.parse(body, { async: true, renderer, gfm: true });
+ return body;
} catch (e) {
console.error(e);
return "No changelog found.";
diff --git a/apps/web/src/utils/md.ts b/apps/web/src/utils/md.ts
new file mode 100644
index 000000000..b5894ba1a
--- /dev/null
+++ b/apps/web/src/utils/md.ts
@@ -0,0 +1,54 @@
+/*
+This file is part of the Notesnook project (https://notesnook.com/)
+
+Copyright (C) 2023 Streetwriters (Private) Limited
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+import { marked } from "marked";
+
+const emoji: marked.TokenizerExtension & marked.RendererExtension = {
+ name: "emoji",
+ level: "inline",
+ start(src) {
+ return src.indexOf(":");
+ },
+ tokenizer(src, _tokens) {
+ const rule = /^:(\w+):/;
+ const match = rule.exec(src);
+ if (match) {
+ return {
+ type: "emoji",
+ raw: match[0],
+ emoji: match[1]
+ };
+ }
+ },
+ renderer(token) {
+ return `<span className="emoji ${token}" />`;
+ }
+};
+
+const renderer = new marked.Renderer();
+renderer.link = function (href, title, text) {
+ return `<a target="_blank" rel="noopener noreferrer" href="${href}" ${
+ title ? `title=${title}` : ""
+ }>${text}</a>`;
+};
+marked.use({ extensions: [emoji] });
+
+export function mdToHtml(markdown: string) {
+ return marked.parse(markdown, { async: false, renderer, gfm: true });
+}
diff --git a/apps/web/src/views/auth.tsx b/apps/web/src/views/auth.tsx
index 1534de29a..9a3a83d2b 100644
--- a/apps/web/src/views/auth.tsx
+++ b/apps/web/src/views/auth.tsx
@@ -755,6 +755,7 @@ function MFASelector(props: BaseAuthComponentProps<"mfa:select">) {
(method, index) =>
isValidMethod(method.type) && (
<Button
+ key={method.type}
type="submit"
variant={"secondary"}
mt={2}
diff --git a/apps/web/src/views/topics.js b/apps/web/src/views/topics.js
index d6e7e1045..c7ddfdc04 100644
--- a/apps/web/src/views/topics.js
+++ b/apps/web/src/views/topics.js
@@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-import { useEffect, useMemo, useState } from "react";
+import { useEffect, useState } from "react";
import ListContainer from "../components/list-container";
import { useStore as useNbStore } from "../stores/notebook-store";
import { useStore as useAppStore } from "../stores/app-store";
@@ -28,37 +28,37 @@ import {
ChevronRight,
Edit,
RemoveShortcutLink,
- ShortcutLink
+ ShortcutLink,
+ SortAsc
} from "../components/icons";
import { getTotalNotes } from "../common";
import { formatDate } from "@notesnook/core/utils/date";
-import { db } from "../common/db";
import { pluralize } from "../utils/string";
import { Allotment } from "allotment";
import { Plus } from "../components/icons";
import { useStore as useNotesStore } from "../stores/note-store";
import Placeholder from "../components/placeholders";
+import { showSortMenu } from "../components/group-header";
function Notebook() {
const [isCollapsed, setIsCollapsed] = useState(false);
- const selectedNotebookId = useNbStore((store) => store.selectedNotebookId);
+ const selectedNotebook = useNbStore((store) => store.selectedNotebook);
const refresh = useNbStore((store) => store.setSelectedNotebook);
- const notebooks = useNbStore((store) => store.notebooks);
const context = useNotesStore((store) => store.context);
const refreshContext = useNotesStore((store) => store.refreshContext);
const isCompact = useNotesStore((store) => store.viewMode === "compact");
useEffect(() => {
- if (context && context.value && selectedNotebookId !== context.value.id)
+ if (
+ context &&
+ context.value &&
+ selectedNotebook &&
+ selectedNotebook.id !== context.value.id
+ )
refresh(context.value.id);
- }, [selectedNotebookId, context, refresh]);
-
- const selectedNotebook = useMemo(
- () => db.notebooks?.notebook(selectedNotebookId)?.data,
- [selectedNotebookId, notebooks]
- );
+ }, [selectedNotebook, context, refresh]);
if (!context) return null;
return (
@@ -69,7 +69,7 @@ function Notebook() {
{ title: "Notebooks", onClick: () => navigate(`/notebooks/`) },
{
title: selectedNotebook.title,
- onClick: () => navigate(`/notebooks/${selectedNotebookId}`)
+ onClick: () => navigate(`/notebooks/${selectedNotebook.id}`)
}
].map((crumb, index, array) => (
<>
@@ -139,8 +139,11 @@ export default Notebook;
function Topics({ selectedNotebook, isCollapsed, setIsCollapsed }) {
const refresh = useNbStore((store) => store.setSelectedNotebook);
+ const topics = useNbStore((store) => store.selectedNotebookTopics);
+
+ if (!selectedNotebook) return null;
return (
- <Flex variant="columnFill" sx={{ height: "100%" }}>
+ <Flex id="topics" variant="columnFill" sx={{ height: "100%" }}>
<Flex
sx={{
m: 1,
@@ -161,26 +164,42 @@ function Topics({ selectedNotebook, isCollapsed, setIsCollapsed }) {
TOPICS
</Text>
</Flex>
- <Button
- variant="tool"
- sx={{
- p: "1px",
- bg: "transparent",
- visibility: isCollapsed ? "collapse" : "visible"
- }}
- onClick={(e) => {
- hashNavigate(`/topics/create`);
- }}
- >
- <Plus size={20} />
- </Button>
+ <Flex sx={{ alignItems: "center" }}>
+ <Button
+ variant="tool"
+ data-test-id="topics-sort-button"
+ sx={{
+ p: "3.5px",
+ bg: "transparent",
+ visibility: isCollapsed ? "collapse" : "visible"
+ }}
+ onClick={(e) => {
+ e.stopPropagation();
+ showSortMenu("topics", () => refresh(selectedNotebook.id));
+ }}
+ >
+ <SortAsc size={15} />
+ </Button>
+ <Button
+ variant="tool"
+ sx={{
+ p: "1px",
+ bg: "transparent",
+ visibility: isCollapsed ? "collapse" : "visible"
+ }}
+ onClick={(e) => {
+ e.stopPropagation();
+ hashNavigate(`/topics/create`);
+ }}
+ >
+ <Plus size={20} />
+ </Button>
+ </Flex>
</Flex>
<ListContainer
type="topics"
- groupType="topics"
- refresh={() => refresh(selectedNotebook.id)}
- items={selectedNotebook.topics}
+ items={topics}
context={{
notebookId: selectedNotebook.id
}}
diff --git a/apps/web/src/views/trash.js b/apps/web/src/views/trash.js
index 7cd9d7f4a..5a2d6c1e8 100644
--- a/apps/web/src/views/trash.js
+++ b/apps/web/src/views/trash.js
@@ -51,20 +51,9 @@ function Trash() {
confirm({
title: "Clear Trash",
subtitle: "Are you sure you want to clear all the trash?",
- yesText: "Clear trash",
- noText: "Cancel",
- message: (
- <>
- This action is{" "}
- <Text as="span" sx={{ color: "error" }}>
- IRREVERSIBLE
- </Text>
- . You will{" "}
- <Text as="span" sx={{ color: "primary" }}>
- not be able to recover any of these items.
- </Text>
- </>
- )
+ positiveButtonText: "Clear trash",
+ negativeButtonText: "Cancel",
+ message: `Are you sure you want to proceed? **This action is IRREVERSIBLE**.`
}).then(async (res) => {
if (res) {
try {