Skip to content

Commit

Permalink
kinda all over the place, these changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
sphinxrave committed Dec 2, 2023
1 parent daac6f2 commit dd54d02
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
3 changes: 3 additions & 0 deletions packages/react/src/components/video/VideoCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ export function VideoCard({
>
<Link
to={videoHref}
state={{ video: videoObject }}
target={videoTarget}
onClick={
onInfoClick
Expand Down Expand Up @@ -350,6 +351,7 @@ export function VideoCard({
<Link
to={videoHref}
target={videoTarget}
state={{ video: videoObject }}
className="relative w-full"
onClick={
onThumbnailClick
Expand Down Expand Up @@ -401,6 +403,7 @@ export function VideoCard({
<Link
className="line-clamp-2 pr-4 text-sm font-bold md:text-[1rem] md:leading-6"
to={videoHref}
state={{ video: videoObject }}
target={videoTarget}
onClick={
onInfoClick
Expand Down
30 changes: 22 additions & 8 deletions packages/react/src/routes/watch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,9 @@ export default function Watch() {
const chatPos = useAtomValue(chatPosAtom);
const [ref, bounds] = useMeasure({ debounce: 50, scroll: false });

const isTwitch = location.state?.isTwitch ?? data?.link?.includes("twitch");

// Preload video frames for better experience
useLayoutEffect(() => {
const videoPlaceholder: QueueVideo = {
const videoPlaceholder: QueueVideo = location.state.video ?? {
id: id!,
url: `https://youtu.be/${id}`,
channel_id: "",
Expand All @@ -76,6 +74,11 @@ export default function Watch() {
type: "vtuber",
},
};
videoPlaceholder.url =
location.state?.video?.link?.includes("twitch") ??
data?.link?.includes("twitch")
? location.state.video?.link
: `https://youtu.be/${id}`;
setMiniPlayer(false);
setCurrentVideo(videoPlaceholder);
if (queue.length)
Expand All @@ -95,14 +98,25 @@ export default function Watch() {
if (isSuccess) {
setCurrentVideo({
...data,
url: isTwitch ? data.link : `https://youtu.be/${id}`,
url:
location.state?.video?.link?.includes("twitch") ??
data?.link?.includes("twitch")
? data.link
: `https://youtu.be/${id}`,
});
if (queue.length)
setQueue((q) =>
q.toSpliced(
q.findIndex((q) => q.id === id),
1,
{ ...data, url: isTwitch ? data.link : `https://youtu.be/${id}` },
{
...data,
url:
location.state?.video?.link?.includes("twitch") ??
data?.link?.includes("twitch")
? data.link
: `https://youtu.be/${id}`,
},
),
);
}
Expand Down Expand Up @@ -146,23 +160,23 @@ export default function Watch() {
)}
</div>
)}
{data && <Controlbar {...data} />}
{currentVideo && <Controlbar {...(data ?? currentVideo)} />}
</div>
<div
className={cn("flex flex-col gap-1", {
"px-4 @screen-lg:px-8 py-4": theaterMode,
})}
>
<h2 className="text-xl font-bold">{data?.title}</h2>
{data && <PlayerStats {...data} />}
{currentVideo && <PlayerStats {...(data ?? currentVideo)} />}
</div>
<div
className={cn("flex flex-col gap-4", {
"px-4 @screen-lg:px-8 pb-8": theaterMode,
})}
>
{channel && <ChannelCard size="xs" {...channel} />}
{!isTwitch && data?.description && (
{!data?.link?.includes("twitch") && data?.description && (
<PlayerDescription description={data.description} />
)}
<div className="flex @screen-lg:hidden">
Expand Down

0 comments on commit dd54d02

Please sign in to comment.