diff --git a/apps/web/src/common/export.ts b/apps/web/src/common/export.ts index ee04433c1..416d9f0a2 100644 --- a/apps/web/src/common/export.ts +++ b/apps/web/src/common/export.ts @@ -21,10 +21,6 @@ import { TaskManager } from "./task-manager"; import { ExportStream } from "../utils/streams/export-stream"; import { createZipStream } from "../utils/streams/zip-stream"; import { createWriteStream } from "../utils/stream-saver"; -import { - isEncryptedContent, - isUnencryptedContent -} from "@notesnook/core/dist/collections/content"; import { FilteredSelector } from "@notesnook/core/dist/database/sql-collection"; import { Note, isDeleted } from "@notesnook/core"; import { fromAsyncIterator } from "../utils/stream"; @@ -125,7 +121,11 @@ export async function exportNote( format: keyof typeof FORMAT_TO_EXT; } ) { - if (!db.vault.unlocked && note.locked && !(await Vault.unlockVault())) { + if ( + !db.vault.unlocked && + (await db.vaults.itemExists(note)) && + !(await Vault.unlockVault()) + ) { showToast("error", `Skipping note "${note.title}" as it is locked.`); return false; } diff --git a/apps/web/src/common/notices.ts b/apps/web/src/common/notices.ts index 51c8a8318..6bbf46cab 100644 --- a/apps/web/src/common/notices.ts +++ b/apps/web/src/common/notices.ts @@ -102,7 +102,7 @@ export async function shouldAddLoginNotice() { export async function shouldAddConfirmEmailNotice() { const user = await db.user.getUser(); - return !user || user.isEmailConfirmed; + return !user?.isEmailConfirmed; } type NoticeData = { diff --git a/apps/web/src/components/note/index.tsx b/apps/web/src/components/note/index.tsx index ec4e1861e..14b009031 100644 --- a/apps/web/src/components/note/index.tsx +++ b/apps/web/src/components/note/index.tsx @@ -101,6 +101,7 @@ function Note(props: NoteProps) { color, notebooks, attachments, + locked, item, date, reminder, @@ -133,12 +134,12 @@ function Note(props: NoteProps) { heading: color ? primary : "heading", background: "background" }} - context={{ color }} + context={{ color, locked }} menuItems={menuItems} - onClick={() => { + onClick={async () => { if (note.conflicted) { hashNavigate(`/notes/${note.id}/conflict`, { replace: true }); - } else if (note.locked) { + } else if (locked) { hashNavigate(`/notes/${note.id}/unlock`, { replace: true }); } else { hashNavigate(`/notes/${note.id}/edit`, { replace: true }); @@ -188,7 +189,7 @@ function Note(props: NoteProps) { {compact ? ( <> {note.conflicted && } - {note.locked && } + {locked && } {note.favorite && } @@ -225,7 +226,7 @@ function Note(props: NoteProps) { )} - {note.locked && } + {locked && } {note.favorite && } @@ -317,7 +318,7 @@ const notFullySyncedText = const menuItems: ( note: Note, ids?: string[], - context?: { color?: Color } + context?: { color?: Color; locked?: boolean } ) => MenuItem[] = (note, ids = [], context) => { // const isSynced = db.notes.note(note.id)?.synced(); @@ -354,11 +355,11 @@ const menuItems: ( key: "lock", //isDisabled: !isSynced, title: "Lock", - isChecked: note.locked, + isChecked: context?.locked, icon: Lock.path, onClick: async () => { const { unlock, lock } = store.get(); - if (!note.locked) { + if (!context?.locked) { if (await lock(note.id)) showToast("success", "Note locked successfully!"); } else if (await unlock(note.id)) { @@ -419,7 +420,7 @@ const menuItems: ( key: "publish", isDisabled: //!isSynced || - !db.monographs.isPublished(note.id) && note.locked, + !db.monographs.isPublished(note.id) && context?.locked, icon: Publish.path, title: "Publish", isChecked: db.monographs.isPublished(note.id), @@ -500,7 +501,7 @@ const menuItems: ( key: "duplicate", title: "Duplicate", //!isSynced || - isDisabled: note.locked, + isDisabled: context?.locked, icon: Duplicate.path, onClick: () => store.get().duplicate(...ids), multiSelect: true diff --git a/apps/web/src/components/trash-item/index.tsx b/apps/web/src/components/trash-item/index.tsx index 344216838..080123637 100644 --- a/apps/web/src/components/trash-item/index.tsx +++ b/apps/web/src/components/trash-item/index.tsx @@ -29,6 +29,7 @@ import { hashNavigate } from "../../navigation"; import { useStore } from "../../stores/note-store"; import { MenuItem } from "@notesnook/ui"; import { TrashItem } from "@notesnook/core/dist/types"; +import { db } from "../../common/db"; type TrashItemProps = { item: TrashItem; date: number }; function TrashItem(props: TrashItemProps) { @@ -56,11 +57,11 @@ function TrashItem(props: TrashItemProps) { } menuItems={menuItems} - onClick={() => { + onClick={async () => { if (item.itemType === "note") - !item.locked - ? hashNavigate(`/notes/${item.id}/edit`, { replace: true }) - : showToast("error", "Locked notes cannot be previewed in trash."); + (await db.vaults.itemExists({ id: item.id, type: "note" })) + ? showToast("error", "Locked notes cannot be previewed in trash.") + : hashNavigate(`/notes/${item.id}/edit`, { replace: true }); }} /> ); diff --git a/apps/web/src/dialogs/issue-dialog.tsx b/apps/web/src/dialogs/issue-dialog.tsx index 152ccc6a6..3c77d71d2 100644 --- a/apps/web/src/dialogs/issue-dialog.tsx +++ b/apps/web/src/dialogs/issue-dialog.tsx @@ -161,7 +161,7 @@ function showIssueReportedDialog({ url }: { url: string }) { }); } -function getDeviceInfo() { +export function getDeviceInfo() { const version = appVersion.formatted; const os = platform.os; const browser = `${platform.name} ${platform.version}`; diff --git a/apps/web/src/dialogs/migration-dialog.tsx b/apps/web/src/dialogs/migration-dialog.tsx index 5a442c2c2..f3a991483 100644 --- a/apps/web/src/dialogs/migration-dialog.tsx +++ b/apps/web/src/dialogs/migration-dialog.tsx @@ -68,6 +68,7 @@ export default function MigrationDialog(props: MigrationDialogProps) { props.onClose(true); } catch (e) { + console.error(e); if (e instanceof Error) setError(e); } } @@ -94,7 +95,7 @@ export default function MigrationDialog(props: MigrationDialogProps) { }} > ("user"); if (!user) return; - const key = await this._getCryptoKey(user.email); + const key = await this._getCryptoKey(`_uk_@${user.email}`); if (!key) return; await this.database.deleteMany([ diff --git a/apps/web/src/stores/editor-store.ts b/apps/web/src/stores/editor-store.ts index 7a0133c9a..185d865da 100644 --- a/apps/web/src/stores/editor-store.ts +++ b/apps/web/src/stores/editor-store.ts @@ -81,9 +81,9 @@ class EditorStore extends BaseStore { hashNavigate("/notes/create", { replace: true, addNonce: true }); }); - EV.subscribe(EVENTS.vaultLocked, () => { + EV.subscribe(EVENTS.vaultLocked, async () => { const { id, locked } = this.get().session; - if (locked) hashNavigate(`/notes/${id}/unlock`, { replace: true }); + if (id && locked) hashNavigate(`/notes/${id}/unlock`, { replace: true }); }); }; @@ -153,7 +153,7 @@ class EditorStore extends BaseStore { noteStore.setSelectedNote(note.id); setDocumentTitle(settingStore.get().hideNoteTitle ? undefined : note.title); - if (note.locked) + if (await db.vaults.itemExists(note)) return hashNavigate(`/notes/${noteId}/unlock`, { replace: true }); if (note.conflicted) return hashNavigate(`/notes/${noteId}/conflict`, { replace: true }); diff --git a/apps/web/src/utils/web-extension-server.ts b/apps/web/src/utils/web-extension-server.ts index 382645b9b..10792c208 100644 --- a/apps/web/src/utils/web-extension-server.ts +++ b/apps/web/src/utils/web-extension-server.ts @@ -44,7 +44,7 @@ export class WebExtensionServer implements Server { async getNotes(): Promise { const notes = await db.notes.all - .where((eb) => eb("notes.locked", "==", false)) + // TODO: .where((eb) => eb("notes.locked", "==", false)) .fields(["notes.id", "notes.title"]) .items(undefined, db.settings.getGroupOptions("notes")); return notes; diff --git a/apps/web/src/views/app-lock.tsx b/apps/web/src/views/app-lock.tsx index 793b9defd..28383426d 100644 --- a/apps/web/src/views/app-lock.tsx +++ b/apps/web/src/views/app-lock.tsx @@ -19,7 +19,7 @@ along with this program. If not, see . import { PropsWithChildren, useEffect, useState } from "react"; import { useStore as useSettingStore } from "../stores/setting-store"; -import usePromise from "../hooks/use-promise"; +import { usePromise } from "@notesnook/common"; import { KeyChain } from "../interfaces/key-store"; import { Button, Flex, Text } from "@theme-ui/components"; import { Loading, Lock } from "../components/icons";