diff --git a/src/contexts/client.js b/src/contexts/client.js index da06c75..16ae78f 100644 --- a/src/contexts/client.js +++ b/src/contexts/client.js @@ -16,7 +16,7 @@ export const sonarr = () => { const res = axios; res.defaults.baseURL = `${window.location.protocol}//${host}/sonarr/`; res.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; - res.defaults.headers.common['X-Api-Key'] = process.env.REACT_APP_RADARR_API_KEY; + res.defaults.headers.common['X-Api-Key'] = process.env.REACT_APP_SONARR_API_KEY; res.defaults.headers.common['Accept'] = 'application/json'; return res; } \ No newline at end of file diff --git a/src/pages/HomePage.js b/src/pages/HomePage.js index fd470f8..0d87aa8 100644 --- a/src/pages/HomePage.js +++ b/src/pages/HomePage.js @@ -3,20 +3,27 @@ import {Accordion, Badge, Col, Container, Row} from "react-bootstrap"; import CardCompact from "../components/CardCompact"; import {useToast} from "../hooks/useToast"; import {SkeletonCompact} from "../components/SkeletonCompact"; -import {radarr} from "../contexts/client"; +import {radarr, sonarr} from "../contexts/client"; const Home = () => { - const [loading, setLoading] = useState(false); + const [loadingTv, setLoadingTv] = useState(false); + const [loadingMovies, setLoadingMovies] = useState(false); const [movies, setMovies] = useState([]); - // const [series, setSeries] = useState([]); + const [tv, setTv] = useState([]); const {addToast} = useToast(); useEffect(() => { - setLoading(true); + setLoadingMovies(true); + setLoadingTv(true); radarr().get("api/v3/movie") .then((r) => setMovies(r.data)) .catch((err) => addToast(err, 'alert')) - .finally(() => setLoading(false)); + .finally(() => setLoadingMovies(false)); + + sonarr().get("api/v3/series") + .then((r) => setTv(r.data)) + .catch((err) => addToast(err, 'alert')) + .finally(() => setLoadingTv(false)); // eslint-disable-next-line }, []); @@ -29,7 +36,7 @@ const Home = () => { - {loading ? + {loadingMovies ? ( // Отображаем 10 скелетонов Array.from({length: 10}, (_, index) => ( @@ -39,7 +46,7 @@ const Home = () => { )) ) : - movies.map(rec => ( + movies?.map(rec => ( @@ -51,7 +58,22 @@ const Home = () => { Сериалы - Функционал для сериалов пока не реализован + {loadingTv ? + ( + // Отображаем 10 скелетонов + Array.from({length: 10}, (_, index) => ( + + + + )) + ) + : + tv.length > 0 ? tv.map(rec => ( + + + + )) : + Функционал для сериалов пока не реализован}