mirror of
https://github.com/zadam/trilium.git
synced 2025-12-15 12:49:53 +01:00
lint: note paths
This commit is contained in:
@@ -1,12 +1,13 @@
|
|||||||
import { TabContext } from "./ribbon-interface";
|
import { useEffect, useMemo, useState } from "preact/hooks";
|
||||||
|
|
||||||
|
import FNote, { NotePathRecord } from "../../entities/fnote";
|
||||||
import { t } from "../../services/i18n";
|
import { t } from "../../services/i18n";
|
||||||
|
import { NOTE_PATH_TITLE_SEPARATOR } from "../../services/tree";
|
||||||
import Button from "../react/Button";
|
import Button from "../react/Button";
|
||||||
import { useTriliumEvent } from "../react/hooks";
|
import { useTriliumEvent } from "../react/hooks";
|
||||||
import { useEffect, useMemo, useState } from "preact/hooks";
|
|
||||||
import FNote, { NotePathRecord } from "../../entities/fnote";
|
|
||||||
import NoteLink from "../react/NoteLink";
|
import NoteLink from "../react/NoteLink";
|
||||||
import { joinElements } from "../react/react_utils";
|
import { joinElements } from "../react/react_utils";
|
||||||
import { NOTE_PATH_TITLE_SEPARATOR } from "../../services/tree";
|
import { TabContext } from "./ribbon-interface";
|
||||||
|
|
||||||
export default function NotePathsTab({ note, hoistedNoteId, notePath }: TabContext) {
|
export default function NotePathsTab({ note, hoistedNoteId, notePath }: TabContext) {
|
||||||
const sortedNotePaths = useSortedNotePaths(note, hoistedNoteId);
|
const sortedNotePaths = useSortedNotePaths(note, hoistedNoteId);
|
||||||
@@ -21,6 +22,7 @@ export default function NotePathsTab({ note, hoistedNoteId, notePath }: TabConte
|
|||||||
<ul className="note-path-list">
|
<ul className="note-path-list">
|
||||||
{sortedNotePaths?.length ? sortedNotePaths.map(sortedNotePath => (
|
{sortedNotePaths?.length ? sortedNotePaths.map(sortedNotePath => (
|
||||||
<NotePath
|
<NotePath
|
||||||
|
key={sortedNotePath.notePath}
|
||||||
currentNotePath={notePath}
|
currentNotePath={notePath}
|
||||||
notePathRecord={sortedNotePath}
|
notePathRecord={sortedNotePath}
|
||||||
/>
|
/>
|
||||||
@@ -33,7 +35,7 @@ export default function NotePathsTab({ note, hoistedNoteId, notePath }: TabConte
|
|||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
</div>
|
</div>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useSortedNotePaths(note: FNote | null | undefined, hoistedNoteId?: string) {
|
export function useSortedNotePaths(note: FNote | null | undefined, hoistedNoteId?: string) {
|
||||||
@@ -46,7 +48,7 @@ export function useSortedNotePaths(note: FNote | null | undefined, hoistedNoteId
|
|||||||
.filter((notePath) => !notePath.isHidden));
|
.filter((notePath) => !notePath.isHidden));
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(refresh, [ note?.noteId ]);
|
useEffect(refresh, [ note, hoistedNoteId ]);
|
||||||
useTriliumEvent("entitiesReloaded", ({ loadResults }) => {
|
useTriliumEvent("entitiesReloaded", ({ loadResults }) => {
|
||||||
const noteId = note?.noteId;
|
const noteId = note?.noteId;
|
||||||
if (!noteId) return;
|
if (!noteId) return;
|
||||||
@@ -60,8 +62,8 @@ export function useSortedNotePaths(note: FNote | null | undefined, hoistedNoteId
|
|||||||
}
|
}
|
||||||
|
|
||||||
function NotePath({ currentNotePath, notePathRecord }: { currentNotePath?: string | null, notePathRecord?: NotePathRecord }) {
|
function NotePath({ currentNotePath, notePathRecord }: { currentNotePath?: string | null, notePathRecord?: NotePathRecord }) {
|
||||||
const notePath = notePathRecord?.notePath ?? [];
|
const notePath = notePathRecord?.notePath;
|
||||||
const notePathString = useMemo(() => notePath.join("/"), [ notePath ]);
|
const notePathString = useMemo(() => (notePath ?? []).join("/"), [ notePath ]);
|
||||||
|
|
||||||
const [ classes, icons ] = useMemo(() => {
|
const [ classes, icons ] = useMemo(() => {
|
||||||
const classes: string[] = [];
|
const classes: string[] = [];
|
||||||
@@ -74,17 +76,17 @@ function NotePath({ currentNotePath, notePathRecord }: { currentNotePath?: strin
|
|||||||
if (!notePathRecord || notePathRecord.isInHoistedSubTree) {
|
if (!notePathRecord || notePathRecord.isInHoistedSubTree) {
|
||||||
classes.push("path-in-hoisted-subtree");
|
classes.push("path-in-hoisted-subtree");
|
||||||
} else {
|
} else {
|
||||||
icons.push({ icon: "bx bx-trending-up", title: t("note_paths.outside_hoisted") })
|
icons.push({ icon: "bx bx-trending-up", title: t("note_paths.outside_hoisted") });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (notePathRecord?.isArchived) {
|
if (notePathRecord?.isArchived) {
|
||||||
classes.push("path-archived");
|
classes.push("path-archived");
|
||||||
icons.push({ icon: "bx bx-archive", title: t("note_paths.archived") })
|
icons.push({ icon: "bx bx-archive", title: t("note_paths.archived") });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (notePathRecord?.isSearch) {
|
if (notePathRecord?.isSearch) {
|
||||||
classes.push("path-search");
|
classes.push("path-search");
|
||||||
icons.push({ icon: "bx bx-search", title: t("note_paths.search") })
|
icons.push({ icon: "bx bx-search", title: t("note_paths.search") });
|
||||||
}
|
}
|
||||||
|
|
||||||
return [ classes.join(" "), icons ];
|
return [ classes.join(" "), icons ];
|
||||||
@@ -93,7 +95,7 @@ function NotePath({ currentNotePath, notePathRecord }: { currentNotePath?: strin
|
|||||||
// Determine the full note path (for the links) of every component of the current note path.
|
// Determine the full note path (for the links) of every component of the current note path.
|
||||||
const pathSegments: string[] = [];
|
const pathSegments: string[] = [];
|
||||||
const fullNotePaths: string[] = [];
|
const fullNotePaths: string[] = [];
|
||||||
for (const noteId of notePath) {
|
for (const noteId of notePath ?? []) {
|
||||||
pathSegments.push(noteId);
|
pathSegments.push(noteId);
|
||||||
fullNotePaths.push(pathSegments.join("/"));
|
fullNotePaths.push(pathSegments.join("/"));
|
||||||
}
|
}
|
||||||
@@ -101,12 +103,12 @@ function NotePath({ currentNotePath, notePathRecord }: { currentNotePath?: strin
|
|||||||
return (
|
return (
|
||||||
<li class={classes}>
|
<li class={classes}>
|
||||||
{joinElements(fullNotePaths.map(notePath => (
|
{joinElements(fullNotePaths.map(notePath => (
|
||||||
<NoteLink notePath={notePath} noPreview />
|
<NoteLink key={notePath} notePath={notePath} noPreview />
|
||||||
)), NOTE_PATH_TITLE_SEPARATOR)}
|
)), NOTE_PATH_TITLE_SEPARATOR)}
|
||||||
|
|
||||||
{icons.map(({ icon, title }) => (
|
{icons.map(({ icon, title }) => (
|
||||||
<span class={icon} title={title} />
|
<span key={title} class={icon} title={title} />
|
||||||
))}
|
))}
|
||||||
</li>
|
</li>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user