diff --git a/src/components/details.tsx b/src/components/details.tsx index 75fd06f..806087f 100644 --- a/src/components/details.tsx +++ b/src/components/details.tsx @@ -33,6 +33,8 @@ import { CachedFileTree } from "cachedfiletree"; import { useFileTree, useMutateTorrent, useSessionStats, useTorrentDetails } from "queries"; import { ConfigContext } from "config"; import { useResizeObserver } from "@mantine/hooks"; +import { MemoSectionsContextMenu, getSectionsMap } from "./sectionscontextmenu"; +import { useContextMenu } from "./contextmenu"; interface DetailsProps { torrentId?: number, @@ -382,32 +384,32 @@ function ServerStats() { const DetailsPanels = React.memo(function DetailsPanels({ torrent }: { torrent: Torrent | undefined }) { return (<> - + {torrent !== undefined ? : <>} - + {torrent !== undefined ? : <>} - + {torrent !== undefined ? : <>} - + {torrent !== undefined ? : <>} - + {torrent !== undefined ? : <>} - + ); @@ -428,46 +430,71 @@ function Details(props: DetailsProps) { else if (fetchedTorrent !== undefined) setTorrent(fetchedTorrent); }, [fetchedTorrent, props.torrentId]); + const [tabs, setTabs] = useState(config.values.interface.detailsTabs); + const [tabsMap, setTabsMap] = useState(getSectionsMap(tabs)); + + useEffect(() => { + config.values.interface.detailsTabs = tabs; + setTabsMap(getSectionsMap(tabs)); + }, [config, tabs]); + + const defaultTab = useMemo(() => { + return tabs.find((tab) => tab.visible)?.section ?? ""; + }, [tabs]); + + const [info, setInfo, handler] = useContextMenu(); + return ( - - - - - - General - - - - - - {`Files${torrent !== undefined ? ` (${torrent.files.length as number})` : ""}`} - - - - - - {`Pieces${torrent !== undefined ? ` (${torrent.pieceCount as number})` : ""}`} - - - - - - Peers - - - - - - Trackers - - - - - - Server statistics - - + + + {tabs[tabsMap.General].visible && + + + + General + + } + {tabs[tabsMap.Files].visible && + + + + {`Files${torrent !== undefined ? ` (${torrent.files.length as number})` : ""}`} + + } + {tabs[tabsMap.Pieces].visible && + + + + {`Pieces${torrent !== undefined ? ` (${torrent.pieceCount as number})` : ""}`} + + } + {tabs[tabsMap.Peers].visible && + + + + Peers + + } + {tabs[tabsMap.Trackers].visible && + + + + Trackers + + } + {tabs[tabsMap[""]].visible && + "] }} />} + {tabs[tabsMap["Server statistics"]].visible && + + + + Server statistics + + }
", "Server statistics", +] as const; +type DetailsSectionsName = typeof DetailsSections[number]; + export type SectionsVisibility = Array<{ section: S, visible: boolean, @@ -137,6 +142,7 @@ interface Settings { statusBarSections: SectionsVisibility, showFiltersPanel: boolean, showDetailsPanel: boolean, + detailsTabs: SectionsVisibility, showFilesSearchBox: boolean, mainSplit: SplitType, skipAddDialog: boolean, @@ -242,6 +248,10 @@ const DefaultSettings: Settings = { })), showFiltersPanel: true, showDetailsPanel: true, + detailsTabs: DetailsSections.map((section) => ({ + section, + visible: true, + })), showFilesSearchBox: false, mainSplit: "vertical", skipAddDialog: false,