mirror of
https://github.com/zadam/trilium.git
synced 2025-11-21 16:14:23 +01:00
refactor(collections): fix typecheck and remove generics
This commit is contained in:
parent
88ae996694
commit
ec76e9cf2a
@ -1,6 +1,6 @@
|
|||||||
import FNote from "./entities/fnote";
|
import FNote from "./entities/fnote";
|
||||||
import { render } from "preact";
|
import { render } from "preact";
|
||||||
import { CustomNoteList } from "./widgets/collections/NoteList";
|
import { CustomNoteList, useNoteViewType } from "./widgets/collections/NoteList";
|
||||||
import { useCallback, useLayoutEffect, useRef } from "preact/hooks";
|
import { useCallback, useLayoutEffect, useRef } from "preact/hooks";
|
||||||
import content_renderer from "./services/content_renderer";
|
import content_renderer from "./services/content_renderer";
|
||||||
|
|
||||||
@ -85,7 +85,9 @@ function SingleNoteRenderer({ note, onReady }: RendererProps) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function CollectionRenderer({ note, onReady }: RendererProps) {
|
function CollectionRenderer({ note, onReady }: RendererProps) {
|
||||||
|
const viewType = useNoteViewType(note);
|
||||||
return <CustomNoteList
|
return <CustomNoteList
|
||||||
|
viewType={viewType}
|
||||||
isEnabled
|
isEnabled
|
||||||
note={note}
|
note={note}
|
||||||
notePath={note.getBestNotePath().join("/")}
|
notePath={note.getBestNotePath().join("/")}
|
||||||
|
|||||||
@ -27,7 +27,7 @@ interface NoteListProps {
|
|||||||
onReady?: () => void;
|
onReady?: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function NoteList<T extends object>(props: Pick<NoteListProps, "displayOnlyCollections" | "media" | "onReady">) {
|
export default function NoteList(props: Pick<NoteListProps, "displayOnlyCollections" | "media" | "onReady">) {
|
||||||
const { note, noteContext, notePath, ntxId } = useNoteContext();
|
const { note, noteContext, notePath, ntxId } = useNoteContext();
|
||||||
const viewType = useNoteViewType(note);
|
const viewType = useNoteViewType(note);
|
||||||
const [ enabled, setEnabled ] = useState(noteContext?.hasNoteList());
|
const [ enabled, setEnabled ] = useState(noteContext?.hasNoteList());
|
||||||
@ -37,12 +37,12 @@ export default function NoteList<T extends object>(props: Pick<NoteListProps, "d
|
|||||||
return <CustomNoteList viewType={viewType} note={note} isEnabled={!!enabled} notePath={notePath} ntxId={ntxId} {...props} />
|
return <CustomNoteList viewType={viewType} note={note} isEnabled={!!enabled} notePath={notePath} ntxId={ntxId} {...props} />
|
||||||
}
|
}
|
||||||
|
|
||||||
export function SearchNoteList<T extends object>(props: Omit<NoteListProps, "isEnabled">) {
|
export function SearchNoteList(props: Omit<NoteListProps, "isEnabled" | "viewType">) {
|
||||||
const viewType = useNoteViewType(props.note);
|
const viewType = useNoteViewType(props.note);
|
||||||
return <CustomNoteList {...props} isEnabled={true} viewType={viewType} />
|
return <CustomNoteList {...props} isEnabled={true} viewType={viewType} />
|
||||||
}
|
}
|
||||||
|
|
||||||
export function CustomNoteList<T extends object>({ note, viewType, isEnabled: shouldEnable, notePath, highlightedTokens, displayOnlyCollections, ntxId, onReady, ...restProps }: NoteListProps) {
|
export function CustomNoteList({ note, viewType, isEnabled: shouldEnable, notePath, highlightedTokens, displayOnlyCollections, ntxId, onReady, ...restProps }: NoteListProps) {
|
||||||
const widgetRef = useRef<HTMLDivElement>(null);
|
const widgetRef = useRef<HTMLDivElement>(null);
|
||||||
const noteIds = useNoteIds(shouldEnable ? note : null, viewType, ntxId);
|
const noteIds = useNoteIds(shouldEnable ? note : null, viewType, ntxId);
|
||||||
const isFullHeight = (viewType && viewType !== "list" && viewType !== "grid");
|
const isFullHeight = (viewType && viewType !== "list" && viewType !== "grid");
|
||||||
@ -119,7 +119,7 @@ function getComponentByViewType(viewType: ViewTypeOptions, props: ViewModeProps<
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function useNoteViewType(note?: FNote | null): ViewTypeOptions | undefined {
|
export function useNoteViewType(note?: FNote | null): ViewTypeOptions | undefined {
|
||||||
const [ viewType ] = useNoteLabel(note, "viewType");
|
const [ viewType ] = useNoteLabel(note, "viewType");
|
||||||
|
|
||||||
if (!note) {
|
if (!note) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user