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 { 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;
}

View File

@@ -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 = {

View File

@@ -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 && <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} />}
<TimeAgo live={true} datetime={date} locale="short" />
</>
@@ -225,7 +226,7 @@ function Note(props: NoteProps) {
<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} />}
@@ -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

View File

@@ -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) {
</Flex>
}
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 });
}}
/>
);

View File

@@ -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}`;

View File

@@ -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) {
}}
>
<ErrorText
error={error.stack}
error={error}
as="p"
sx={{
borderRadius: "default",

View File

@@ -56,7 +56,7 @@ export class NNStorage implements IStorage {
const user = await this.read<User>("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([

View File

@@ -81,9 +81,9 @@ class EditorStore extends BaseStore<EditorStore> {
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<EditorStore> {
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 });

View File

@@ -44,7 +44,7 @@ export class WebExtensionServer implements Server {
async getNotes(): Promise<ItemReference[] | undefined> {
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;

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 { 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";