Files
suwayomi-material-you-webui/webUI/react/src/screens/Reader.tsx

57 lines
1.4 KiB
TypeScript
Raw Normal View History

2021-01-22 17:00:33 +03:30
import React, { useContext, useEffect, useState } from 'react';
2021-01-20 01:05:24 +03:30
import { useParams } from 'react-router-dom';
2021-01-22 17:00:33 +03:30
import NavBarTitle from '../context/NavbarTitle';
2021-01-20 01:05:24 +03:30
const style = {
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
margin: '0 auto',
backgroundColor: '#343a40',
} as React.CSSProperties;
interface IPage {
index: number
imageUrl: string
}
2021-01-22 17:00:33 +03:30
interface IData {
first: IChapter
second: IPage[]
}
2021-01-20 01:05:24 +03:30
export default function Reader() {
2021-01-22 17:00:33 +03:30
const { setTitle } = useContext(NavBarTitle);
2021-01-20 01:05:24 +03:30
const [pages, setPages] = useState<IPage[]>([]);
const { chapterId, mangaId } = useParams<{chapterId: string, mangaId: string}>();
useEffect(() => {
fetch(`http://127.0.0.1:4567/api/v1/manga/${mangaId}/chapter/${chapterId}`)
.then((response) => response.json())
2021-01-22 17:00:33 +03:30
.then((data:IData) => {
setTitle(data.first.name);
setPages(data.second);
});
2021-01-20 01:05:24 +03:30
}, []);
pages.sort((a, b) => (a.index - b.index));
let mapped;
if (pages.length === 0) {
mapped = <h3>wait</h3>;
} else {
mapped = pages.map(({ imageUrl }) => (
<div style={{ margin: '0 auto' }}>
<img src={imageUrl} alt="f" style={{ maxWidth: '100%' }} />
</div>
));
}
return (
<div style={style}>
{mapped}
</div>
);
}