import { Box, Collapse, Fade } from "@mui/material"; import { ChevronRight, ExpandMore } from "@mui/icons-material"; import { TreeView } from "@mui/x-tree-view"; import React, { useEffect } from "react"; import { TransitionGroup } from "react-transition-group"; import { defaultPath, defaultSharedWithMePath, defaultTrashPath } from "../../../hooks/useNavigation.tsx"; import { useAppSelector } from "../../../redux/hooks.ts"; import SessionManager, { UserSettings } from "../../../session"; import CrUri, { Filesystem } from "../../../util/uri.ts"; import { FileManagerIndex } from "../FileManager.tsx"; import { FmIndexContext } from "../FmIndexContext.tsx"; import Pinned, { usePinned } from "./Pinned.tsx"; import TreeFiles from "./TreeFiles.tsx"; export interface TreeNavigationProps { scrollRef?: React.MutableRefObject; index?: number; hideWithDrawer?: boolean; disableSharedWithMe?: boolean; disableTrash?: boolean; } const TreeNavigation = React.memo( ({ index = 0, scrollRef, hideWithDrawer, disableSharedWithMe, disableTrash }: TreeNavigationProps) => { const base = useAppSelector((s) => s.fileManager[index].path_root); const path = useAppSelector((s) => s.fileManager[index].pure_path_with_category); const currentFs = useAppSelector((s) => s.fileManager[index].current_fs); const elements = useAppSelector((s) => s.fileManager[index].path_elements); const drawerOpen = useAppSelector((s) => s.globalState.drawerOpen); const [expanded, setExpanded] = React.useState([]); useEffect(() => { const res: string[] = []; if (path) { const p = new CrUri(path); if (p.is_search()) { return; } } if (base && elements) { const b = new CrUri(base); res.push(base); elements.forEach((element) => { b.join(element); res.push(b.toString()); }); } if (SessionManager.getWithFallback(UserSettings.TreeViewAutoExpand)) { setExpanded((e) => [...new Set([...e, ...res])]); } }, [path, base, elements]); const pinned = usePinned(); const alreadyPinned = base && pinned && pinned.find((p) => p.uri == base); const showShareTree = base && currentFs && currentFs == Filesystem.share && !alreadyPinned; useEffect(() => { if (showShareTree && scrollRef && scrollRef.current) { scrollRef.current?.scrollTo({ top: 0, behavior: "smooth" }); } }, [showShareTree]); const isLogin = !!SessionManager.currentLoginOrNull(); return ( } defaultExpandIcon={} expanded={expanded} onNodeToggle={(_event, nodeIds: string[]) => { setExpanded(nodeIds); }} > {showShareTree && ( )} {isLogin && ( <> {index == FileManagerIndex.main && ( <> )} {!disableSharedWithMe && ( )} {!disableTrash && ( )} )} ); }, ); export default TreeNavigation;