feat: torrents modal view for mobile
This commit is contained in:
1 parent
b2e973e09e
commit
c256b7fb7c
4 files changed
+59
-48
No files matched your search
@@ -2,20 +2,21 @@ import { create, InstanceProps } from 'react-modal-promise';
|
|||||||
|
|
||||||
import { Modal } from '@/components/ui/dialog';
|
import { Modal } from '@/components/ui/dialog';
|
||||||
import { Input } from '@/components/ui/input';
|
import { Input } from '@/components/ui/input';
|
||||||
import { useHost, useSetHost } from '@/hooks/useMagnetHosts';
|
import { usePrefix, useSetPrefix } from '@/hooks/useMagnetHosts';
|
||||||
|
|
||||||
const showHostManagerModal = create<InstanceProps<string>>(({ onResolve, onReject }) => {
|
const showHostManagerModal = create<InstanceProps<string>>(({ onResolve, onReject }) => {
|
||||||
const host = useHost();
|
const prefix = usePrefix();
|
||||||
const setHost = useSetHost();
|
const setPrefix = useSetPrefix();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal className='p-2 max-w-[200px] m-auto' onClose={onReject}>
|
<Modal className='p-2 max-w-[200px] m-auto' onClose={onReject}>
|
||||||
<Input
|
<Input
|
||||||
autoFocus
|
autoFocus
|
||||||
placeholder='Enter host of Elementum'
|
placeholder='Enter address of your torrents streamer'
|
||||||
value={host}
|
value={prefix}
|
||||||
className='focus-visible:ring-0'
|
className='focus-visible:ring-0'
|
||||||
onChange={({ target: { value } }) => setHost(value)}
|
onChange={({ target: { value } }) => setPrefix(value)}
|
||||||
onKeyDown={({ key }) => key === 'Enter' && onResolve(host)}
|
onKeyDown={({ key }) => key === 'Enter' && onResolve(prefix)}
|
||||||
/>
|
/>
|
||||||
</Modal>
|
</Modal>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
import React, { Dispatch, FC, SetStateAction, useState } from 'react';
|
import React, { Dispatch, FC, Fragment, SetStateAction, useState } from 'react';
|
||||||
import { create, InstanceProps } from 'react-modal-promise';
|
import { create, InstanceProps } from 'react-modal-promise';
|
||||||
import { ArrowDownIcon, CaretSortIcon } from '@radix-ui/react-icons';
|
import { ArrowDownIcon, CaretSortIcon } from '@radix-ui/react-icons';
|
||||||
import { Cast, Loader, Magnet } from 'lucide-react';
|
import { Cast, Copy,Loader, Magnet } from 'lucide-react';
|
||||||
|
|
||||||
import useTorrents from '@/app/(site)/useTorrents';
|
import useTorrents from '@/app/(site)/useTorrents';
|
||||||
import { Modal } from '@/components/ui/dialog';
|
import { Modal } from '@/components/ui/dialog';
|
||||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table';
|
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table';
|
||||||
import { Toggle } from '@/components/ui/toggle';
|
import { Toggle } from '@/components/ui/toggle';
|
||||||
import { useCastMagnet, useHost, useSetHost } from '@/hooks/useMagnetHosts';
|
import { useCastMagnet, usePrefix } from '@/hooks/useMagnetHosts';
|
||||||
import { ORDER } from '@/lib/api/parsers/pirate-bay';
|
import { ORDER } from '@/lib/api/parsers/pirate-bay';
|
||||||
|
|
||||||
import showHostManagerModal from './HostManager';
|
import showHostManagerModal from './HostManager';
|
||||||
@@ -41,7 +41,7 @@ const TableHeadSortable = ({
|
|||||||
}
|
}
|
||||||
className='cursor-pointer select-none px-2'
|
className='cursor-pointer select-none px-2'
|
||||||
>
|
>
|
||||||
<div className='flex gap-1 items-center justify-center'>
|
<div className='flex gap-1 items-center'>
|
||||||
<span>{title}</span>
|
<span>{title}</span>
|
||||||
{value.by === by ? <ArrowDownIcon className='ml-2 h-4 w-4' /> : <CaretSortIcon className='ml-2 h-4 w-4' />}
|
{value.by === by ? <ArrowDownIcon className='ml-2 h-4 w-4' /> : <CaretSortIcon className='ml-2 h-4 w-4' />}
|
||||||
</div>
|
</div>
|
||||||
@@ -50,7 +50,8 @@ const TableHeadSortable = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const Torrents: FC<Props> = ({ title, year, onResolve }) => {
|
const Torrents: FC<Props> = ({ title, year, onResolve }) => {
|
||||||
const host = useHost();
|
const isMobile = matchMedia('(max-width: 600px)').matches;
|
||||||
|
const prefix = usePrefix();
|
||||||
const [sorting, setSorting] = useState<Sorting>({ by: ORDER.seeders });
|
const [sorting, setSorting] = useState<Sorting>({ by: ORDER.seeders });
|
||||||
const [withYear, setWithYear] = useState(true);
|
const [withYear, setWithYear] = useState(true);
|
||||||
|
|
||||||
@@ -68,7 +69,8 @@ const Torrents: FC<Props> = ({ title, year, onResolve }) => {
|
|||||||
<TableHeader>
|
<TableHeader>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableHead className='px-2' colSpan={4}>
|
<TableHead className='px-2' colSpan={4}>
|
||||||
{title}{' '}
|
<div className='grid grid-cols-[1fr_auto] items-center gap-3'>
|
||||||
|
<span className='overflow-ellipsis overflow-hidden text-base whitespace-nowrap'>{title}</span>
|
||||||
<Toggle
|
<Toggle
|
||||||
size='sm'
|
size='sm'
|
||||||
className='p-2 h-7'
|
className='p-2 h-7'
|
||||||
@@ -77,45 +79,55 @@ const Torrents: FC<Props> = ({ title, year, onResolve }) => {
|
|||||||
>
|
>
|
||||||
{year}
|
{year}
|
||||||
</Toggle>
|
</Toggle>
|
||||||
|
</div>
|
||||||
</TableHead>
|
</TableHead>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableHead className='px-2'>Title</TableHead>
|
{!isMobile && <TableHead className='px-2'>Title</TableHead>}
|
||||||
<TableHeadSortable title='Size' by={ORDER.size} value={sorting} onChange={setSorting} />
|
<TableHeadSortable title='Size' by={ORDER.size} value={sorting} onChange={setSorting} />
|
||||||
<TableHeadSortable title='Seeders' by={ORDER.seeders} value={sorting} onChange={setSorting} />
|
<TableHeadSortable title='Seeders' by={ORDER.seeders} value={sorting} onChange={setSorting} />
|
||||||
<TableHead className='px-2 text-center cursor-pointer select-none' onClick={() => showHostManagerModal()}>
|
<TableHead className='px-2 cursor-pointer select-none' onClick={() => showHostManagerModal()} />
|
||||||
Magnet
|
|
||||||
</TableHead>
|
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{torrents?.map((torrent) => (
|
{torrents?.map((torrent) => (
|
||||||
<TableRow key={torrent.magnet + torrent.id}>
|
<Fragment key={torrent.magnet + torrent.id}>
|
||||||
<TableCell className='break-all p-2'>{torrent.title}</TableCell>
|
{isMobile && (
|
||||||
<TableCell className='p-2'>
|
<TableRow className='border-b-0'>
|
||||||
<div className='flex items-center gap-1 shrink-0 justify-center'>{torrent.size}</div>
|
<TableCell className='break-all p-2' colSpan={4}>
|
||||||
|
{torrent.title}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell className='text-center p-2'>{torrent.seeders}</TableCell>
|
</TableRow>
|
||||||
<TableCell className='text-center p-1'>
|
)}
|
||||||
<div className='flex gap-2 m-auto justify-center'>
|
<TableRow>
|
||||||
{host ? (
|
{!isMobile && <TableCell className='break-all p-2'>{torrent.title}</TableCell>}
|
||||||
<a
|
<TableCell className='p-2'>
|
||||||
onClick={(event) => {
|
<div className='flex items-center gap-1 shrink-0'>{torrent.size}</div>
|
||||||
event.preventDefault();
|
</TableCell>
|
||||||
cast(torrent.magnet!);
|
<TableCell className='p-2'>{torrent.seeders}</TableCell>
|
||||||
}}
|
<TableCell className='text-center p-1 pr-2'>
|
||||||
className='flex items-center justify-center h-8 w-8 border rounded-lg'
|
<div className='flex gap-2 justify-end'>
|
||||||
>
|
|
||||||
<Cast size={20} />
|
|
||||||
</a>
|
|
||||||
) : (
|
|
||||||
<a href={torrent.magnet} className='flex items-center justify-center h-8 w-8 border rounded-lg'>
|
<a href={torrent.magnet} className='flex items-center justify-center h-8 w-8 border rounded-lg'>
|
||||||
<Magnet size={20} />
|
<Magnet size={20} />
|
||||||
</a>
|
</a>
|
||||||
|
<div
|
||||||
|
className='flex items-center justify-center h-8 w-8 border rounded-lg cursor-pointer'
|
||||||
|
onClick={() => navigator.clipboard.writeText(torrent.magnet)}
|
||||||
|
>
|
||||||
|
<Copy size={20} />
|
||||||
|
</div>
|
||||||
|
{prefix && !prefix.includes('{host}') && (
|
||||||
|
<div
|
||||||
|
onClick={() => cast(torrent.magnet!)}
|
||||||
|
className='flex items-center justify-center h-8 w-8 border rounded-lg cursor-pointer'
|
||||||
|
>
|
||||||
|
<Cast size={20} />
|
||||||
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
|
</Fragment>
|
||||||
))}
|
))}
|
||||||
{isLoading && (
|
{isLoading && (
|
||||||
<TableRow>
|
<TableRow>
|
||||||
|
|||||||
@@ -17,11 +17,10 @@ const Trailer: FC<{ trailerKey?: string } & InstanceProps<void>> = ({ trailerKey
|
|||||||
if (!trailerKey) return;
|
if (!trailerKey) return;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal className='block p-0 min-h-[400px] border-none' style={{ aspectRatio: '16/9' }} onClose={onResolve}>
|
<Modal className='block p-0 max-w-[930px] border-none bg-black' style={{ aspectRatio: '16/9' }} onClose={onResolve}>
|
||||||
<iframe
|
<iframe
|
||||||
allow='autoplay'
|
allow='autoplay'
|
||||||
className='border-none rounded-lg'
|
className='border-none rounded-lg'
|
||||||
style={{ aspectRatio: '16/9' }}
|
|
||||||
width='100%'
|
width='100%'
|
||||||
height='100%'
|
height='100%'
|
||||||
src={`//www.youtube.com/embed/${trailerKey}?autoplay=1`}
|
src={`//www.youtube.com/embed/${trailerKey}?autoplay=1`}
|
||||||
|
|||||||
+10
-11
@@ -4,29 +4,28 @@ import { atomWithStorage } from 'jotai/utils';
|
|||||||
|
|
||||||
import showHostManagerModal from '@/components/Movie/components/Torrents/HostManager';
|
import showHostManagerModal from '@/components/Movie/components/Torrents/HostManager';
|
||||||
|
|
||||||
const hostAtom = atomWithStorage<string>('magnet-host', '', undefined, {
|
const magnetPrefixAtom = atomWithStorage<string>('magnet-prefix', 'http://{host}:65220/playuri?uri=', undefined, {
|
||||||
unstable_getOnInit: true
|
unstable_getOnInit: true
|
||||||
});
|
});
|
||||||
|
|
||||||
export const useHost = () => useAtomValue(hostAtom);
|
export const usePrefix = () => useAtomValue(magnetPrefixAtom);
|
||||||
|
|
||||||
export const useSetHost = () => useSetAtom(hostAtom);
|
export const useSetPrefix = () => useSetAtom(magnetPrefixAtom);
|
||||||
|
|
||||||
export const useCastMagnet = () => {
|
export const useCastMagnet = () => {
|
||||||
const hosts = useHost();
|
const prefix = usePrefix();
|
||||||
|
|
||||||
return useCallback(
|
return useCallback(
|
||||||
(magnet: string) => {
|
(magnet: string) => {
|
||||||
const open = (hosts: string) =>
|
const open = (prefix: string) => {
|
||||||
hosts.split(',').forEach((host) => {
|
const link = window.open(`${prefix}${magnet}`, '_blank');
|
||||||
const link = window.open(`http://${host}:65220/playuri?uri=${magnet}`, '_blank');
|
|
||||||
setTimeout(() => link?.close(), 1000);
|
setTimeout(() => link?.close(), 1000);
|
||||||
});
|
};
|
||||||
|
|
||||||
if (!hosts) return showHostManagerModal().then(open);
|
if (!prefix || prefix.includes('{host}')) return showHostManagerModal().then(open);
|
||||||
|
|
||||||
return Promise.resolve(open(hosts));
|
return Promise.resolve(open(prefix));
|
||||||
},
|
},
|
||||||
[hosts]
|
[prefix]
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
Reference in new issue
Block a user