diff --git a/src/main/reset.ts b/src/main/reset.ts index 40ecc210..e2383f3c 100644 --- a/src/main/reset.ts +++ b/src/main/reset.ts @@ -27,7 +27,7 @@ export const resetSettings = () => { export const resetApp = () => { // Sonic announcement sounds.play('RESET'); - + // Notification notification({ title: $init.resetApp, diff --git a/src/renderer/context/library-context.tsx b/src/renderer/context/library-context.tsx index dcabcc0d..b4a11989 100644 --- a/src/renderer/context/library-context.tsx +++ b/src/renderer/context/library-context.tsx @@ -2,7 +2,6 @@ import { ipcChannels } from '@/config/ipc-channels'; import { CollectionStoreType, LibraryStoreType } from '@/main/store'; import { RANDOM_LIBRARY_DELAY } from '@/renderer/config/config'; import { CollectionType, LibraryType } from '@/types/media'; -import { debounce } from '@/utils/debounce'; import React, { createContext, useCallback, @@ -43,6 +42,7 @@ export function LibraryContextProvider({ const [genres, setGenres] = useState({}); const [playlists, setPlaylists] = useState({}); const [randomLibraryArray, setRandomLibraryArray] = useState([]); + const [shouldShuffle, setShouldShuffle] = useState(false); const libraryArray = useMemo(() => Object.values(library), [library]); const playlistsArray = useMemo(() => Object.values(playlists), [playlists]); @@ -74,34 +74,53 @@ export function LibraryContextProvider({ }; }, []); - const shuffleLibraryArray = () => { + const shuffleLibraryArray = useCallback(() => { + console.log('shuffling'); const shuffled = [...libraryArray]; setRandomLibraryArray(shuffled.sort(() => 0.5 - Math.random())); - }; + }, [libraryArray]); - const debouncedShuffleLibraryArray = useCallback( - debounce(shuffleLibraryArray, RANDOM_LIBRARY_DELAY), - [libraryArray], - ); + useEffect(() => { + setShouldShuffle(true); + }, [libraryArray]); useEffect(() => { - debouncedShuffleLibraryArray(); - }, [libraryArray, debouncedShuffleLibraryArray]); + if (shouldShuffle) { + const timer = setTimeout(() => { + shuffleLibraryArray(); + setShouldShuffle(false); + }, RANDOM_LIBRARY_DELAY); + + return () => clearTimeout(timer); + } + }, [shouldShuffle, shuffleLibraryArray]); + + const contextValue = useMemo( + () => ({ + library, + libraryArray, + randomLibraryArray: + randomLibraryArray.length > 0 ? randomLibraryArray : libraryArray, + genres, + genresArray, + playlists, + playlistsArray, + liked, + }), + [ + library, + libraryArray, + randomLibraryArray, + genres, + genresArray, + playlists, + playlistsArray, + liked, + ], + ); return ( - 0 ? randomLibraryArray : libraryArray, - genres, - genresArray, - playlists, - playlistsArray, - liked, - }} - > + {children} ); diff --git a/src/renderer/windows/main/pages/Library.tsx b/src/renderer/windows/main/pages/Library.tsx index e4e14f7d..b3cd75a1 100644 --- a/src/renderer/windows/main/pages/Library.tsx +++ b/src/renderer/windows/main/pages/Library.tsx @@ -30,7 +30,7 @@ export function Library(_props: Props) {
- {libraryArray.map((media: MediaType) => ( + {randomLibraryArray.map((media: MediaType) => (
+
+
+
+ {`${title} +
+
+
+ +
+
+
+
+
+ {`${title} +
+
+

+ {title} +

+

{year}

+

{description}

+ {ratings && ratings.length > 0 && ( +
+
+ {[...Array(5)].map((_, index) => ( + + ))} +
+ + {ratings[0].Value}/10 + +
+ )} +
+ {omdb?.director && ( +
+

Director

+

{omdb.director}

+
+ )} + {omdb?.actors && ( +
+

Cast

+

{omdb.actors}

+
+ )} +
+
+ {trailer && ( + + )} + +
+
+
+
+
+