2021-01-26 23:32:12 +03:30
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
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-03-08 21:04:42 +03:30
|
|
|
import NavbarContext from '../context/NavbarContext';
|
2021-03-07 22:25:29 +03:30
|
|
|
import client from '../util/client';
|
|
|
|
|
import useLocalStorage from '../util/useLocalStorage';
|
2021-01-20 01:05:24 +03:30
|
|
|
|
|
|
|
|
const style = {
|
|
|
|
|
display: 'flex',
|
|
|
|
|
flexDirection: 'column',
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
margin: '0 auto',
|
|
|
|
|
backgroundColor: '#343a40',
|
|
|
|
|
} as React.CSSProperties;
|
|
|
|
|
|
2021-02-04 03:42:30 +03:30
|
|
|
const range = (n:number) => Array.from({ length: n }, (value, key) => key);
|
2021-01-22 17:00:33 +03:30
|
|
|
|
2021-01-20 01:05:24 +03:30
|
|
|
export default function Reader() {
|
2021-03-07 22:25:29 +03:30
|
|
|
const [serverAddress] = useLocalStorage<String>('serverBaseURL', '');
|
2021-03-08 21:04:42 +03:30
|
|
|
const { setTitle } = useContext(NavbarContext);
|
2021-01-22 17:00:33 +03:30
|
|
|
|
2021-02-04 03:42:30 +03:30
|
|
|
const [pageCount, setPageCount] = useState<number>(-1);
|
2021-01-20 01:05:24 +03:30
|
|
|
const { chapterId, mangaId } = useParams<{chapterId: string, mangaId: string}>();
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
2021-03-07 22:25:29 +03:30
|
|
|
client.get(`/api/v1/manga/${mangaId}/chapter/${chapterId}`)
|
|
|
|
|
.then((response) => response.data)
|
2021-02-04 03:42:30 +03:30
|
|
|
.then((data:IChapter) => {
|
|
|
|
|
setTitle(data.name);
|
|
|
|
|
setPageCount(data.pageCount);
|
2021-01-22 17:00:33 +03:30
|
|
|
});
|
2021-01-20 01:05:24 +03:30
|
|
|
}, []);
|
|
|
|
|
|
2021-02-04 03:42:30 +03:30
|
|
|
if (pageCount === -1) {
|
|
|
|
|
return (
|
|
|
|
|
<div style={style}>
|
|
|
|
|
<h3>wait</h3>
|
2021-01-20 01:05:24 +03:30
|
|
|
</div>
|
2021-02-04 03:42:30 +03:30
|
|
|
);
|
2021-01-20 01:05:24 +03:30
|
|
|
}
|
|
|
|
|
|
2021-02-04 03:42:30 +03:30
|
|
|
const mapped = range(pageCount).map((index) => (
|
|
|
|
|
<div style={{ margin: '0 auto' }}>
|
2021-03-07 22:25:29 +03:30
|
|
|
<img src={`${serverAddress}/api/v1/manga/${mangaId}/chapter/${chapterId}/page/${index}`} alt="F" style={{ maxWidth: '100%' }} />
|
2021-02-04 03:42:30 +03:30
|
|
|
</div>
|
|
|
|
|
));
|
2021-01-20 01:05:24 +03:30
|
|
|
return (
|
|
|
|
|
<div style={style}>
|
|
|
|
|
{mapped}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|