From 17e18fb6f9e9fe3b96261c0351277045a9ce4ff0 Mon Sep 17 00:00:00 2001 From: enigma0Z Date: Tue, 10 Dec 2024 16:54:04 -0500 Subject: [PATCH] Fix broken tests/refs with refactor of mediastore --- components/AudioPlayer.js | 32 +++--- components/NativeShellWebView.js | 18 +-- components/VideoPlayer.js | 32 +++--- .../__snapshots__/VideoPlayer.test.js.snap | 2 +- hooks/useStores.js | 2 + screens/DownloadScreen.js | 8 +- screens/HomeScreen.js | 30 ++--- screens/__tests__/HomeScreen.test.js | 6 +- stores/MediaStore.js | 86 -------------- stores/MediaStore.ts | 66 +++++++++++ stores/RootStore.ts | 4 - stores/__tests__/MediaStore.test.js | 107 ++++++++++-------- stores/__tests__/RootStore.test.js | 8 +- 13 files changed, 194 insertions(+), 207 deletions(-) delete mode 100644 stores/MediaStore.js create mode 100644 stores/MediaStore.ts diff --git a/components/AudioPlayer.js b/components/AudioPlayer.js index a5a478d54..8ec8aef54 100644 --- a/components/AudioPlayer.js +++ b/components/AudioPlayer.js @@ -13,7 +13,7 @@ import { useStores } from '../hooks/useStores'; import { msToTicks } from '../utils/Time'; const AudioPlayer = observer(() => { - const { rootStore } = useStores(); + const { mediaStore } = useStores(); const [ player, setPlayer ] = useState(); @@ -57,46 +57,46 @@ const AudioPlayer = observer(() => { didJustFinish === undefined || isPlaying === undefined || positionMs === undefined || - rootStore.mediaStore.isFinished + mediaStore.isFinished ) { return; } - rootStore.mediaStore.isFinished = didJustFinish; - rootStore.mediaStore.isPlaying = isPlaying; - rootStore.mediaStore.positionTicks = msToTicks(positionMs); + mediaStore.isFinished = didJustFinish; + mediaStore.isPlaying = isPlaying; + mediaStore.positionTicks = msToTicks(positionMs); }); setPlayer(sound); } }; - if (rootStore.mediaStore.type === MediaTypes.Audio) { + if (mediaStore.type === MediaTypes.Audio) { createPlayer({ - uri: rootStore.mediaStore.uri, - positionMillis: rootStore.mediaStore.positionMillis + uri: mediaStore.uri, + positionMillis: mediaStore.positionMillis }); } - }, [ rootStore.mediaStore.type, rootStore.mediaStore.uri ]); + }, [ mediaStore.type, mediaStore.uri ]); // Update the play/pause state when the store indicates it should useEffect(() => { - if (rootStore.mediaStore.type === MediaTypes.Audio && rootStore.mediaStore.shouldPlayPause) { - if (rootStore.mediaStore.isPlaying) { + if (mediaStore.type === MediaTypes.Audio && mediaStore.shouldPlayPause) { + if (mediaStore.isPlaying) { player?.pauseAsync(); } else { player?.playAsync(); } - rootStore.mediaStore.shouldPlayPause = false; + mediaStore.shouldPlayPause = false; } - }, [ rootStore.mediaStore.shouldPlayPause ]); + }, [ mediaStore.shouldPlayPause ]); // Stop the player when the store indicates it should stop playback useEffect(() => { - if (rootStore.mediaStore.type === MediaTypes.Audio && rootStore.mediaStore.shouldStop) { + if (mediaStore.type === MediaTypes.Audio && mediaStore.shouldStop) { player?.stopAsync(); player?.unloadAsync(); - rootStore.mediaStore.shouldStop = false; + mediaStore.shouldStop = false; } - }, [ rootStore.mediaStore.shouldStop ]); + }, [ mediaStore.shouldStop ]); return <>; }); diff --git a/components/NativeShellWebView.js b/components/NativeShellWebView.js index efde0c0d0..887c8d760 100644 --- a/components/NativeShellWebView.js +++ b/components/NativeShellWebView.js @@ -23,7 +23,7 @@ import RefreshWebView from './RefreshWebView'; const NativeShellWebView = observer( function NativeShellWebView(props, ref) { - const { rootStore, downloadStore, serverStore } = useStores(); + const { rootStore, downloadStore, serverStore, mediaStore } = useStores(); const [ isRefreshing, setIsRefreshing ] = useState(false); const server = serverStore.servers[rootStore.settingStore.activeServer]; @@ -70,7 +70,7 @@ true; if (rootStore.isFullscreen) return; // Stop media playback in native players - rootStore.mediaStore.shouldStop = true; + mediaStore.shouldStop = true; setIsRefreshing(true); ref.current?.reload(); @@ -124,19 +124,19 @@ true; break; case 'ExpoAudioPlayer.play': case 'ExpoVideoPlayer.play': - rootStore.mediaStore.type = event === 'ExpoAudioPlayer.play' ? MediaTypes.Audio : MediaTypes.Video; - rootStore.mediaStore.uri = data.url; - rootStore.mediaStore.backdropUri = data.backdropUrl; - rootStore.mediaStore.isFinished = false; - rootStore.mediaStore.positionTicks = data.playerStartPositionTicks; + mediaStore.type = event === 'ExpoAudioPlayer.play' ? MediaTypes.Audio : MediaTypes.Video; + mediaStore.uri = data.url; + mediaStore.backdropUri = data.backdropUrl; + mediaStore.isFinished = false; + mediaStore.positionTicks = data.playerStartPositionTicks; break; case 'ExpoAudioPlayer.playPause': case 'ExpoVideoPlayer.playPause': - rootStore.mediaStore.shouldPlayPause = true; + mediaStore.shouldPlayPause = true; break; case 'ExpoAudioPlayer.stop': case 'ExpoVideoPlayer.stop': - rootStore.mediaStore.shouldStop = true; + mediaStore.shouldStop = true; break; case 'console.debug': // console.debug('[Browser Console]', data); diff --git a/components/VideoPlayer.js b/components/VideoPlayer.js index f8d2a9e95..2a92a744a 100644 --- a/components/VideoPlayer.js +++ b/components/VideoPlayer.js @@ -13,7 +13,7 @@ import { useStores } from '../hooks/useStores'; import { msToTicks } from '../utils/Time'; const VideoPlayer = observer(() => { - const { rootStore } = useStores(); + const { rootStore, mediaStore } = useStores(); const player = useRef(null); // Local player fullscreen state @@ -31,37 +31,37 @@ const VideoPlayer = observer(() => { // Update the player when media type or uri changes useEffect(() => { - if (rootStore.mediaStore.type === MediaTypes.Video) { + if (mediaStore.type === MediaTypes.Video) { rootStore.didPlayerCloseManually = true; player.current?.loadAsync({ - uri: rootStore.mediaStore.uri + uri: mediaStore.uri }, { - positionMillis: rootStore.mediaStore.positionMillis, + positionMillis: mediaStore.positionMillis, shouldPlay: true }); } - }, [ rootStore.mediaStore.type, rootStore.mediaStore.uri ]); + }, [ mediaStore.type, mediaStore.uri ]); // Update the play/pause state when the store indicates it should useEffect(() => { - if (rootStore.mediaStore.type === MediaTypes.Video && rootStore.mediaStore.shouldPlayPause) { - if (rootStore.mediaStore.isPlaying) { + if (mediaStore.type === MediaTypes.Video && mediaStore.shouldPlayPause) { + if (mediaStore.isPlaying) { player.current?.pauseAsync(); } else { player.current?.playAsync(); } - rootStore.mediaStore.shouldPlayPause = false; + mediaStore.shouldPlayPause = false; } - }, [ rootStore.mediaStore.shouldPlayPause ]); + }, [ mediaStore.shouldPlayPause ]); // Close the player when the store indicates it should stop playback useEffect(() => { - if (rootStore.mediaStore.type === MediaTypes.Video && rootStore.mediaStore.shouldStop) { + if (mediaStore.type === MediaTypes.Video && mediaStore.shouldStop) { rootStore.didPlayerCloseManually = false; closeFullscreen(); - rootStore.mediaStore.shouldStop = false; + mediaStore.shouldStop = false; } - }, [ rootStore.mediaStore.shouldStop ]); + }, [ mediaStore.shouldStop ]); const openFullscreen = () => { if (!isPresenting) { @@ -86,7 +86,7 @@ const VideoPlayer = observer(() => {