Skip to content

Commit

Permalink
Change context menu "Open" and "Open folder"
Browse files Browse the repository at this point in the history
... 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.
  • Loading branch information
qu1ck committed Dec 22, 2023
1 parent 20501c0 commit 8016e76
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
14 changes: 9 additions & 5 deletions src/components/tables/filetreetable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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} />}
Expand All @@ -411,6 +414,7 @@ export function FileTreeTable(props: FileTreeTableProps) {
getRowId,
getSubRows,
selectedReducer,
setCurrent,
onRowDoubleClick,
}} />
</div>
Expand All @@ -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();

Expand Down Expand Up @@ -496,13 +500,13 @@ function FiletreeContextMenu(props: {
<Menu.Item
onClick={() => { onOpen(false); }}
icon={<Icon.BoxArrowUpRight size="1.1rem" />}
disabled={props.selected.length !== 1}>
disabled={props.currentRow === ""}>
<Text weight="bold">Open</Text>
</Menu.Item>
<Menu.Item
onClick={() => { onOpen(true); }}
icon={<Icon.Folder2Open size="1.1rem" />}
disabled={props.selected.length !== 1}>
disabled={props.currentRow === ""}>
<Text>Open folder</Text>
</Menu.Item>
<Menu.Divider />
Expand Down
9 changes: 4 additions & 5 deletions src/components/tables/torrenttable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -593,14 +592,14 @@ function TorrentContextMenu(props: {
onClick={() => { onOpen(false); }}
onMouseEnter={closeQueueSubmenu}
icon={<Icon.BoxArrowUpRight size="1.1rem" />}
disabled={serverSelected.size !== 1}>
disabled={serverData.current === undefined}>
<Text weight="bold">Open</Text>
</Menu.Item>
<Menu.Item
onClick={() => { onOpen(true); }}
onMouseEnter={closeQueueSubmenu}
icon={<Icon.Folder2Open size="1.1rem" />}
disabled={serverSelected.size !== 1}>
disabled={serverData.current === undefined}>
<Text>Open folder</Text>
</Menu.Item>
<Menu.Divider />
Expand Down

0 comments on commit 8016e76

Please sign in to comment.