From 8016e76a00678ba06d5e4f3114f0c3de7898c9c5 Mon Sep 17 00:00:00 2001 From: qu1ck Date: Thu, 21 Dec 2023 16:52:26 -0800 Subject: [PATCH] Change context menu "Open" and "Open folder" ... to act on last clicked/selected row. They are now enabled even if multiple rows are selected. Fixes issue in filetree table not being able to "open" a folder because selecting it creates a multiple selection including it's child rows. --- src/components/tables/filetreetable.tsx | 14 +++++++++----- src/components/tables/torrenttable.tsx | 9 ++++----- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/components/tables/filetreetable.tsx b/src/components/tables/filetreetable.tsx index 9d4d8a3..8448540 100644 --- a/src/components/tables/filetreetable.tsx +++ b/src/components/tables/filetreetable.tsx @@ -375,10 +375,12 @@ export function FileTreeTable(props: FileTreeTableProps) { else tableRef.current?.setExpanded(false); }, [searchTerms]); + const [current, setCurrent] = useState(""); const { selected, selectedReducer } = useSelected(data, props.fileTree, searchTerms); useEffect(() => { selectedReducer({ verb: "set", ids: [], isReset: true }); + setCurrent(""); }, [props.fileTree.torrenthash, selectedReducer]); const [showFileSearchBox, toggleFileSearchBox] = useReducer((shown: boolean) => { @@ -397,6 +399,7 @@ export function FileTreeTable(props: FileTreeTableProps) { setContextMenuInfo={setInfo} fileTree={props.fileTree} selected={selected} + currentRow={current} onEntryOpen={onEntryOpen} setExpanded={tableRef.current?.setExpanded} toggleFileSearchBox={toggleFileSearchBox} />} @@ -411,6 +414,7 @@ export function FileTreeTable(props: FileTreeTableProps) { getRowId, getSubRows, selectedReducer, + setCurrent, onRowDoubleClick, }} /> @@ -423,18 +427,18 @@ function FiletreeContextMenu(props: { setContextMenuInfo: (i: ContextMenuInfo) => void, fileTree: CachedFileTree, selected: string[], + currentRow: string, onEntryOpen: (rowPath: string, reveal: boolean) => void, setExpanded?: (state: boolean) => void, toggleFileSearchBox: () => void, }) { const { onEntryOpen } = props; const onOpen = useCallback((reveal: boolean) => { - const [path] = props.selected; - const entry = props.fileTree.findEntry(path); + const entry = props.fileTree.findEntry(props.currentRow); if (entry === undefined) return; const rowPath = entry.fullpath + (isDirEntry(entry) ? "/" : ""); onEntryOpen(rowPath, reveal); - }, [onEntryOpen, props.fileTree, props.selected]); + }, [onEntryOpen, props.fileTree, props.currentRow]); const { mutate } = useMutateTorrent(); @@ -496,13 +500,13 @@ function FiletreeContextMenu(props: { { onOpen(false); }} icon={} - disabled={props.selected.length !== 1}> + disabled={props.currentRow === ""}> Open { onOpen(true); }} icon={} - disabled={props.selected.length !== 1}> + disabled={props.currentRow === ""}> Open folder diff --git a/src/components/tables/torrenttable.tsx b/src/components/tables/torrenttable.tsx index 034051e..1f06965 100644 --- a/src/components/tables/torrenttable.tsx +++ b/src/components/tables/torrenttable.tsx @@ -462,11 +462,10 @@ function TorrentContextMenu(props: { const { onRowDoubleClick } = props; const onOpen = useCallback((reveal: boolean) => { - const [id] = [...serverSelected]; - const torrent = serverData.torrents.find((t) => t.id === id); + const torrent = serverData.torrents.find((t) => t.id === serverData.current); if (torrent === undefined) return; onRowDoubleClick(torrent, reveal); - }, [onRowDoubleClick, serverData.torrents, serverSelected]); + }, [onRowDoubleClick, serverData]); const mutate = useTorrentAction(); @@ -593,14 +592,14 @@ function TorrentContextMenu(props: { onClick={() => { onOpen(false); }} onMouseEnter={closeQueueSubmenu} icon={} - disabled={serverSelected.size !== 1}> + disabled={serverData.current === undefined}> Open { onOpen(true); }} onMouseEnter={closeQueueSubmenu} icon={} - disabled={serverSelected.size !== 1}> + disabled={serverData.current === undefined}> Open folder