From f588dbed5b5b4df1fc1827ef9ce4cb94bc7bd12a Mon Sep 17 00:00:00 2001 From: lavafrai Date: Wed, 4 Dec 2024 23:47:36 +0300 Subject: [PATCH 1/8] feat: saving the user's preferred voiceover --- .../ReleasePlayer/ReleasePlayer.tsx | 15 ++++++++-- app/store/voiceover.ts | 28 +++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 app/store/voiceover.ts diff --git a/app/components/ReleasePlayer/ReleasePlayer.tsx b/app/components/ReleasePlayer/ReleasePlayer.tsx index 11bfd6e..a3b16f4 100644 --- a/app/components/ReleasePlayer/ReleasePlayer.tsx +++ b/app/components/ReleasePlayer/ReleasePlayer.tsx @@ -2,6 +2,7 @@ import { Spinner } from "#/components/Spinner/Spinner"; import { useUserStore } from "#/store/auth"; +import { useVoiceoverStore } from "#/store/voiceover"; import { Card, Dropdown, Button } from "flowbite-react"; import { ENDPOINTS } from "#/api/config"; import { useState, useEffect } from "react"; @@ -139,20 +140,30 @@ const saveAnonEpisodeWatched = ( export const ReleasePlayer = (props: { id: number }) => { const userStore = useUserStore(); + const preferredVoiceoverStore = useVoiceoverStore(); + const storedPreferredVoiceover = preferredVoiceoverStore.getPreferredVoiceover(props.id); const [voiceoverInfo, setVoiceoverInfo] = useState(null); const [selectedVoiceover, setSelectedVoiceover] = useState(null); const [sourcesInfo, setSourcesInfo] = useState(null); const [selectedSource, setSelectedSource] = useState(null); const [episodeInfo, setEpisodeInfo] = useState(null); const [selectedEpisode, setSelectedEpisode] = useState(null); + const setSelectedVoiceoverAndSaveAsPreferred = (voiceover: any) => { + setSelectedVoiceover(voiceover); + preferredVoiceoverStore.setPreferredVoiceover(props.id, voiceover.name); + } useEffect(() => { async function _fetchInfo() { const voiceover = await _fetch( `${ENDPOINTS.release.episode}/${props.id}` ); + const preferredVoiceover = voiceover.types.find( + (voiceover: any) => voiceover.name === storedPreferredVoiceover + ) || voiceover.types[0]; + setVoiceoverInfo(voiceover.types); - setSelectedVoiceover(voiceover.types[0]); + setSelectedVoiceover(preferredVoiceover); } _fetchInfo(); // eslint-disable-next-line react-hooks/exhaustive-deps @@ -227,7 +238,7 @@ export const ReleasePlayer = (props: { id: number }) => { {voiceoverInfo.map((voiceover: any) => ( setSelectedVoiceover(voiceover)} + onClick={() => setSelectedVoiceoverAndSaveAsPreferred(voiceover)} > {voiceover.name} diff --git a/app/store/voiceover.ts b/app/store/voiceover.ts new file mode 100644 index 0000000..e60f033 --- /dev/null +++ b/app/store/voiceover.ts @@ -0,0 +1,28 @@ +"use client"; +import { create } from "zustand"; +import { persist } from "zustand/middleware"; + +interface voiceoverState { + preferences: Map; + getPreferredVoiceover: (id: number) => (string | undefined); + setPreferredVoiceover: (id: number, voiceover: string) => void; +} + +export const useVoiceoverStore = create()( + persist( + (set, get) => ({ + preferences: new Map(), + getPreferredVoiceover: (id: number) => get().preferences[id], + setPreferredVoiceover: (id: number, voiceover: string) => { + let current = get().preferences + current[id] = voiceover + set({ + preferences: current, + }); + }, + }), + { + name: "voiceover-preferences", + } + ) +); \ No newline at end of file From 70e4d7a523db9e62336f31ddba02d73a1e5208f7 Mon Sep 17 00:00:00 2001 From: lavafrai Date: Thu, 5 Dec 2024 00:12:23 +0300 Subject: [PATCH 2/8] feat: saving the user's preferred video source --- .../ReleasePlayer/ReleasePlayer.tsx | 17 ++++++-- app/store/player.ts | 42 +++++++++++++++++++ app/store/voiceover.ts | 28 ------------- 3 files changed, 55 insertions(+), 32 deletions(-) create mode 100644 app/store/player.ts delete mode 100644 app/store/voiceover.ts diff --git a/app/components/ReleasePlayer/ReleasePlayer.tsx b/app/components/ReleasePlayer/ReleasePlayer.tsx index a3b16f4..0e74655 100644 --- a/app/components/ReleasePlayer/ReleasePlayer.tsx +++ b/app/components/ReleasePlayer/ReleasePlayer.tsx @@ -2,7 +2,7 @@ import { Spinner } from "#/components/Spinner/Spinner"; import { useUserStore } from "#/store/auth"; -import { useVoiceoverStore } from "#/store/voiceover"; +import { useUserPlayerPreferencesStore } from "#/store/player"; import { Card, Dropdown, Button } from "flowbite-react"; import { ENDPOINTS } from "#/api/config"; import { useState, useEffect } from "react"; @@ -140,8 +140,9 @@ const saveAnonEpisodeWatched = ( export const ReleasePlayer = (props: { id: number }) => { const userStore = useUserStore(); - const preferredVoiceoverStore = useVoiceoverStore(); + const preferredVoiceoverStore = useUserPlayerPreferencesStore(); const storedPreferredVoiceover = preferredVoiceoverStore.getPreferredVoiceover(props.id); + const storedPreferredPlayer = preferredVoiceoverStore.getPreferredPlayer(props.id); const [voiceoverInfo, setVoiceoverInfo] = useState(null); const [selectedVoiceover, setSelectedVoiceover] = useState(null); const [sourcesInfo, setSourcesInfo] = useState(null); @@ -152,6 +153,10 @@ export const ReleasePlayer = (props: { id: number }) => { setSelectedVoiceover(voiceover); preferredVoiceoverStore.setPreferredVoiceover(props.id, voiceover.name); } + const setSelectedPlayerAndSaveAsPreferred = (player: any) => { + setSelectedSource(player); + preferredVoiceoverStore.setPreferredPlayer(props.id, player.name); + } useEffect(() => { async function _fetchInfo() { @@ -174,8 +179,12 @@ export const ReleasePlayer = (props: { id: number }) => { const sources = await _fetch( `${ENDPOINTS.release.episode}/${props.id}/${selectedVoiceover.id}` ); + const preferredSource = sources.sources.find( + (source: any) => source.name === storedPreferredPlayer + ) || sources.sources[0]; + setSourcesInfo(sources.sources); - setSelectedSource(sources.sources[0]); + setSelectedSource(preferredSource); } if (selectedVoiceover) { _fetchInfo(); @@ -252,7 +261,7 @@ export const ReleasePlayer = (props: { id: number }) => { {sourcesInfo.map((source: any) => ( setSelectedSource(source)} + onClick={() => setSelectedPlayerAndSaveAsPreferred(source)} > {source.name} diff --git a/app/store/player.ts b/app/store/player.ts new file mode 100644 index 0000000..eb92dad --- /dev/null +++ b/app/store/player.ts @@ -0,0 +1,42 @@ +"use client"; +import { create } from "zustand"; +import { persist } from "zustand/middleware"; + +interface userPlayerPreferencesState { + voiceover: Map; + player: Map; + getPreferredVoiceover: (id: number) => (string | undefined); + setPreferredVoiceover: (id: number, voiceover: string) => void; + getPreferredPlayer: (id: number) => (string | undefined); + setPreferredPlayer: (id: number, player: string) => void; +} + +export const useUserPlayerPreferencesStore = create()( + persist( + (set, get) => ({ + voiceover: new Map(), + player: new Map(), + getPreferredVoiceover: (id: number) => get().voiceover[id], + setPreferredVoiceover: (id: number, voiceover: string) => { + let current = get().voiceover + current[id] = voiceover + set({ + voiceover: current, + player: get().player, + }); + }, + getPreferredPlayer: (id: number) => get().player[id], + setPreferredPlayer: (id: number, player: string) => { + let current = get().player + current[id] = player + set({ + voiceover: get().voiceover, + player: current, + }) + } + }), + { + name: "player-preferences", + } + ) +); \ No newline at end of file diff --git a/app/store/voiceover.ts b/app/store/voiceover.ts deleted file mode 100644 index e60f033..0000000 --- a/app/store/voiceover.ts +++ /dev/null @@ -1,28 +0,0 @@ -"use client"; -import { create } from "zustand"; -import { persist } from "zustand/middleware"; - -interface voiceoverState { - preferences: Map; - getPreferredVoiceover: (id: number) => (string | undefined); - setPreferredVoiceover: (id: number, voiceover: string) => void; -} - -export const useVoiceoverStore = create()( - persist( - (set, get) => ({ - preferences: new Map(), - getPreferredVoiceover: (id: number) => get().preferences[id], - setPreferredVoiceover: (id: number, voiceover: string) => { - let current = get().preferences - current[id] = voiceover - set({ - preferences: current, - }); - }, - }), - { - name: "voiceover-preferences", - } - ) -); \ No newline at end of file From 57245d99b7e8eec36e00933c62b1ae7001fd2e47 Mon Sep 17 00:00:00 2001 From: Kentai Radiquum Date: Thu, 5 Dec 2024 18:12:48 +0500 Subject: [PATCH 3/8] refactor: change types from Map to Record in playerStore --- app/store/player.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/store/player.ts b/app/store/player.ts index eb92dad..d4fe947 100644 --- a/app/store/player.ts +++ b/app/store/player.ts @@ -3,8 +3,8 @@ import { create } from "zustand"; import { persist } from "zustand/middleware"; interface userPlayerPreferencesState { - voiceover: Map; - player: Map; + voiceover: Record; + player: Record; getPreferredVoiceover: (id: number) => (string | undefined); setPreferredVoiceover: (id: number, voiceover: string) => void; getPreferredPlayer: (id: number) => (string | undefined); @@ -14,8 +14,8 @@ interface userPlayerPreferencesState { export const useUserPlayerPreferencesStore = create()( persist( (set, get) => ({ - voiceover: new Map(), - player: new Map(), + voiceover: {}, + player: {}, getPreferredVoiceover: (id: number) => get().voiceover[id], setPreferredVoiceover: (id: number, voiceover: string) => { let current = get().voiceover From 9d921c1ee4a6e236665f818fc8c6509210c477fb Mon Sep 17 00:00:00 2001 From: Kentai Radiquum Date: Thu, 5 Dec 2024 18:30:56 +0500 Subject: [PATCH 4/8] feat: add some more error handling for the player --- .../ReleasePlayer/ReleasePlayer.tsx | 111 +++++++++++------- 1 file changed, 71 insertions(+), 40 deletions(-) diff --git a/app/components/ReleasePlayer/ReleasePlayer.tsx b/app/components/ReleasePlayer/ReleasePlayer.tsx index 0e74655..64e8294 100644 --- a/app/components/ReleasePlayer/ReleasePlayer.tsx +++ b/app/components/ReleasePlayer/ReleasePlayer.tsx @@ -141,34 +141,45 @@ const saveAnonEpisodeWatched = ( export const ReleasePlayer = (props: { id: number }) => { const userStore = useUserStore(); const preferredVoiceoverStore = useUserPlayerPreferencesStore(); - const storedPreferredVoiceover = preferredVoiceoverStore.getPreferredVoiceover(props.id); - const storedPreferredPlayer = preferredVoiceoverStore.getPreferredPlayer(props.id); + const storedPreferredVoiceover = + preferredVoiceoverStore.getPreferredVoiceover(props.id); + const storedPreferredPlayer = preferredVoiceoverStore.getPreferredPlayer( + props.id + ); const [voiceoverInfo, setVoiceoverInfo] = useState(null); const [selectedVoiceover, setSelectedVoiceover] = useState(null); const [sourcesInfo, setSourcesInfo] = useState(null); const [selectedSource, setSelectedSource] = useState(null); const [episodeInfo, setEpisodeInfo] = useState(null); const [selectedEpisode, setSelectedEpisode] = useState(null); + const [error, setError] = useState(null); const setSelectedVoiceoverAndSaveAsPreferred = (voiceover: any) => { setSelectedVoiceover(voiceover); preferredVoiceoverStore.setPreferredVoiceover(props.id, voiceover.name); - } + }; const setSelectedPlayerAndSaveAsPreferred = (player: any) => { setSelectedSource(player); preferredVoiceoverStore.setPreferredPlayer(props.id, player.name); - } + }; useEffect(() => { async function _fetchInfo() { - const voiceover = await _fetch( - `${ENDPOINTS.release.episode}/${props.id}` - ); - const preferredVoiceover = voiceover.types.find( - (voiceover: any) => voiceover.name === storedPreferredVoiceover - ) || voiceover.types[0]; - - setVoiceoverInfo(voiceover.types); - setSelectedVoiceover(preferredVoiceover); + try { + const voiceover = await _fetch( + `${ENDPOINTS.release.episode}/${props.id}` + ); + const preferredVoiceover = + voiceover.types.find( + (voiceover: any) => voiceover.name === storedPreferredVoiceover + ) || voiceover.types[0]; + setVoiceoverInfo(voiceover.types); + setSelectedVoiceover(preferredVoiceover); + } catch { + setVoiceoverInfo([]); + setSelectedVoiceover(null); + console.log("Error fetching voiceover info"); + setError("Ошибка получения озвучек"); + } } _fetchInfo(); // eslint-disable-next-line react-hooks/exhaustive-deps @@ -176,15 +187,22 @@ export const ReleasePlayer = (props: { id: number }) => { useEffect(() => { async function _fetchInfo() { - const sources = await _fetch( - `${ENDPOINTS.release.episode}/${props.id}/${selectedVoiceover.id}` - ); - const preferredSource = sources.sources.find( - (source: any) => source.name === storedPreferredPlayer - ) || sources.sources[0]; - - setSourcesInfo(sources.sources); - setSelectedSource(preferredSource); + try { + const sources = await _fetch( + `${ENDPOINTS.release.episode}/${props.id}/${selectedVoiceover.id}` + ); + const preferredSource = + sources.sources.find( + (source: any) => source.name === storedPreferredPlayer + ) || sources.sources[0]; + setSourcesInfo(sources.sources); + setSelectedSource(preferredSource); + } catch { + setSourcesInfo([]); + setSelectedSource(null); + console.log("Error fetching player info"); + setError("Ошибка получения доступных плееров"); + } } if (selectedVoiceover) { _fetchInfo(); @@ -194,20 +212,27 @@ export const ReleasePlayer = (props: { id: number }) => { useEffect(() => { async function _fetchInfo(url: string) { - const episodes = await _fetch(url); + try { + const episodes = await _fetch(url); - if (episodes.episodes.length === 0) { - const remSources = sourcesInfo.filter( - (source) => source.id !== selectedSource.id - ); - setSourcesInfo(remSources); - setSelectedSource(remSources[0]); + if (episodes.episodes.length === 0) { + const remSources = sourcesInfo.filter( + (source) => source.id !== selectedSource.id + ); + setSourcesInfo(remSources); + setSelectedSource(remSources[0]); - return; + return; + } + + setEpisodeInfo(episodes.episodes); + setSelectedEpisode(episodes.episodes[0]); + } catch { + setEpisodeInfo([]); + setSelectedEpisode(null); + console.log("Error fetching episodes info"); + setError("Ошибка получения доступных эпизодов"); } - - setEpisodeInfo(episodes.episodes); - setSelectedEpisode(episodes.episodes[0]); } if (selectedSource) { let url = `${ENDPOINTS.release.episode}/${props.id}/${selectedVoiceover.id}/${selectedSource.id}`; @@ -234,7 +259,7 @@ export const ReleasePlayer = (props: { id: number }) => { {!voiceoverInfo || !sourcesInfo || !episodeInfo ? (
- + {!error ? :

{error}

}
) : ( <> @@ -247,7 +272,9 @@ export const ReleasePlayer = (props: { id: number }) => { {voiceoverInfo.map((voiceover: any) => ( setSelectedVoiceoverAndSaveAsPreferred(voiceover)} + onClick={() => + setSelectedVoiceoverAndSaveAsPreferred(voiceover) + } > {voiceover.name} @@ -269,11 +296,15 @@ export const ReleasePlayer = (props: { id: number }) => {
- + {selectedEpisode ? ( + + ) : ( +

Ошибка загрузки плеера

+ )}
Date: Thu, 5 Dec 2024 18:49:35 +0500 Subject: [PATCH 5/8] refactor: player store https://github.com/Radiquum/AniX/pull/3#discussion_r1871410991 --- app/store/player.ts | 63 +++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 33 deletions(-) diff --git a/app/store/player.ts b/app/store/player.ts index d4fe947..369f604 100644 --- a/app/store/player.ts +++ b/app/store/player.ts @@ -3,40 +3,37 @@ import { create } from "zustand"; import { persist } from "zustand/middleware"; interface userPlayerPreferencesState { - voiceover: Record; - player: Record; - getPreferredVoiceover: (id: number) => (string | undefined); - setPreferredVoiceover: (id: number, voiceover: string) => void; - getPreferredPlayer: (id: number) => (string | undefined); - setPreferredPlayer: (id: number, player: string) => void; + voiceover: Record; + player: Record; + getPreferredVoiceover: (id: number) => string | undefined; + setPreferredVoiceover: (id: number, voiceover: string) => void; + getPreferredPlayer: (id: number) => string | undefined; + setPreferredPlayer: (id: number, player: string) => void; } -export const useUserPlayerPreferencesStore = create()( +export const useUserPlayerPreferencesStore = + create()( persist( - (set, get) => ({ - voiceover: {}, - player: {}, - getPreferredVoiceover: (id: number) => get().voiceover[id], - setPreferredVoiceover: (id: number, voiceover: string) => { - let current = get().voiceover - current[id] = voiceover - set({ - voiceover: current, - player: get().player, - }); - }, - getPreferredPlayer: (id: number) => get().player[id], - setPreferredPlayer: (id: number, player: string) => { - let current = get().player - current[id] = player - set({ - voiceover: get().voiceover, - player: current, - }) - } - }), - { - name: "player-preferences", - } + (set, get) => ({ + voiceover: {}, + player: {}, + getPreferredVoiceover: (id: number) => get().voiceover[id], + setPreferredVoiceover: (id: number, voiceover: string) => { + set({ + voiceover: { ...get().voiceover, [id]: voiceover }, + player: get().player, + }); + }, + getPreferredPlayer: (id: number) => get().player[id], + setPreferredPlayer: (id: number, player: string) => { + set({ + player: { ...get().player, [id]: player }, + voiceover: get().voiceover, + }); + }, + }), + { + name: "player-preferences", + } ) -); \ No newline at end of file + ); From 8a69eefc2e3388bc6023d70c3b7c72c1568850b9 Mon Sep 17 00:00:00 2001 From: Kentai Radiquum Date: Thu, 5 Dec 2024 19:28:08 +0500 Subject: [PATCH 6/8] refactor: move Fetching info from UseEffects to external function --- .../ReleasePlayer/ReleasePlayer.tsx | 158 ++++++++++-------- 1 file changed, 88 insertions(+), 70 deletions(-) diff --git a/app/components/ReleasePlayer/ReleasePlayer.tsx b/app/components/ReleasePlayer/ReleasePlayer.tsx index 64e8294..78289d6 100644 --- a/app/components/ReleasePlayer/ReleasePlayer.tsx +++ b/app/components/ReleasePlayer/ReleasePlayer.tsx @@ -162,87 +162,105 @@ export const ReleasePlayer = (props: { id: number }) => { preferredVoiceoverStore.setPreferredPlayer(props.id, player.name); }; - useEffect(() => { - async function _fetchInfo() { - try { - const voiceover = await _fetch( - `${ENDPOINTS.release.episode}/${props.id}` - ); - const preferredVoiceover = - voiceover.types.find( - (voiceover: any) => voiceover.name === storedPreferredVoiceover - ) || voiceover.types[0]; - setVoiceoverInfo(voiceover.types); - setSelectedVoiceover(preferredVoiceover); - } catch { - setVoiceoverInfo([]); - setSelectedVoiceover(null); - console.log("Error fetching voiceover info"); - setError("Ошибка получения озвучек"); - } - } - _fetchInfo(); - // eslint-disable-next-line react-hooks/exhaustive-deps - }, []); + function _setError(error: string) { + setVoiceoverInfo(null); + setSelectedVoiceover(null); + setSourcesInfo(null); + setSelectedSource(null); + setEpisodeInfo(null); + setSelectedEpisode(null); + setError(error); + } - useEffect(() => { - async function _fetchInfo() { - try { - const sources = await _fetch( - `${ENDPOINTS.release.episode}/${props.id}/${selectedVoiceover.id}` - ); - const preferredSource = - sources.sources.find( - (source: any) => source.name === storedPreferredPlayer - ) || sources.sources[0]; - setSourcesInfo(sources.sources); - setSelectedSource(preferredSource); - } catch { - setSourcesInfo([]); - setSelectedSource(null); - console.log("Error fetching player info"); - setError("Ошибка получения доступных плееров"); - } - } - if (selectedVoiceover) { - _fetchInfo(); - } - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [selectedVoiceover]); - - useEffect(() => { - async function _fetchInfo(url: string) { - try { - const episodes = await _fetch(url); - - if (episodes.episodes.length === 0) { - const remSources = sourcesInfo.filter( - (source) => source.id !== selectedSource.id - ); - setSourcesInfo(remSources); - setSelectedSource(remSources[0]); - - return; + async function _fetchInfo( + url: string, + type: "voiceover" | "sources" | "episodes" + ) { + let data: any = {}; + data = await fetch(url) + .then((res) => { + if (res.ok) { + return res.json(); + } else { + throw new Error("Error fetching data"); } + }) + .catch((err) => { + console.log(err); + _setError("Ошибка получение ответа от сервера"); + return; + }); - setEpisodeInfo(episodes.episodes); - setSelectedEpisode(episodes.episodes[0]); - } catch { - setEpisodeInfo([]); - setSelectedEpisode(null); - console.log("Error fetching episodes info"); - setError("Ошибка получения доступных эпизодов"); - } + if (data && Object.keys(data).length == 0) { + _setError("Ошибка получение данных с сервера"); } + + if (type == "voiceover") { + if (data.types.length > 0) { + setVoiceoverInfo(data.types); + const preferredVoiceover = + data.types.find( + (voiceover: any) => voiceover.name === storedPreferredVoiceover + ) || data.types[0]; + setSelectedVoiceover(preferredVoiceover); + } else { + _setError("Ошибка получения озвучек"); + } + } else if (type == "sources") { + if (data.sources.length > 0) { + setSourcesInfo(data.sources); + const preferredSource = + data.sources.find( + (source: any) => source.name === storedPreferredPlayer + ) || data.sources[0]; + setSelectedSource(preferredSource); + } else { + _setError("Ошибка получения источников"); + } + } else if (type == "episodes") { + if (data.episodes.length === 0) { + const remSources = sourcesInfo.filter( + (source) => source.id !== selectedSource.id + ); + setSourcesInfo(remSources); + setSelectedSource(remSources[0]); + return; + } else if (data.episodes.length > 0) { + setEpisodeInfo(data.episodes); + setSelectedEpisode(data.episodes[0]); + } else { + _setError("Ошибка получения эпизодов"); + } + } else { + _setError("Неизвестный тип запроса"); + } + } + + useEffect(() => { + _fetchInfo(`${ENDPOINTS.release.episode}/${props.id}`, "voiceover"); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [props.id]); + + useEffect(() => { + if (selectedVoiceover) { + _fetchInfo( + `${ENDPOINTS.release.episode}/${props.id}/${selectedVoiceover.id}`, + "sources" + ); + } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [props.id, selectedVoiceover]); + + useEffect(() => { if (selectedSource) { let url = `${ENDPOINTS.release.episode}/${props.id}/${selectedVoiceover.id}/${selectedSource.id}`; if (userStore.token) { url = `${ENDPOINTS.release.episode}/${props.id}/${selectedVoiceover.id}/${selectedSource.id}?token=${userStore.token}`; } - _fetchInfo(url); + _fetchInfo(url, "episodes"); } // eslint-disable-next-line react-hooks/exhaustive-deps - }, [selectedSource, userStore.token]); + }, [props.id, selectedSource, userStore.token]); async function _addToHistory(episode: any) { if (episode && userStore.token) { From 7b2debe6078b7a1fa8ba61141878792fa035b206 Mon Sep 17 00:00:00 2001 From: Kentai Radiquum Date: Thu, 5 Dec 2024 19:41:32 +0500 Subject: [PATCH 7/8] fix: Sibnet player episode position --- app/components/ReleasePlayer/ReleasePlayer.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/components/ReleasePlayer/ReleasePlayer.tsx b/app/components/ReleasePlayer/ReleasePlayer.tsx index 78289d6..2070bfb 100644 --- a/app/components/ReleasePlayer/ReleasePlayer.tsx +++ b/app/components/ReleasePlayer/ReleasePlayer.tsx @@ -370,7 +370,9 @@ export const ReleasePlayer = (props: { id: number }) => { {episode.name ? episode.name : `${ - selectedSource.name != "Sibnet" + !["Sibnet", "Sibnet (не работает)"].includes( + selectedSource.name + ) ? episode.position : episode.position + 1 } серия`} From 9404c64faa4c5d6694b6b7cb0a5616e361c906be Mon Sep 17 00:00:00 2001 From: Kentai Radiquum Date: Thu, 5 Dec 2024 20:11:50 +0500 Subject: [PATCH 8/8] feat: save of the last watched episode for a selected voiceover and player --- .../ReleasePlayer/ReleasePlayer.tsx | 50 ++++++++----------- 1 file changed, 21 insertions(+), 29 deletions(-) diff --git a/app/components/ReleasePlayer/ReleasePlayer.tsx b/app/components/ReleasePlayer/ReleasePlayer.tsx index 2070bfb..e077b9b 100644 --- a/app/components/ReleasePlayer/ReleasePlayer.tsx +++ b/app/components/ReleasePlayer/ReleasePlayer.tsx @@ -39,27 +39,14 @@ const getAnonEpisodesWatched = ( ) => { const anonEpisodesWatched = JSON.parse(localStorage.getItem("anonEpisodesWatched")) || {}; - console.log("anonEpisodesWatched", anonEpisodesWatched); if (!anonEpisodesWatched.hasOwnProperty(Release)) { - console.log( - `no key found for R: ${Release}`, - anonEpisodesWatched.hasOwnProperty(Release) - ); anonEpisodesWatched[Release] = {}; } if (!anonEpisodesWatched[Release].hasOwnProperty(Source)) { - console.log( - `no key found for R: ${Release} S: ${Source}`, - anonEpisodesWatched.hasOwnProperty(Release) - ); anonEpisodesWatched[Release][Source] = {}; } if (!anonEpisodesWatched[Release][Source].hasOwnProperty(Voiceover)) { - console.log( - `no key found for R: ${Release} S: ${Source} V: ${Voiceover}`, - anonEpisodesWatched.hasOwnProperty(Release) - ); anonEpisodesWatched[Release][Source][Voiceover] = {}; } @@ -76,33 +63,17 @@ const getAnonCurrentEpisodeWatched = ( JSON.parse(localStorage.getItem("anonEpisodesWatched")) || {}; if (!anonEpisodesWatched.hasOwnProperty(Release)) { - console.log( - `no key found for R: ${Release}`, - anonEpisodesWatched.hasOwnProperty(Release) - ); return false; } if (!anonEpisodesWatched[Release].hasOwnProperty(Source)) { - console.log( - `no key found for R: ${Release} S: ${Source}`, - anonEpisodesWatched.hasOwnProperty(Release) - ); return false; } if (!anonEpisodesWatched[Release][Source].hasOwnProperty(Voiceover)) { - console.log( - `no key found for R: ${Release} S: ${Source} V: ${Voiceover}`, - anonEpisodesWatched.hasOwnProperty(Release) - ); return false; } if ( !anonEpisodesWatched[Release][Source][Voiceover].hasOwnProperty(Episode) ) { - console.log( - `no key found for R: ${Release} S: ${Source} V: ${Voiceover} E: ${Episode}`, - anonEpisodesWatched.hasOwnProperty(Release) - ); return false; } @@ -228,6 +199,27 @@ export const ReleasePlayer = (props: { id: number }) => { } else if (data.episodes.length > 0) { setEpisodeInfo(data.episodes); setSelectedEpisode(data.episodes[0]); + + const WatchedEpisodes = getAnonEpisodesWatched( + props.id, + selectedSource.id, + selectedVoiceover.id + ); + if ( + Object.keys( + WatchedEpisodes[props.id][selectedSource.id][selectedVoiceover.id] + ).length != 0 + ) { + const watchedEpisodes = + WatchedEpisodes[props.id][selectedSource.id][selectedVoiceover.id]; + let lastWatchedEpisode = Number(Object.keys(watchedEpisodes).pop()); + if ( + !["Sibnet", "Sibnet (не работает)"].includes(selectedSource.name) + ) { + lastWatchedEpisode = Number(lastWatchedEpisode) - 1; + } + setSelectedEpisode(data.episodes[lastWatchedEpisode]); + } } else { _setError("Ошибка получения эпизодов"); }