mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-09-01 19:49:54 +02:00
web: fix note history tests
This commit is contained in:
committed by
Abdullah Atta
parent
60974182e5
commit
f088ddf50b
@@ -348,6 +348,7 @@ class SessionHistoryItemModel {
|
||||
await fillPasswordDialog(this.page, password);
|
||||
}
|
||||
await this.previewNotice.waitFor();
|
||||
await this.properties.close();
|
||||
}
|
||||
|
||||
async isLocked() {
|
||||
|
||||
@@ -170,11 +170,7 @@ export function Attachment({
|
||||
<AttachmentError
|
||||
color={"icon-error"}
|
||||
size={16}
|
||||
title={
|
||||
typeof attachment.failed === "object"
|
||||
? attachment.failed.toString()
|
||||
: attachment.failed
|
||||
}
|
||||
title={processing?.failed || item.failed}
|
||||
/>
|
||||
) : processing?.working ? (
|
||||
<Loading size={16} />
|
||||
|
||||
@@ -147,10 +147,9 @@ function Note(props: NoteProps) {
|
||||
body={note.headline as string}
|
||||
onKeyPress={async (e) => {
|
||||
if (e.key === "Delete") {
|
||||
const selectedItems = selectionStore
|
||||
.get()
|
||||
.selectedItems.filter((i) => i.type === item.type && i !== item);
|
||||
await Multiselect.moveNotesToTrash([item, ...selectedItems]);
|
||||
// @ts-expect-error write tests for this
|
||||
const selectedItems = selectionStore.get().selectedItems;
|
||||
await Multiselect.moveNotesToTrash([item.id, ...selectedItems]);
|
||||
}
|
||||
}}
|
||||
colors={{
|
||||
|
||||
@@ -265,8 +265,7 @@ function Notebooks({ noteId }: { noteId: string }) {
|
||||
.selector.sorted(db.settings.getGroupOptions("notebooks"))
|
||||
);
|
||||
|
||||
if (result.status !== "fulfilled" || result.value.ids.length <= 0)
|
||||
return null;
|
||||
if (result.status !== "fulfilled" || result.value.length <= 0) return null;
|
||||
|
||||
return (
|
||||
<Section title="Notebooks">
|
||||
@@ -274,7 +273,7 @@ function Notebooks({ noteId }: { noteId: string }) {
|
||||
mode="fixed"
|
||||
estimatedSize={50}
|
||||
getItemKey={(index) => result.value.key(index)}
|
||||
items={result.value.ids}
|
||||
items={result.value.placeholders}
|
||||
renderItem={({ index }) => (
|
||||
<ResolvedItem index={index} items={result.value} type="notebook">
|
||||
{({ item, data }) => (
|
||||
@@ -292,8 +291,7 @@ function Reminders({ noteId }: { noteId: string }) {
|
||||
.from({ id: noteId, type: "note" }, "reminder")
|
||||
.selector.sorted(db.settings.getGroupOptions("reminders"))
|
||||
);
|
||||
if (result.status !== "fulfilled" || result.value.ids.length <= 0)
|
||||
return null;
|
||||
if (result.status !== "fulfilled" || result.value.length <= 0) return null;
|
||||
|
||||
return (
|
||||
<Section title="Reminders">
|
||||
@@ -301,7 +299,7 @@ function Reminders({ noteId }: { noteId: string }) {
|
||||
mode="fixed"
|
||||
estimatedSize={54}
|
||||
getItemKey={(index) => result.value.key(index)}
|
||||
items={result.value.ids}
|
||||
items={result.value.placeholders}
|
||||
renderItem={({ index }) => (
|
||||
<ResolvedItem index={index} items={result.value} type="reminder">
|
||||
{({ item, data }) => (
|
||||
@@ -319,15 +317,14 @@ function Attachments({ noteId }: { noteId: string }) {
|
||||
.ofNote(noteId, "all")
|
||||
.sorted({ sortBy: "dateCreated", sortDirection: "desc" })
|
||||
);
|
||||
if (result.status !== "fulfilled" || result.value.ids.length <= 0)
|
||||
return null;
|
||||
if (result.status !== "fulfilled" || result.value.length <= 0) return null;
|
||||
|
||||
return (
|
||||
<Section title="Attachments">
|
||||
<VirtualizedTable
|
||||
estimatedSize={30}
|
||||
getItemKey={(index) => result.value.key(index)}
|
||||
items={result.value.ids}
|
||||
items={result.value.placeholders}
|
||||
header={<></>}
|
||||
renderRow={({ index }) => (
|
||||
<ResolvedItem index={index} type="attachment" items={result.value}>
|
||||
@@ -354,8 +351,7 @@ function SessionHistory({
|
||||
.get(noteId)
|
||||
.sorted({ sortBy: "dateModified", sortDirection: "desc" })
|
||||
);
|
||||
if (result.status !== "fulfilled" || result.value.ids.length <= 0)
|
||||
return null;
|
||||
if (result.status !== "fulfilled" || result.value.length <= 0) return null;
|
||||
|
||||
return (
|
||||
<Section
|
||||
@@ -366,7 +362,7 @@ function SessionHistory({
|
||||
mode="fixed"
|
||||
estimatedSize={28}
|
||||
getItemKey={(index) => result.value.key(index)}
|
||||
items={result.value.ids}
|
||||
items={result.value.placeholders}
|
||||
renderItem={({ index }) => (
|
||||
<ResolvedItem type="session" index={index} items={result.value}>
|
||||
{({ item }) => (
|
||||
|
||||
@@ -112,7 +112,7 @@ function AddTagsDialog(props: AddTagsDialogProps) {
|
||||
getItemKey={(index) => tags.key(index)}
|
||||
mode="fixed"
|
||||
estimatedSize={30}
|
||||
items={tags.ids}
|
||||
items={tags.placeholders}
|
||||
sx={{ mt: 2 }}
|
||||
itemGap={5}
|
||||
placeholders={{
|
||||
|
||||
@@ -320,7 +320,7 @@ function AttachmentsDialog({ onClose }: AttachmentsDialogProps) {
|
||||
mode="fixed"
|
||||
estimatedSize={30}
|
||||
getItemKey={(index) => attachments.key(index)}
|
||||
items={attachments.ids}
|
||||
items={attachments.placeholders}
|
||||
context={{
|
||||
isSelected: (id: string) => selected.indexOf(id) > -1,
|
||||
select: (id: string) => {
|
||||
|
||||
@@ -70,7 +70,8 @@ async function processAttachment(
|
||||
attachments: Record<string, any>
|
||||
) {
|
||||
const name = path.basename(entry.name);
|
||||
if (!name || attachments[name] || db.attachments?.exists(name)) return;
|
||||
if (!name || attachments[name] || (await db.attachments?.exists(name)))
|
||||
return;
|
||||
|
||||
const { hashBuffer, writeEncryptedFile } = await import("../interfaces/fs");
|
||||
|
||||
@@ -92,7 +93,8 @@ async function processNote(entry: ZipEntry, attachments: Record<string, any>) {
|
||||
const note = await fileToJson<Note>(entry);
|
||||
for (const attachment of note.attachments || []) {
|
||||
const cipherData = attachments[attachment.hash];
|
||||
if (!cipherData || db.attachments?.exists(attachment.hash)) continue;
|
||||
if (!cipherData || (await db.attachments?.exists(attachment.hash)))
|
||||
continue;
|
||||
|
||||
await db.attachments?.add({
|
||||
...cipherData,
|
||||
|
||||
@@ -28,6 +28,7 @@ type Batch<T> = {
|
||||
export class VirtualizedGrouping<T> {
|
||||
private cache: Map<number, Batch<T>> = new Map();
|
||||
private pending: Map<number, Promise<Batch<T>>> = new Map();
|
||||
private _placeholders: boolean[] = [];
|
||||
|
||||
constructor(
|
||||
readonly length: number,
|
||||
@@ -43,6 +44,13 @@ export class VirtualizedGrouping<T> {
|
||||
readonly groups?: () => Promise<{ index: number; group: GroupHeader }[]>
|
||||
) {}
|
||||
|
||||
get placeholders() {
|
||||
if (this._placeholders.length !== this.length) {
|
||||
this._placeholders = new Array(this.length).fill(true);
|
||||
}
|
||||
return this._placeholders;
|
||||
}
|
||||
|
||||
key(index: number) {
|
||||
return `${index}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user