Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open the download dialog when clicking on the name of a torrent #8132

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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