refactor(torrents): move pin into row actions
Move the pin toggle out of the title cell into the row's action buttons (next to play) and drop the hover-reveal animation, so the title column stays clean. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
461ff51721
commit
526f0c24e0
2 files changed
+17
-39
No files matched your search
+10
-2
@@ -1,5 +1,5 @@
|
|||||||
import { FC, useEffect, useMemo, useState } from 'react';
|
import { FC, useEffect, useMemo, useState } from 'react';
|
||||||
import { Cast, Download, ListVideo, Loader, Magnet, Play, TrafficCone } from 'lucide-react';
|
import { Bookmark, Cast, Download, ListVideo, Loader, Magnet, Play, TrafficCone } from 'lucide-react';
|
||||||
|
|
||||||
import { providers } from '@/components/Preview/components/Torrents/constants';
|
import { providers } from '@/components/Preview/components/Torrents/constants';
|
||||||
import { useCastMagnet, usePrefix } from '@/components/Preview/components/Torrents/hooks/useMagnetHosts';
|
import { useCastMagnet, usePrefix } from '@/components/Preview/components/Torrents/hooks/useMagnetHosts';
|
||||||
@@ -45,7 +45,7 @@ const Actions: FC<Props> = ({ torrent, title, provider, show }) => {
|
|||||||
|
|
||||||
const fetchMagnet = useMagnet(torrent);
|
const fetchMagnet = useMagnet(torrent);
|
||||||
|
|
||||||
const { pin, isPinned, savedMagnet, rememberMagnet } = usePinnedTorrents();
|
const { pin, toggle, isPinned, savedMagnet, rememberMagnet } = usePinnedTorrents();
|
||||||
|
|
||||||
const key = torrentKey(torrent);
|
const key = torrentKey(torrent);
|
||||||
const pinned = isPinned(key);
|
const pinned = isPinned(key);
|
||||||
@@ -115,6 +115,14 @@ const Actions: FC<Props> = ({ torrent, title, provider, show }) => {
|
|||||||
<Play size={15} />
|
<Play size={15} />
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
|
<Button
|
||||||
|
variant='outline'
|
||||||
|
className='grow-0 px-3'
|
||||||
|
onClick={() => toggle(key)}
|
||||||
|
title={pinned ? 'Unpin' : 'Pin to top'}
|
||||||
|
>
|
||||||
|
<Bookmark size={16} className={cn(pinned && 'fill-current')} />
|
||||||
|
</Button>
|
||||||
<Button variant='outline' className='relative grow-0 px-3' title='Download m3u playlist'>
|
<Button variant='outline' className='relative grow-0 px-3' title='Download m3u playlist'>
|
||||||
<a
|
<a
|
||||||
className='absolute left-0 top-0 size-full'
|
className='absolute left-0 top-0 size-full'
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { FC, Fragment, MouseEvent, useState } from 'react';
|
import { FC, Fragment, useState } from 'react';
|
||||||
import { ArrowDownIcon, Bookmark } from 'lucide-react';
|
import { ArrowDownIcon } from 'lucide-react';
|
||||||
|
|
||||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table';
|
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table';
|
||||||
import { Sort } from '@/data/parsers';
|
import { Sort } from '@/data/parsers';
|
||||||
@@ -35,7 +35,7 @@ const TorrentsTable: FC<Props> = ({ title, torrents, show, sort, sortable, provi
|
|||||||
|
|
||||||
const [episodesSort, setEpisodesSort] = useState<EpisodesSort | null>(null);
|
const [episodesSort, setEpisodesSort] = useState<EpisodesSort | null>(null);
|
||||||
|
|
||||||
const { isPinned, toggle } = usePinnedTorrents();
|
const { isPinned } = usePinnedTorrents();
|
||||||
|
|
||||||
const sorted = episodesSort
|
const sorted = episodesSort
|
||||||
? [...torrents].sort((a, b) => {
|
? [...torrents].sort((a, b) => {
|
||||||
@@ -53,30 +53,6 @@ const TorrentsTable: FC<Props> = ({ title, torrents, show, sort, sortable, provi
|
|||||||
...sorted.filter((torrent) => !isPinned(torrentKey(torrent)))
|
...sorted.filter((torrent) => !isPinned(torrentKey(torrent)))
|
||||||
];
|
];
|
||||||
|
|
||||||
const renderPin = (torrent: Torrent, mobile?: boolean) => {
|
|
||||||
const pinned = isPinned(torrentKey(torrent));
|
|
||||||
const onClick = (event: MouseEvent) => {
|
|
||||||
event.stopPropagation();
|
|
||||||
toggle(torrentKey(torrent));
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<button
|
|
||||||
type='button'
|
|
||||||
onClick={onClick}
|
|
||||||
aria-label={pinned ? 'Unpin torrent' : 'Pin torrent to top'}
|
|
||||||
className={cn(
|
|
||||||
'flex shrink-0 items-center overflow-hidden text-muted-foreground transition-all duration-200 hover:text-foreground',
|
|
||||||
pinned || mobile
|
|
||||||
? 'w-5 opacity-100'
|
|
||||||
: 'w-5 opacity-100 [@media(hover:hover)]:w-0 [@media(hover:hover)]:opacity-0 [@media(hover:hover)]:group-hover:w-5 [@media(hover:hover)]:group-hover:opacity-100'
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<Bookmark className={cn('size-4', pinned && 'fill-current')} />
|
|
||||||
</button>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
// server sort (size/seeds) refetches in a new order, so drop the client-side S:E sort
|
// server sort (size/seeds) refetches in a new order, so drop the client-side S:E sort
|
||||||
const handleChangeSort = (next: Sort) => {
|
const handleChangeSort = (next: Sort) => {
|
||||||
setEpisodesSort(null);
|
setEpisodesSort(null);
|
||||||
@@ -128,22 +104,16 @@ const TorrentsTable: FC<Props> = ({ title, torrents, show, sort, sortable, provi
|
|||||||
return (
|
return (
|
||||||
<Fragment key={torrent.magnet + torrent.id + torrent.download}>
|
<Fragment key={torrent.magnet + torrent.id + torrent.download}>
|
||||||
<TableRow className='table-row border-b-0 hover:bg-transparent md:hidden'>
|
<TableRow className='table-row border-b-0 hover:bg-transparent md:hidden'>
|
||||||
<TableCell className='p-2' colSpan={colSpan}>
|
<TableCell className='break-all p-2' colSpan={colSpan}>
|
||||||
<span className='flex w-full flex-wrap items-center gap-1'>
|
<span className='flex w-full flex-wrap items-center gap-3'>
|
||||||
{renderPin(torrent, true)}
|
|
||||||
<span className='break-all'>
|
|
||||||
{torrent.title} {isSeries && torrent.episodes && `[${torrent.episodes}]`}{' '}
|
{torrent.title} {isSeries && torrent.episodes && `[${torrent.episodes}]`}{' '}
|
||||||
{torrent.quality && `[${torrent.quality}]`}
|
{torrent.quality && `[${torrent.quality}]`}
|
||||||
</span>
|
</span>
|
||||||
</span>
|
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
<TableRow className='group hover:bg-transparent'>
|
<TableRow className='hover:bg-transparent'>
|
||||||
<TableCell className='hidden break-all p-2 md:table-cell' title={torrent.originalTitle}>
|
<TableCell className='hidden break-all p-2 md:table-cell' title={torrent.originalTitle}>
|
||||||
<span className='flex items-center'>
|
{torrent.title}
|
||||||
{renderPin(torrent)}
|
|
||||||
<span className='break-all'>{torrent.title}</span>
|
|
||||||
</span>
|
|
||||||
</TableCell>
|
</TableCell>
|
||||||
{isSeries && (
|
{isSeries && (
|
||||||
<TableCell className='hidden p-2 md:table-cell'>
|
<TableCell className='hidden p-2 md:table-cell'>
|
||||||
|
|||||||
Reference in new issue
Block a user