mirror of
https://github.com/zadam/trilium.git
synced 2025-11-06 21:36:05 +01:00
chore(react/collections): display books even if collections only
This commit is contained in:
@@ -7,6 +7,7 @@ import { useEffect, useRef, useState } from "preact/hooks";
|
|||||||
|
|
||||||
interface NoteListProps {
|
interface NoteListProps {
|
||||||
note?: FNote | null;
|
note?: FNote | null;
|
||||||
|
/** if set to `true` then only collection-type views are displayed such as geo-map and the calendar. The original book types grid and list will be ignored. */
|
||||||
displayOnlyCollections?: boolean;
|
displayOnlyCollections?: boolean;
|
||||||
highlightedTokens?: string[] | null;
|
highlightedTokens?: string[] | null;
|
||||||
}
|
}
|
||||||
@@ -19,12 +20,12 @@ export default function NoteList({ note: providedNote, highlightedTokens, displa
|
|||||||
const noteIds = useNoteIds(note, viewType);
|
const noteIds = useNoteIds(note, viewType);
|
||||||
const isFullHeight = (viewType !== "list" && viewType !== "grid");
|
const isFullHeight = (viewType !== "list" && viewType !== "grid");
|
||||||
const [ isIntersecting, setIsIntersecting ] = useState(false);
|
const [ isIntersecting, setIsIntersecting ] = useState(false);
|
||||||
const shouldRender = (isFullHeight || isIntersecting);
|
const shouldRender = (isFullHeight || isIntersecting || note?.type === "book");
|
||||||
const isEnabled = (note && noteContext?.hasNoteList() && !!viewType && shouldRender);
|
const isEnabled = (note && noteContext?.hasNoteList() && !!viewType && shouldRender);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isFullHeight || displayOnlyCollections) {
|
if (isFullHeight || displayOnlyCollections || note?.type === "book") {
|
||||||
// Double role: no need to check if the note list is visible if the view is full-height, but also prevent legacy views if `displayOnlyCollections` is true.
|
// Double role: no need to check if the note list is visible if the view is full-height or book, but also prevent legacy views if `displayOnlyCollections` is true.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,27 +10,6 @@ export default class NoteListWidget extends NoteContextAwareWidget {
|
|||||||
private noteIdRefreshed?: string;
|
private noteIdRefreshed?: string;
|
||||||
private shownNoteId?: string | null;
|
private shownNoteId?: string | null;
|
||||||
private viewMode?: ViewMode<any> | null;
|
private viewMode?: ViewMode<any> | null;
|
||||||
private displayOnlyCollections: boolean;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param displayOnlyCollections if set to `true` then only collection-type views are displayed such as geo-map and the calendar. The original book types grid and list will be ignored.
|
|
||||||
*/
|
|
||||||
constructor(displayOnlyCollections: boolean) {
|
|
||||||
super();
|
|
||||||
|
|
||||||
this.displayOnlyCollections = displayOnlyCollections;
|
|
||||||
}
|
|
||||||
|
|
||||||
isEnabled() {
|
|
||||||
if (this.displayOnlyCollections && this.note?.type !== "book") {
|
|
||||||
const viewType = this.note?.getLabelValue("viewType");
|
|
||||||
if (!viewType || ["grid", "list"].includes(viewType)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.noteContext?.hasNoteList();
|
|
||||||
}
|
|
||||||
|
|
||||||
async refreshNoteListEvent({ noteId }: EventData<"refreshNoteList">) {
|
async refreshNoteListEvent({ noteId }: EventData<"refreshNoteList">) {
|
||||||
if (this.isNote(noteId) && this.note) {
|
if (this.isNote(noteId) && this.note) {
|
||||||
|
|||||||
Reference in New Issue
Block a user