добавлено апи сонарр для главной страницы
This commit is contained in:
@@ -16,7 +16,7 @@ export const sonarr = () => {
|
|||||||
const res = axios;
|
const res = axios;
|
||||||
res.defaults.baseURL = `${window.location.protocol}//${host}/sonarr/`;
|
res.defaults.baseURL = `${window.location.protocol}//${host}/sonarr/`;
|
||||||
res.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
|
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';
|
res.defaults.headers.common['Accept'] = 'application/json';
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@@ -3,20 +3,27 @@ import {Accordion, Badge, Col, Container, Row} from "react-bootstrap";
|
|||||||
import CardCompact from "../components/CardCompact";
|
import CardCompact from "../components/CardCompact";
|
||||||
import {useToast} from "../hooks/useToast";
|
import {useToast} from "../hooks/useToast";
|
||||||
import {SkeletonCompact} from "../components/SkeletonCompact";
|
import {SkeletonCompact} from "../components/SkeletonCompact";
|
||||||
import {radarr} from "../contexts/client";
|
import {radarr, sonarr} from "../contexts/client";
|
||||||
|
|
||||||
const Home = () => {
|
const Home = () => {
|
||||||
const [loading, setLoading] = useState(false);
|
const [loadingTv, setLoadingTv] = useState(false);
|
||||||
|
const [loadingMovies, setLoadingMovies] = useState(false);
|
||||||
const [movies, setMovies] = useState([]);
|
const [movies, setMovies] = useState([]);
|
||||||
// const [series, setSeries] = useState([]);
|
const [tv, setTv] = useState([]);
|
||||||
const {addToast} = useToast();
|
const {addToast} = useToast();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setLoading(true);
|
setLoadingMovies(true);
|
||||||
|
setLoadingTv(true);
|
||||||
radarr().get("api/v3/movie")
|
radarr().get("api/v3/movie")
|
||||||
.then((r) => setMovies(r.data))
|
.then((r) => setMovies(r.data))
|
||||||
.catch((err) => addToast(err, 'alert'))
|
.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
|
// eslint-disable-next-line
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
@@ -29,7 +36,7 @@ const Home = () => {
|
|||||||
</Accordion.Header>
|
</Accordion.Header>
|
||||||
<Accordion.Body>
|
<Accordion.Body>
|
||||||
<Row>
|
<Row>
|
||||||
{loading ?
|
{loadingMovies ?
|
||||||
(
|
(
|
||||||
// Отображаем 10 скелетонов
|
// Отображаем 10 скелетонов
|
||||||
Array.from({length: 10}, (_, index) => (
|
Array.from({length: 10}, (_, index) => (
|
||||||
@@ -39,7 +46,7 @@ const Home = () => {
|
|||||||
))
|
))
|
||||||
)
|
)
|
||||||
:
|
:
|
||||||
movies.map(rec => (
|
movies?.map(rec => (
|
||||||
<Col key={`col-${rec.title}-${rec.year}`}>
|
<Col key={`col-${rec.title}-${rec.year}`}>
|
||||||
<CardCompact item={rec} key={`${rec.title}-${rec.year}`}/>
|
<CardCompact item={rec} key={`${rec.title}-${rec.year}`}/>
|
||||||
</Col>
|
</Col>
|
||||||
@@ -51,7 +58,22 @@ const Home = () => {
|
|||||||
<Accordion.Header className="mt-5">Сериалы</Accordion.Header>
|
<Accordion.Header className="mt-5">Сериалы</Accordion.Header>
|
||||||
<Accordion.Body>
|
<Accordion.Body>
|
||||||
<Row>
|
<Row>
|
||||||
<Badge bg="info">Функционал для сериалов пока не реализован</Badge>
|
{loadingTv ?
|
||||||
|
(
|
||||||
|
// Отображаем 10 скелетонов
|
||||||
|
Array.from({length: 10}, (_, index) => (
|
||||||
|
<Col key={`skeleton-tv-${index}`}>
|
||||||
|
<SkeletonCompact key={index} width={300} height={400}/>
|
||||||
|
</Col>
|
||||||
|
))
|
||||||
|
)
|
||||||
|
:
|
||||||
|
tv.length > 0 ? tv.map(rec => (
|
||||||
|
<Col key={`col-tv-${rec.title}-${rec.year}`}>
|
||||||
|
<CardCompact item={rec} key={`${rec.title}-${rec.year}`}/>
|
||||||
|
</Col>
|
||||||
|
)) :
|
||||||
|
<Badge bg="info">Функционал для сериалов пока не реализован</Badge>}
|
||||||
</Row>
|
</Row>
|
||||||
</Accordion.Body>
|
</Accordion.Body>
|
||||||
</Accordion.Item>
|
</Accordion.Item>
|
||||||
|
|||||||
Reference in New Issue
Block a user