chore(print/list): address review

This commit is contained in:
Elian Doran 2025-11-20 21:42:50 +02:00
parent 049721bbfe
commit be115c74c3
No known key found for this signature in database
3 changed files with 15 additions and 14 deletions

View File

@ -11,7 +11,7 @@ import tree from "../../../services/tree";
import link from "../../../services/link";
import { t } from "../../../services/i18n";
import attribute_renderer from "../../../services/attribute_renderer";
import { useFilteredNoteIds } from "./utils";
import { filterChildNotes, useFilteredNoteIds } from "./utils";
export function ListView({ note, noteIds: unfilteredNoteIds, highlightedTokens }: ViewModeProps<{}>) {
const [ isExpanded ] = useNoteLabelBoolean(note, "expanded");
@ -161,14 +161,10 @@ function NoteContent({ note, trim, noChildrenList, highlightedTokens }: { note:
}
function NoteChildren({ note, parentNote, highlightedTokens }: { note: FNote, parentNote: FNote, highlightedTokens: string[] | null | undefined }) {
const imageLinks = note.getRelations("imageLink");
const [ childNotes, setChildNotes ] = useState<FNote[]>();
useEffect(() => {
note.getChildNotes().then(childNotes => {
const filteredChildNotes = childNotes.filter((childNote) => !imageLinks.find((rel) => rel.value === childNote.noteId));
setChildNotes(filteredChildNotes);
});
filterChildNotes(note).then(setChildNotes);
}, [ note ]);
return childNotes?.map(childNote => <ListNoteCard note={childNote} parentNote={parentNote} highlightedTokens={highlightedTokens} />)

View File

@ -1,10 +1,9 @@
import { useEffect, useLayoutEffect, useState } from "preact/hooks";
import { RawHtmlBlock } from "../../react/RawHtml";
import froca from "../../../services/froca";
import type FNote from "../../../entities/fnote";
import content_renderer from "../../../services/content_renderer";
import type { ViewModeProps } from "../interface";
import { useFilteredNoteIds } from "./utils";
import { filterChildNotes, useFilteredNoteIds } from "./utils";
interface NotesWithContent {
note: FNote;
@ -13,10 +12,11 @@ interface NotesWithContent {
export function ListPrintView({ note, noteIds: unfilteredNoteIds, onReady }: ViewModeProps<{}>) {
const noteIds = useFilteredNoteIds(note, unfilteredNoteIds);
const noteIdsSet = new Set<string>();
const [ notesWithContent, setNotesWithContent ] = useState<NotesWithContent[]>();
useLayoutEffect(() => {
const noteIdsSet = new Set<string>();
froca.getNotes(noteIds).then(async (notes) => {
const notesWithContent: NotesWithContent[] = [];
@ -34,9 +34,7 @@ export function ListPrintView({ note, noteIds: unfilteredNoteIds, onReady }: Vie
notesWithContent.push({ note, contentEl });
if (note.hasChildren()) {
const imageLinks = note.getRelations("imageLink");
const childNotes = await note.getChildNotes();
const filteredChildNotes = childNotes.filter((childNote) => !imageLinks.find((rel) => rel.value === childNote.noteId));
const filteredChildNotes = await filterChildNotes(note);
for (const childNote of filteredChildNotes) {
await processNote(childNote, depth + 1);
}
@ -82,7 +80,7 @@ function insertPageTitle(contentEl: HTMLElement, title: string) {
}
function rewriteHeadings(contentEl: HTMLElement, depth: number) {
const headings = contentEl.querySelectorAll("h1, h2, h3, h4, h5, h6")
const headings = contentEl.querySelectorAll("h1, h2, h3, h4, h5, h6");
for (const headingEl of headings) {
const currentLevel = parseInt(headingEl.tagName.substring(1), 10);
const newLevel = Math.min(currentLevel + depth, 6);

View File

@ -9,5 +9,12 @@ export function useFilteredNoteIds(note: FNote, noteIds: string[]) {
const includedLinks = note ? note.getRelations().filter((rel) => rel.name === "imageLink" || rel.name === "includeNoteLink") : [];
const includedNoteIds = new Set(includedLinks.map((rel) => rel.value));
return noteIds.filter((noteId) => !includedNoteIds.has(noteId) && noteId !== "_hidden");
}, noteIds);
}, [ note, noteIds ]);
}
export async function filterChildNotes(note: FNote) {
const imageLinks = note.getRelations("imageLink");
const imageLinkNoteIds = new Set(imageLinks.map(rel => rel.value));
const childNotes = await note.getChildNotes();
return childNotes.filter((childNote) => !imageLinkNoteIds.has(childNote.noteId));
}