1
0
Fork 0
mirror of https://github.com/sussy-code/smov.git synced 2024-12-21 14:47:41 +01:00

first load spinner

This commit is contained in:
Jelle van Snik 2023-01-14 00:27:40 +01:00
parent a64841507f
commit 4d07751a4a
4 changed files with 17 additions and 1 deletions

View file

@ -4,7 +4,9 @@ import { useVideoPlayerState } from "../VideoContext";
export function LoadingControl() { export function LoadingControl() {
const { videoState } = useVideoPlayerState(); const { videoState } = useVideoPlayerState();
if (!videoState.isLoading) return null; const isLoading = videoState.isFirstLoading || videoState.isLoading;
if (!isLoading) return null;
return <Spinner />; return <Spinner />;
} }

View file

@ -12,6 +12,7 @@ export function MiddlePauseControl() {
if (videoState.hasPlayedOnce) return null; if (videoState.hasPlayedOnce) return null;
if (videoState.isPlaying) return null; if (videoState.isPlaying) return null;
if (videoState.isFirstLoading) return null;
return ( return (
<div <div

View file

@ -13,6 +13,7 @@ export type PlayerState = {
isPaused: boolean; isPaused: boolean;
isSeeking: boolean; isSeeking: boolean;
isLoading: boolean; isLoading: boolean;
isFirstLoading: boolean;
isFullscreen: boolean; isFullscreen: boolean;
time: number; time: number;
duration: number; duration: number;
@ -32,6 +33,7 @@ export const initialPlayerState: PlayerContext = {
isFullscreen: false, isFullscreen: false,
isLoading: false, isLoading: false,
isSeeking: false, isSeeking: false,
isFirstLoading: true,
time: 0, time: 0,
duration: 0, duration: 0,
volume: 0, volume: 0,
@ -64,6 +66,7 @@ function readState(player: HTMLVideoElement, update: SetPlayer) {
...state, ...state,
pausedWhenSeeking: s.pausedWhenSeeking, pausedWhenSeeking: s.pausedWhenSeeking,
hasPlayedOnce: s.hasPlayedOnce, hasPlayedOnce: s.hasPlayedOnce,
isFirstLoading: s.isFirstLoading,
})); }));
} }
@ -122,6 +125,12 @@ function registerListeners(player: HTMLVideoElement, update: SetPlayer) {
buffered: handleBuffered(player.currentTime, player.buffered), buffered: handleBuffered(player.currentTime, player.buffered),
})); }));
}; };
const canplay = () => {
update((s) => ({
...s,
isFirstLoading: false,
}));
};
player.addEventListener("pause", pause); player.addEventListener("pause", pause);
player.addEventListener("playing", playing); player.addEventListener("playing", playing);
@ -133,6 +142,7 @@ function registerListeners(player: HTMLVideoElement, update: SetPlayer) {
player.addEventListener("volumechange", volumechange); player.addEventListener("volumechange", volumechange);
player.addEventListener("progress", progress); player.addEventListener("progress", progress);
player.addEventListener("waiting", waiting); player.addEventListener("waiting", waiting);
player.addEventListener("canplay", canplay);
return () => { return () => {
player.removeEventListener("pause", pause); player.removeEventListener("pause", pause);
@ -145,6 +155,7 @@ function registerListeners(player: HTMLVideoElement, update: SetPlayer) {
player.removeEventListener("volumechange", volumechange); player.removeEventListener("volumechange", volumechange);
player.removeEventListener("progress", progress); player.removeEventListener("progress", progress);
player.removeEventListener("waiting", waiting); player.removeEventListener("waiting", waiting);
player.removeEventListener("canplay", canplay);
}; };
} }

View file

@ -52,6 +52,8 @@ export function SearchResultsView({ searchQuery }: { searchQuery: MWQuery }) {
); );
useEffect(() => { useEffect(() => {
// TODO use cache
// TODO run immediately without debounce on mount
async function runSearch(query: MWQuery) { async function runSearch(query: MWQuery) {
const searchResults = await runSearchQuery(query); const searchResults = await runSearchQuery(query);
if (!searchResults) return; if (!searchResults) return;