mirror of
https://github.com/zadam/trilium.git
synced 2025-11-21 16:14:23 +01:00
chore(print/list): address review
This commit is contained in:
parent
049721bbfe
commit
be115c74c3
@ -11,7 +11,7 @@ import tree from "../../../services/tree";
|
|||||||
import link from "../../../services/link";
|
import link from "../../../services/link";
|
||||||
import { t } from "../../../services/i18n";
|
import { t } from "../../../services/i18n";
|
||||||
import attribute_renderer from "../../../services/attribute_renderer";
|
import attribute_renderer from "../../../services/attribute_renderer";
|
||||||
import { useFilteredNoteIds } from "./utils";
|
import { filterChildNotes, useFilteredNoteIds } from "./utils";
|
||||||
|
|
||||||
export function ListView({ note, noteIds: unfilteredNoteIds, highlightedTokens }: ViewModeProps<{}>) {
|
export function ListView({ note, noteIds: unfilteredNoteIds, highlightedTokens }: ViewModeProps<{}>) {
|
||||||
const [ isExpanded ] = useNoteLabelBoolean(note, "expanded");
|
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 }) {
|
function NoteChildren({ note, parentNote, highlightedTokens }: { note: FNote, parentNote: FNote, highlightedTokens: string[] | null | undefined }) {
|
||||||
const imageLinks = note.getRelations("imageLink");
|
|
||||||
const [ childNotes, setChildNotes ] = useState<FNote[]>();
|
const [ childNotes, setChildNotes ] = useState<FNote[]>();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
note.getChildNotes().then(childNotes => {
|
filterChildNotes(note).then(setChildNotes);
|
||||||
const filteredChildNotes = childNotes.filter((childNote) => !imageLinks.find((rel) => rel.value === childNote.noteId));
|
|
||||||
setChildNotes(filteredChildNotes);
|
|
||||||
});
|
|
||||||
}, [ note ]);
|
}, [ note ]);
|
||||||
|
|
||||||
return childNotes?.map(childNote => <ListNoteCard note={childNote} parentNote={parentNote} highlightedTokens={highlightedTokens} />)
|
return childNotes?.map(childNote => <ListNoteCard note={childNote} parentNote={parentNote} highlightedTokens={highlightedTokens} />)
|
||||||
|
|||||||
@ -1,10 +1,9 @@
|
|||||||
import { useEffect, useLayoutEffect, useState } from "preact/hooks";
|
import { useEffect, useLayoutEffect, useState } from "preact/hooks";
|
||||||
import { RawHtmlBlock } from "../../react/RawHtml";
|
|
||||||
import froca from "../../../services/froca";
|
import froca from "../../../services/froca";
|
||||||
import type FNote from "../../../entities/fnote";
|
import type FNote from "../../../entities/fnote";
|
||||||
import content_renderer from "../../../services/content_renderer";
|
import content_renderer from "../../../services/content_renderer";
|
||||||
import type { ViewModeProps } from "../interface";
|
import type { ViewModeProps } from "../interface";
|
||||||
import { useFilteredNoteIds } from "./utils";
|
import { filterChildNotes, useFilteredNoteIds } from "./utils";
|
||||||
|
|
||||||
interface NotesWithContent {
|
interface NotesWithContent {
|
||||||
note: FNote;
|
note: FNote;
|
||||||
@ -13,10 +12,11 @@ interface NotesWithContent {
|
|||||||
|
|
||||||
export function ListPrintView({ note, noteIds: unfilteredNoteIds, onReady }: ViewModeProps<{}>) {
|
export function ListPrintView({ note, noteIds: unfilteredNoteIds, onReady }: ViewModeProps<{}>) {
|
||||||
const noteIds = useFilteredNoteIds(note, unfilteredNoteIds);
|
const noteIds = useFilteredNoteIds(note, unfilteredNoteIds);
|
||||||
const noteIdsSet = new Set<string>();
|
|
||||||
const [ notesWithContent, setNotesWithContent ] = useState<NotesWithContent[]>();
|
const [ notesWithContent, setNotesWithContent ] = useState<NotesWithContent[]>();
|
||||||
|
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
|
const noteIdsSet = new Set<string>();
|
||||||
|
|
||||||
froca.getNotes(noteIds).then(async (notes) => {
|
froca.getNotes(noteIds).then(async (notes) => {
|
||||||
const notesWithContent: NotesWithContent[] = [];
|
const notesWithContent: NotesWithContent[] = [];
|
||||||
|
|
||||||
@ -34,9 +34,7 @@ export function ListPrintView({ note, noteIds: unfilteredNoteIds, onReady }: Vie
|
|||||||
notesWithContent.push({ note, contentEl });
|
notesWithContent.push({ note, contentEl });
|
||||||
|
|
||||||
if (note.hasChildren()) {
|
if (note.hasChildren()) {
|
||||||
const imageLinks = note.getRelations("imageLink");
|
const filteredChildNotes = await filterChildNotes(note);
|
||||||
const childNotes = await note.getChildNotes();
|
|
||||||
const filteredChildNotes = childNotes.filter((childNote) => !imageLinks.find((rel) => rel.value === childNote.noteId));
|
|
||||||
for (const childNote of filteredChildNotes) {
|
for (const childNote of filteredChildNotes) {
|
||||||
await processNote(childNote, depth + 1);
|
await processNote(childNote, depth + 1);
|
||||||
}
|
}
|
||||||
@ -82,7 +80,7 @@ function insertPageTitle(contentEl: HTMLElement, title: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function rewriteHeadings(contentEl: HTMLElement, depth: number) {
|
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) {
|
for (const headingEl of headings) {
|
||||||
const currentLevel = parseInt(headingEl.tagName.substring(1), 10);
|
const currentLevel = parseInt(headingEl.tagName.substring(1), 10);
|
||||||
const newLevel = Math.min(currentLevel + depth, 6);
|
const newLevel = Math.min(currentLevel + depth, 6);
|
||||||
|
|||||||
@ -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 includedLinks = note ? note.getRelations().filter((rel) => rel.name === "imageLink" || rel.name === "includeNoteLink") : [];
|
||||||
const includedNoteIds = new Set(includedLinks.map((rel) => rel.value));
|
const includedNoteIds = new Set(includedLinks.map((rel) => rel.value));
|
||||||
return noteIds.filter((noteId) => !includedNoteIds.has(noteId) && noteId !== "_hidden");
|
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));
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user