mirror of
https://github.com/zadam/trilium.git
synced 2025-11-01 03:59:05 +01:00
chore(react/collections): avoid intersection observer when not needed
This commit is contained in:
parent
6e575df40b
commit
34fc30b8db
@ -11,18 +11,23 @@ interface NoteListProps {
|
|||||||
highlightedTokens?: string[] | null;
|
highlightedTokens?: string[] | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function NoteList({ note: providedNote, highlightedTokens }: NoteListProps) {
|
export default function NoteList({ note: providedNote, highlightedTokens, displayOnlyCollections }: NoteListProps) {
|
||||||
const widgetRef = useRef<HTMLDivElement>(null);
|
const widgetRef = useRef<HTMLDivElement>(null);
|
||||||
const { note: contextNote } = useNoteContext();
|
const { note: contextNote, noteContext } = useNoteContext();
|
||||||
const note = providedNote ?? contextNote;
|
const note = providedNote ?? contextNote;
|
||||||
const viewType = useNoteViewType(note);
|
const viewType = useNoteViewType(note);
|
||||||
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);
|
||||||
const isEnabled = (note && !!viewType && shouldRender);
|
const isEnabled = (note && noteContext?.hasNoteList() && !!viewType && shouldRender);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (isFullHeight || displayOnlyCollections) {
|
||||||
|
// 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.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const observer = new IntersectionObserver(
|
const observer = new IntersectionObserver(
|
||||||
(entries) => {
|
(entries) => {
|
||||||
if (!isIntersecting) {
|
if (!isIntersecting) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user