mirror of
https://github.com/Qortal/q-tube.git
synced 2025-02-11 17:55:51 +00:00
Added useIsMobile.ts hook to determine the device type. It is used by videoplayer to more accurately determine which controls to show.
Fixed bug causing playback rate to be different than what the player displays it as (Thanks to Crowetic for noticing this).
This commit is contained in:
parent
26d6494e18
commit
222a7b3b89
@ -5,6 +5,7 @@ import { useEffect } from "react";
|
|||||||
import ReactDOM from "react-dom";
|
import ReactDOM from "react-dom";
|
||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
import { Key } from "ts-key-enum";
|
import { Key } from "ts-key-enum";
|
||||||
|
import { useIsMobile } from "../../../../hooks/useIsMobile.ts";
|
||||||
import { setVideoPlaying } from "../../../../state/features/globalSlice.ts";
|
import { setVideoPlaying } from "../../../../state/features/globalSlice.ts";
|
||||||
import {
|
import {
|
||||||
setReduxPlaybackRate,
|
setReduxPlaybackRate,
|
||||||
@ -39,6 +40,7 @@ export const useVideoControlsState = (
|
|||||||
} = videoPlayerState;
|
} = videoPlayerState;
|
||||||
const { identifier, autoPlay } = props;
|
const { identifier, autoPlay } = props;
|
||||||
|
|
||||||
|
const isMobile = useIsMobile();
|
||||||
const showControlsFullScreen = useSignal(true);
|
const showControlsFullScreen = useSignal(true);
|
||||||
const persistSelector = store.getState().persist;
|
const persistSelector = store.getState().persist;
|
||||||
|
|
||||||
@ -54,7 +56,7 @@ export const useVideoControlsState = (
|
|||||||
if (videoRef.current) {
|
if (videoRef.current) {
|
||||||
if (newSpeed > maxSpeed || newSpeed < minSpeed) newSpeed = minSpeed;
|
if (newSpeed > maxSpeed || newSpeed < minSpeed) newSpeed = minSpeed;
|
||||||
|
|
||||||
videoRef.current.playbackRate = playbackRate.value;
|
videoRef.current.playbackRate = newSpeed;
|
||||||
playbackRate.value = newSpeed;
|
playbackRate.value = newSpeed;
|
||||||
store.dispatch(setReduxPlaybackRate(newSpeed));
|
store.dispatch(setReduxPlaybackRate(newSpeed));
|
||||||
}
|
}
|
||||||
@ -66,15 +68,11 @@ export const useVideoControlsState = (
|
|||||||
? changedSpeed
|
? changedSpeed
|
||||||
: Math.min(changedSpeed, maxSpeed);
|
: Math.min(changedSpeed, maxSpeed);
|
||||||
|
|
||||||
if (videoRef.current) {
|
updatePlaybackRate(newSpeed);
|
||||||
updatePlaybackRate(newSpeed);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const decreaseSpeed = () => {
|
const decreaseSpeed = () => {
|
||||||
if (videoRef.current) {
|
updatePlaybackRate(playbackRate.value - speedChange);
|
||||||
updatePlaybackRate(playbackRate.value - speedChange);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const isFullscreen = useSignal(false);
|
const isFullscreen = useSignal(false);
|
||||||
@ -359,10 +357,7 @@ export const useVideoControlsState = (
|
|||||||
|
|
||||||
useSignalEffect(() => {
|
useSignalEffect(() => {
|
||||||
console.log("canPlay is: ", canPlay.value); // makes the function execute when canPlay changes
|
console.log("canPlay is: ", canPlay.value); // makes the function execute when canPlay changes
|
||||||
const videoWidth = videoRef?.current?.offsetWidth;
|
if (isMobile) isMobileView.value = true;
|
||||||
if (videoWidth && videoWidth <= 600) {
|
|
||||||
isMobileView.value = true;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
21
src/hooks/useIsMobile.ts
Normal file
21
src/hooks/useIsMobile.ts
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import { signal } from "@preact/signals-react";
|
||||||
|
import { useSignals } from "@preact/signals-react/runtime";
|
||||||
|
import { useMemo } from "react";
|
||||||
|
|
||||||
|
const isMobile = signal(false);
|
||||||
|
const isDeviceDetermined = signal(false);
|
||||||
|
|
||||||
|
export const useIsMobile = () => {
|
||||||
|
if (isDeviceDetermined.value) return isMobile.value;
|
||||||
|
|
||||||
|
const userAgent = navigator.userAgent || navigator.vendor;
|
||||||
|
|
||||||
|
isMobile.value =
|
||||||
|
/android/i.test(userAgent) || /iPad|iPhone|iPod/.test(userAgent);
|
||||||
|
|
||||||
|
const deviceTypeText = isMobile.value ? "Mobile Device" : "Desktop";
|
||||||
|
console.log("Running on a", deviceTypeText);
|
||||||
|
|
||||||
|
isDeviceDetermined.value = true;
|
||||||
|
return isMobile.value;
|
||||||
|
};
|
@ -4,6 +4,7 @@ import { Box, Grid, Tab } from "@mui/material";
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import LazyLoad from "../../components/common/LazyLoad";
|
import LazyLoad from "../../components/common/LazyLoad";
|
||||||
import { ListSuperLikeContainer } from "../../components/common/ListSuperLikes/ListSuperLikeContainer.tsx";
|
import { ListSuperLikeContainer } from "../../components/common/ListSuperLikes/ListSuperLikeContainer.tsx";
|
||||||
|
import { fontSizeMedium } from "../../constants/Misc.ts";
|
||||||
import { SearchSidebar } from "./Components/SearchSidebar.tsx";
|
import { SearchSidebar } from "./Components/SearchSidebar.tsx";
|
||||||
import { FiltersCol, VideoManagerRow } from "./Components/VideoList-styles.tsx";
|
import { FiltersCol, VideoManagerRow } from "./Components/VideoList-styles.tsx";
|
||||||
import VideoList from "./Components/VideoList.tsx";
|
import VideoList from "./Components/VideoList.tsx";
|
||||||
@ -23,7 +24,12 @@ export const Home = ({ mode }: HomeProps) => {
|
|||||||
getVideosHandler,
|
getVideosHandler,
|
||||||
} = useHomeState(mode);
|
} = useHomeState(mode);
|
||||||
|
|
||||||
const tabFontSize = "100%";
|
const tabPaneSX = {
|
||||||
|
width: "100%",
|
||||||
|
paddingLeft: "0px",
|
||||||
|
paddingRight: "0px",
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Grid container sx={{ width: "100%" }}>
|
<Grid container sx={{ width: "100%" }}>
|
||||||
@ -56,22 +62,22 @@ export const Home = ({ mode }: HomeProps) => {
|
|||||||
<Tab
|
<Tab
|
||||||
label="All Videos"
|
label="All Videos"
|
||||||
value={"all"}
|
value={"all"}
|
||||||
sx={{ fontSize: tabFontSize }}
|
sx={{ fontSize: fontSizeMedium }}
|
||||||
/>
|
/>
|
||||||
<Tab
|
<Tab
|
||||||
label="Subscriptions"
|
label="Subscriptions"
|
||||||
value={"subscriptions"}
|
value={"subscriptions"}
|
||||||
sx={{ fontSize: tabFontSize }}
|
sx={{ fontSize: fontSizeMedium }}
|
||||||
/>
|
/>
|
||||||
</TabList>
|
</TabList>
|
||||||
<TabPanel value={"all"} sx={{ width: "100%" }}>
|
<TabPanel value={"all"} sx={tabPaneSX}>
|
||||||
<VideoList videos={videos} />
|
<VideoList videos={videos} />
|
||||||
<LazyLoad
|
<LazyLoad
|
||||||
onLoadMore={getVideosHandler}
|
onLoadMore={getVideosHandler}
|
||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
></LazyLoad>
|
></LazyLoad>
|
||||||
</TabPanel>
|
</TabPanel>
|
||||||
<TabPanel value={"subscriptions"} sx={{ width: "100%" }}>
|
<TabPanel value={"subscriptions"} sx={tabPaneSX}>
|
||||||
{filteredSubscriptionList.length > 0 ? (
|
{filteredSubscriptionList.length > 0 ? (
|
||||||
<>
|
<>
|
||||||
<VideoList videos={videos} />
|
<VideoList videos={videos} />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user