Skip to content

Commit

Permalink
Open the download dialog when clicking on the name of a torrent (#8132)
Browse files Browse the repository at this point in the history
  • Loading branch information
egbertbouman authored Sep 5, 2024
2 parents c756295 + afed184 commit 8f13391
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
17 changes: 11 additions & 6 deletions src/tribler/ui/src/pages/Popular/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import SimpleTable from "@/components/ui/simple-table";
import SaveAs from "@/dialogs/SaveAs";
import { useState } from "react";
import { useCallback, useMemo, useState } from "react";
import { triblerService } from "@/services/tribler.service";
import { Torrent } from "@/models/torrent.model";
import { ColumnDef } from "@tanstack/react-table";
Expand All @@ -9,7 +9,7 @@ import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/comp
import { useInterval } from '@/hooks/useInterval';


const torrentColumns: ColumnDef<Torrent>[] = [
const getColumns = ({ onDownload }: { onDownload: (torrent: Torrent) => void }): ColumnDef<Torrent>[] => [
{
accessorKey: "category",
header: "",
Expand All @@ -30,7 +30,11 @@ const torrentColumns: ColumnDef<Torrent>[] = [
accessorKey: "name",
header: translateHeader('Name'),
cell: ({ row }) => {
return <span className="line-clamp-1">{row.original.name}</span>
return <span
className="inline-block cursor-pointer hover:underline line-clamp-1"
onClick={() => onDownload(row.original)}>
{row.original.name}
</span>
},
},
{
Expand Down Expand Up @@ -59,10 +63,12 @@ export default function Popular() {
setTorrents(filterDuplicates(popular, 'infohash'));
}, 5000, true);

const OnDoubleClick = (torrent: Torrent) => {
const handleDownload = useCallback((torrent: Torrent) => {
setTorrentDoubleClicked(torrent);
setOpen(true);
}
}, []);

const torrentColumns = useMemo(() => getColumns({ onDownload: handleDownload }), [handleDownload]);

return (
<>
Expand All @@ -79,7 +85,6 @@ export default function Popular() {
<SimpleTable
data={torrents}
columns={torrentColumns}
onRowDoubleClick={(torrent) => { if (torrent) { OnDoubleClick(torrent) } }}
/>
</>
)
Expand Down
17 changes: 11 additions & 6 deletions src/tribler/ui/src/pages/Search/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import SimpleTable from "@/components/ui/simple-table";
import { useEffect, useState } from "react";
import { useCallback, useEffect, useMemo, useState } from "react";
import { triblerService } from "@/services/tribler.service";
import { Torrent } from "@/models/torrent.model";
import { ColumnDef } from "@tanstack/react-table";
Expand All @@ -10,7 +10,7 @@ import { useSearchParams } from "react-router-dom";
import { SwarmHealth } from "@/components/swarm-health";


const torrentColumns: ColumnDef<Torrent>[] = [
const getColumns = ({ onDownload }: { onDownload: (torrent: Torrent) => void }): ColumnDef<Torrent>[] => [
{
accessorKey: "category",
header: "",
Expand All @@ -31,7 +31,11 @@ const torrentColumns: ColumnDef<Torrent>[] = [
accessorKey: "name",
header: "Name",
cell: ({ row }) => {
return <span className="line-clamp-1">{row.original.name}</span>
return <span
className="inline-block cursor-pointer hover:underline line-clamp-1"
onClick={() => onDownload(row.original)}>
{row.original.name}
</span>
},
},
{
Expand Down Expand Up @@ -116,10 +120,12 @@ export default function Search() {
}
}

const OnDoubleClick = (torrent: Torrent) => {
const handleDownload = useCallback((torrent: Torrent) => {
setTorrentDoubleClicked(torrent);
setOpen(true);
}
}, []);

const torrentColumns = useMemo(() => getColumns({ onDownload: handleDownload }), [handleDownload]);

return (
<>
Expand All @@ -136,7 +142,6 @@ export default function Search() {
<SimpleTable
data={torrents}
columns={torrentColumns}
onRowDoubleClick={(torrent) => { if (torrent) { OnDoubleClick(torrent) } }}
/>
</>
)
Expand Down

0 comments on commit 8f13391

Please sign in to comment.