From 22f3eba3466fe168d846bf8f73dbc355810d7a1f Mon Sep 17 00:00:00 2001 From: ner Date: Sun, 13 Oct 2024 13:31:02 +0300 Subject: [PATCH] fix: reduced bundle size --- .../Torrents/components/Player/index.tsx | 67 ++++--------------- components/Show/components/Torrents/index.tsx | 2 +- styles/index.css | 3 + types.d.ts | 1 + 4 files changed, 18 insertions(+), 55 deletions(-) diff --git a/components/Show/components/Torrents/components/Player/index.tsx b/components/Show/components/Torrents/components/Player/index.tsx index 1bc67ab..3eceefd 100644 --- a/components/Show/components/Torrents/components/Player/index.tsx +++ b/components/Show/components/Torrents/components/Player/index.tsx @@ -1,38 +1,26 @@ -'use client'; - -import { useRef, useState } from 'react'; import { create, InstanceProps } from 'react-modal-promise'; -import { MediaPlayer, MediaPlayerInstance, MediaProvider, Poster, Track, VideoSrc } from '@vidstack/react'; -import { defaultLayoutIcons, DefaultVideoLayout } from '@vidstack/react/player/layouts/default'; +import dynamic from 'next/dynamic'; import { Modal } from '@/components/ui/dialog'; import { useToast } from '@/hooks/useToast'; -import { cn } from '@/lib/utils'; -import CaptionsMenu from './components/CaptionsMenu'; -import VideosMenu from './components/VideosMenu'; import useFiles from './useFiles'; -import '@vidstack/react/player/styles/default/theme.css'; -import '@vidstack/react/player/styles/default/layouts/video.css'; +const Player = dynamic(() => import('./Player')); interface Props extends InstanceProps { magnet: string; backdrop: string; + title: string; } -const showPlayer = create(({ onResolve, magnet, backdrop }: Props) => { - const [index, setIndex] = useState(0); - - const player = useRef(null); - +const showPlayer = create(({ onResolve, magnet, backdrop, title }: Props) => { const { data: { subtitles, videos }, - isFetched + isFetched, + isLoading } = useFiles(magnet); - const source = videos[index]; - const { toast } = useToast(); if (isFetched && !videos.length) { @@ -41,42 +29,13 @@ const showPlayer = create(({ onResolve, magnet, backdrop }: Props) => { } return ( - - - - - {subtitles.map((track) => ( - - ))} - - 1) && ( - - ), - afterSettingsMenu: Boolean(subtitles.length) && - }} - /> - + +
+
+ +
+ {isLoading && {title}} +
); }); diff --git a/components/Show/components/Torrents/index.tsx b/components/Show/components/Torrents/index.tsx index 833c063..4976b91 100644 --- a/components/Show/components/Torrents/index.tsx +++ b/components/Show/components/Torrents/index.tsx @@ -125,7 +125,7 @@ const showTorrentsModal = create(({ title, year, imdbID, backdrop, onResolve }: {supportedForStream && (
showPlayer({ magnet: torrent.magnet, backdrop })} + onClick={() => showPlayer({ magnet: torrent.magnet, backdrop, title })} title='Play show' > diff --git a/styles/index.css b/styles/index.css index 8ea8743..f4eec75 100644 --- a/styles/index.css +++ b/styles/index.css @@ -2,6 +2,9 @@ @tailwind components; @tailwind utilities; +@import '@vidstack/react/player/styles/default/theme.css'; +@import '@vidstack/react/player/styles/default/layouts/video.css'; + @layer base { :root { --background: 0 0% 100%; diff --git a/types.d.ts b/types.d.ts index e879456..c50e7ab 100644 --- a/types.d.ts +++ b/types.d.ts @@ -129,6 +129,7 @@ interface Torrent { interface Source { name: string; src: string; + type: string; } interface Subtitles {