Skip to content

Commit

Permalink
player restyled
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-jamming-reilly committed May 7, 2024
1 parent b35dee1 commit df0efa8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ If you are not familiar with the different technologies used in this project, pl

interested in contributing?

- join the [discord](https://discord.gg/uW7rqs6Q)
- join the [discord](https://discord.gg/ykXpmAb7kU)

or reach out to me via:

Expand Down
16 changes: 9 additions & 7 deletions src/components/Player.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import YouTube, { YouTubeProps } from "react-youtube";
import { useParentSizeObserver } from "~/hooks/useParentSize";
import { Drawer, DrawerContent } from "~/components/ui/drawer";
import { ScrollArea } from "~/components/ui/scroll-area";
import { useIsMobile } from "~/hooks/useIsMobile";
import { useScreenDimensions } from "~/hooks/useIsMobile";
import { api } from "~/trpc/react";
import { cn } from "~/lib/utils";
import { SearchItem, DummySearchItemList } from "~/components/SearchItem";
Expand Down Expand Up @@ -37,6 +37,7 @@ function SimilarVideos({
start: start,
end: end,
author,
explore: false,
});

const similarFromOthers = api.video.similar.useQuery({
Expand Down Expand Up @@ -173,7 +174,8 @@ export function Player() {
}
};

const isMobile = useIsMobile();
const dimensions = useScreenDimensions();
const isMobile = dimensions.isMobile;

return (
<Drawer onClose={onClose} open={isOpen}>
Expand All @@ -185,7 +187,7 @@ export function Player() {
)}
>
<ScrollArea className="h-full overflow-auto">
<div className="mx-auto w-fit">
<div className="justify-center mx-auto w-fit">
{video && (
<YouTube
key={`${video.id}-${start}-${end}`}
Expand All @@ -195,8 +197,8 @@ export function Player() {
loading="lazy"
onStateChange={onStateChange}
opts={{
width: isMobile ? 380 : width,
height: isMobile ? hwRatio * 380 : height,
width: isMobile ? dimensions.width - 12 : width,
height: isMobile ? hwRatio * (dimensions.width - 12) : height,
playerVars: {
// https://developers.google.com/youtube/player_parameters#Parameters
color: "white",
Expand All @@ -210,8 +212,8 @@ export function Player() {
)}
{start && end && video && (
<div
style={{ width: isMobile ? 380 : width }}
className=" flex-1 flex my-4"
style={{ width: isMobile ? dimensions.width - 10 : width }}
className=" flex-1 flex my-4 "
>
<SimilarVideos
author={video.author}
Expand Down
10 changes: 7 additions & 3 deletions src/hooks/useIsMobile.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import { useState, useEffect } from "react";

export function useIsMobile() {
export function useScreenDimensions() {
const [width, setWidth] = useState<number>(window.innerWidth);
const [height, setHeight] = useState<number>(window.innerHeight);
const isMobile = width <= 768;

function handleWindowSizeChange() {
setWidth(window.innerWidth);
setHeight(window.innerHeight);
}

useEffect(() => {
window.addEventListener("resize", handleWindowSizeChange);
return () => {
window.removeEventListener("resize", handleWindowSizeChange);
};
}, []);
const isMobile = width <= 768;
return isMobile;

return { width, height, isMobile };
}

0 comments on commit df0efa8

Please sign in to comment.