web: various fixes

This commit is contained in:
Abdullah Atta
2024-02-07 13:38:43 +05:00
parent a45c5db34e
commit bfe9aa5330
10 changed files with 31 additions and 28 deletions

View File

@@ -21,10 +21,6 @@ import { TaskManager } from "./task-manager";
import { ExportStream } from "../utils/streams/export-stream"; import { ExportStream } from "../utils/streams/export-stream";
import { createZipStream } from "../utils/streams/zip-stream"; import { createZipStream } from "../utils/streams/zip-stream";
import { createWriteStream } from "../utils/stream-saver"; 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 { FilteredSelector } from "@notesnook/core/dist/database/sql-collection";
import { Note, isDeleted } from "@notesnook/core"; import { Note, isDeleted } from "@notesnook/core";
import { fromAsyncIterator } from "../utils/stream"; import { fromAsyncIterator } from "../utils/stream";
@@ -125,7 +121,11 @@ export async function exportNote(
format: keyof typeof FORMAT_TO_EXT; 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.`); showToast("error", `Skipping note "${note.title}" as it is locked.`);
return false; return false;
} }

View File

@@ -102,7 +102,7 @@ export async function shouldAddLoginNotice() {
export async function shouldAddConfirmEmailNotice() { export async function shouldAddConfirmEmailNotice() {
const user = await db.user.getUser(); const user = await db.user.getUser();
return !user || user.isEmailConfirmed; return !user?.isEmailConfirmed;
} }
type NoticeData = { type NoticeData = {

View File

@@ -101,6 +101,7 @@ function Note(props: NoteProps) {
color, color,
notebooks, notebooks,
attachments, attachments,
locked,
item, item,
date, date,
reminder, reminder,
@@ -133,12 +134,12 @@ function Note(props: NoteProps) {
heading: color ? primary : "heading", heading: color ? primary : "heading",
background: "background" background: "background"
}} }}
context={{ color }} context={{ color, locked }}
menuItems={menuItems} menuItems={menuItems}
onClick={() => { onClick={async () => {
if (note.conflicted) { if (note.conflicted) {
hashNavigate(`/notes/${note.id}/conflict`, { replace: true }); hashNavigate(`/notes/${note.id}/conflict`, { replace: true });
} else if (note.locked) { } else if (locked) {
hashNavigate(`/notes/${note.id}/unlock`, { replace: true }); hashNavigate(`/notes/${note.id}/unlock`, { replace: true });
} else { } else {
hashNavigate(`/notes/${note.id}/edit`, { replace: true }); hashNavigate(`/notes/${note.id}/edit`, { replace: true });
@@ -188,7 +189,7 @@ function Note(props: NoteProps) {
{compact ? ( {compact ? (
<> <>
{note.conflicted && <Alert size={15} color="var(--icon-error)" />} {note.conflicted && <Alert size={15} color="var(--icon-error)" />}
{note.locked && <Lock size={11} data-test-id={`locked`} />} {locked && <Lock size={11} data-test-id={`locked`} />}
{note.favorite && <Star color={primary} size={15} />} {note.favorite && <Star color={primary} size={15} />}
<TimeAgo live={true} datetime={date} locale="short" /> <TimeAgo live={true} datetime={date} locale="short" />
</> </>
@@ -225,7 +226,7 @@ function Note(props: NoteProps) {
<Pin size={13} color={primary} /> <Pin size={13} color={primary} />
)} )}
{note.locked && <Lock size={13} data-test-id={`locked`} />} {locked && <Lock size={13} data-test-id={`locked`} />}
{note.favorite && <Star color={primary} size={15} />} {note.favorite && <Star color={primary} size={15} />}
@@ -317,7 +318,7 @@ const notFullySyncedText =
const menuItems: ( const menuItems: (
note: Note, note: Note,
ids?: string[], ids?: string[],
context?: { color?: Color } context?: { color?: Color; locked?: boolean }
) => MenuItem[] = (note, ids = [], context) => { ) => MenuItem[] = (note, ids = [], context) => {
// const isSynced = db.notes.note(note.id)?.synced(); // const isSynced = db.notes.note(note.id)?.synced();
@@ -354,11 +355,11 @@ const menuItems: (
key: "lock", key: "lock",
//isDisabled: !isSynced, //isDisabled: !isSynced,
title: "Lock", title: "Lock",
isChecked: note.locked, isChecked: context?.locked,
icon: Lock.path, icon: Lock.path,
onClick: async () => { onClick: async () => {
const { unlock, lock } = store.get(); const { unlock, lock } = store.get();
if (!note.locked) { if (!context?.locked) {
if (await lock(note.id)) if (await lock(note.id))
showToast("success", "Note locked successfully!"); showToast("success", "Note locked successfully!");
} else if (await unlock(note.id)) { } else if (await unlock(note.id)) {
@@ -419,7 +420,7 @@ const menuItems: (
key: "publish", key: "publish",
isDisabled: isDisabled:
//!isSynced || //!isSynced ||
!db.monographs.isPublished(note.id) && note.locked, !db.monographs.isPublished(note.id) && context?.locked,
icon: Publish.path, icon: Publish.path,
title: "Publish", title: "Publish",
isChecked: db.monographs.isPublished(note.id), isChecked: db.monographs.isPublished(note.id),
@@ -500,7 +501,7 @@ const menuItems: (
key: "duplicate", key: "duplicate",
title: "Duplicate", title: "Duplicate",
//!isSynced || //!isSynced ||
isDisabled: note.locked, isDisabled: context?.locked,
icon: Duplicate.path, icon: Duplicate.path,
onClick: () => store.get().duplicate(...ids), onClick: () => store.get().duplicate(...ids),
multiSelect: true multiSelect: true

View File

@@ -29,6 +29,7 @@ import { hashNavigate } from "../../navigation";
import { useStore } from "../../stores/note-store"; import { useStore } from "../../stores/note-store";
import { MenuItem } from "@notesnook/ui"; import { MenuItem } from "@notesnook/ui";
import { TrashItem } from "@notesnook/core/dist/types"; import { TrashItem } from "@notesnook/core/dist/types";
import { db } from "../../common/db";
type TrashItemProps = { item: TrashItem; date: number }; type TrashItemProps = { item: TrashItem; date: number };
function TrashItem(props: TrashItemProps) { function TrashItem(props: TrashItemProps) {
@@ -56,11 +57,11 @@ function TrashItem(props: TrashItemProps) {
</Flex> </Flex>
} }
menuItems={menuItems} menuItems={menuItems}
onClick={() => { onClick={async () => {
if (item.itemType === "note") if (item.itemType === "note")
!item.locked (await db.vaults.itemExists({ id: item.id, type: "note" }))
? hashNavigate(`/notes/${item.id}/edit`, { replace: true }) ? showToast("error", "Locked notes cannot be previewed in trash.")
: showToast("error", "Locked notes cannot be previewed in trash."); : hashNavigate(`/notes/${item.id}/edit`, { replace: true });
}} }}
/> />
); );

View File

@@ -161,7 +161,7 @@ function showIssueReportedDialog({ url }: { url: string }) {
}); });
} }
function getDeviceInfo() { export function getDeviceInfo() {
const version = appVersion.formatted; const version = appVersion.formatted;
const os = platform.os; const os = platform.os;
const browser = `${platform.name} ${platform.version}`; const browser = `${platform.name} ${platform.version}`;

View File

@@ -68,6 +68,7 @@ export default function MigrationDialog(props: MigrationDialogProps) {
props.onClose(true); props.onClose(true);
} catch (e) { } catch (e) {
console.error(e);
if (e instanceof Error) setError(e); if (e instanceof Error) setError(e);
} }
} }
@@ -94,7 +95,7 @@ export default function MigrationDialog(props: MigrationDialogProps) {
}} }}
> >
<ErrorText <ErrorText
error={error.stack} error={error}
as="p" as="p"
sx={{ sx={{
borderRadius: "default", borderRadius: "default",

View File

@@ -56,7 +56,7 @@ export class NNStorage implements IStorage {
const user = await this.read<User>("user"); const user = await this.read<User>("user");
if (!user) return; if (!user) return;
const key = await this._getCryptoKey(user.email); const key = await this._getCryptoKey(`_uk_@${user.email}`);
if (!key) return; if (!key) return;
await this.database.deleteMany([ await this.database.deleteMany([

View File

@@ -81,9 +81,9 @@ class EditorStore extends BaseStore<EditorStore> {
hashNavigate("/notes/create", { replace: true, addNonce: true }); hashNavigate("/notes/create", { replace: true, addNonce: true });
}); });
EV.subscribe(EVENTS.vaultLocked, () => { EV.subscribe(EVENTS.vaultLocked, async () => {
const { id, locked } = this.get().session; 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<EditorStore> {
noteStore.setSelectedNote(note.id); noteStore.setSelectedNote(note.id);
setDocumentTitle(settingStore.get().hideNoteTitle ? undefined : note.title); setDocumentTitle(settingStore.get().hideNoteTitle ? undefined : note.title);
if (note.locked) if (await db.vaults.itemExists(note))
return hashNavigate(`/notes/${noteId}/unlock`, { replace: true }); return hashNavigate(`/notes/${noteId}/unlock`, { replace: true });
if (note.conflicted) if (note.conflicted)
return hashNavigate(`/notes/${noteId}/conflict`, { replace: true }); return hashNavigate(`/notes/${noteId}/conflict`, { replace: true });

View File

@@ -44,7 +44,7 @@ export class WebExtensionServer implements Server {
async getNotes(): Promise<ItemReference[] | undefined> { async getNotes(): Promise<ItemReference[] | undefined> {
const notes = await db.notes.all const notes = await db.notes.all
.where((eb) => eb("notes.locked", "==", false)) // TODO: .where((eb) => eb("notes.locked", "==", false))
.fields(["notes.id", "notes.title"]) .fields(["notes.id", "notes.title"])
.items(undefined, db.settings.getGroupOptions("notes")); .items(undefined, db.settings.getGroupOptions("notes"));
return notes; return notes;

View File

@@ -19,7 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import { PropsWithChildren, useEffect, useState } from "react"; import { PropsWithChildren, useEffect, useState } from "react";
import { useStore as useSettingStore } from "../stores/setting-store"; 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 { KeyChain } from "../interfaces/key-store";
import { Button, Flex, Text } from "@theme-ui/components"; import { Button, Flex, Text } from "@theme-ui/components";
import { Loading, Lock } from "../components/icons"; import { Loading, Lock } from "../components/icons";