Skip to content

Commit be115c7

Browse files
committed
chore(print/list): address review
1 parent 049721b commit be115c7

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

apps/client/src/widgets/collections/legacy/ListOrGridView.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import tree from "../../../services/tree";
1111
import link from "../../../services/link";
1212
import { t } from "../../../services/i18n";
1313
import attribute_renderer from "../../../services/attribute_renderer";
14-
import { useFilteredNoteIds } from "./utils";
14+
import { filterChildNotes, useFilteredNoteIds } from "./utils";
1515

1616
export function ListView({ note, noteIds: unfilteredNoteIds, highlightedTokens }: ViewModeProps<{}>) {
1717
const [ isExpanded ] = useNoteLabelBoolean(note, "expanded");
@@ -161,14 +161,10 @@ function NoteContent({ note, trim, noChildrenList, highlightedTokens }: { note:
161161
}
162162

163163
function NoteChildren({ note, parentNote, highlightedTokens }: { note: FNote, parentNote: FNote, highlightedTokens: string[] | null | undefined }) {
164-
const imageLinks = note.getRelations("imageLink");
165164
const [ childNotes, setChildNotes ] = useState<FNote[]>();
166165

167166
useEffect(() => {
168-
note.getChildNotes().then(childNotes => {
169-
const filteredChildNotes = childNotes.filter((childNote) => !imageLinks.find((rel) => rel.value === childNote.noteId));
170-
setChildNotes(filteredChildNotes);
171-
});
167+
filterChildNotes(note).then(setChildNotes);
172168
}, [ note ]);
173169

174170
return childNotes?.map(childNote => <ListNoteCard note={childNote} parentNote={parentNote} highlightedTokens={highlightedTokens} />)

apps/client/src/widgets/collections/legacy/ListPrintView.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import { useEffect, useLayoutEffect, useState } from "preact/hooks";
2-
import { RawHtmlBlock } from "../../react/RawHtml";
32
import froca from "../../../services/froca";
43
import type FNote from "../../../entities/fnote";
54
import content_renderer from "../../../services/content_renderer";
65
import type { ViewModeProps } from "../interface";
7-
import { useFilteredNoteIds } from "./utils";
6+
import { filterChildNotes, useFilteredNoteIds } from "./utils";
87

98
interface NotesWithContent {
109
note: FNote;
@@ -13,10 +12,11 @@ interface NotesWithContent {
1312

1413
export function ListPrintView({ note, noteIds: unfilteredNoteIds, onReady }: ViewModeProps<{}>) {
1514
const noteIds = useFilteredNoteIds(note, unfilteredNoteIds);
16-
const noteIdsSet = new Set<string>();
1715
const [ notesWithContent, setNotesWithContent ] = useState<NotesWithContent[]>();
1816

1917
useLayoutEffect(() => {
18+
const noteIdsSet = new Set<string>();
19+
2020
froca.getNotes(noteIds).then(async (notes) => {
2121
const notesWithContent: NotesWithContent[] = [];
2222

@@ -34,9 +34,7 @@ export function ListPrintView({ note, noteIds: unfilteredNoteIds, onReady }: Vie
3434
notesWithContent.push({ note, contentEl });
3535

3636
if (note.hasChildren()) {
37-
const imageLinks = note.getRelations("imageLink");
38-
const childNotes = await note.getChildNotes();
39-
const filteredChildNotes = childNotes.filter((childNote) => !imageLinks.find((rel) => rel.value === childNote.noteId));
37+
const filteredChildNotes = await filterChildNotes(note);
4038
for (const childNote of filteredChildNotes) {
4139
await processNote(childNote, depth + 1);
4240
}
@@ -82,7 +80,7 @@ function insertPageTitle(contentEl: HTMLElement, title: string) {
8280
}
8381

8482
function rewriteHeadings(contentEl: HTMLElement, depth: number) {
85-
const headings = contentEl.querySelectorAll("h1, h2, h3, h4, h5, h6")
83+
const headings = contentEl.querySelectorAll("h1, h2, h3, h4, h5, h6");
8684
for (const headingEl of headings) {
8785
const currentLevel = parseInt(headingEl.tagName.substring(1), 10);
8886
const newLevel = Math.min(currentLevel + depth, 6);

apps/client/src/widgets/collections/legacy/utils.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,12 @@ export function useFilteredNoteIds(note: FNote, noteIds: string[]) {
99
const includedLinks = note ? note.getRelations().filter((rel) => rel.name === "imageLink" || rel.name === "includeNoteLink") : [];
1010
const includedNoteIds = new Set(includedLinks.map((rel) => rel.value));
1111
return noteIds.filter((noteId) => !includedNoteIds.has(noteId) && noteId !== "_hidden");
12-
}, noteIds);
12+
}, [ note, noteIds ]);
13+
}
14+
15+
export async function filterChildNotes(note: FNote) {
16+
const imageLinks = note.getRelations("imageLink");
17+
const imageLinkNoteIds = new Set(imageLinks.map(rel => rel.value));
18+
const childNotes = await note.getChildNotes();
19+
return childNotes.filter((childNote) => !imageLinkNoteIds.has(childNote.noteId));
1320
}

0 commit comments

Comments
 (0)