mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-06-30 17:34:39 -05:00
refactor, fix fetch loop
This commit is contained in:
1
webUI/react/.gitignore
vendored
1
webUI/react/.gitignore
vendored
@@ -1,2 +1,3 @@
|
|||||||
node_modules/
|
node_modules/
|
||||||
.eslintcache
|
.eslintcache
|
||||||
|
.vscode
|
||||||
|
|||||||
@@ -1,97 +1,27 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
import React from 'react';
|
||||||
import {
|
import {
|
||||||
BrowserRouter as Router,
|
BrowserRouter as Router, Route, Switch,
|
||||||
Switch,
|
|
||||||
Route,
|
|
||||||
useParams,
|
|
||||||
} from 'react-router-dom';
|
} from 'react-router-dom';
|
||||||
import Button from '@material-ui/core/Button';
|
|
||||||
import NavBar from './components/NavBar';
|
import NavBar from './components/NavBar';
|
||||||
import ExtensionCard from './components/ExtensionCard';
|
import Home from './screens/Home';
|
||||||
import SourceCard from './components/SourceCard';
|
import Sources from './screens/Sources';
|
||||||
import MangaCard from './components/MangaCard';
|
import Extensions from './screens/Extensions';
|
||||||
|
import MangaList from './screens/PopularManga';
|
||||||
function MangaPage() {
|
|
||||||
const { sourceId } = useParams<{sourceId: string}>();
|
|
||||||
let mapped;
|
|
||||||
const [mangas, setMangas] = useState<IManga[]>([]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
fetch(`http://127.0.0.1:4567/api/v1/source/${sourceId}/popular`)
|
|
||||||
.then((response) => response.json())
|
|
||||||
.then((data: { title: string, thumbnail_url: string }[]) => setMangas(
|
|
||||||
data.map((it) => ({ title: it.title, thumbnailUrl: it.thumbnail_url })),
|
|
||||||
));
|
|
||||||
});
|
|
||||||
|
|
||||||
if (mangas.length === 0) {
|
|
||||||
mapped = <h3>wait</h3>;
|
|
||||||
} else {
|
|
||||||
mapped = (
|
|
||||||
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(5, auto)', gridGap: '1em' }}>
|
|
||||||
{mangas.map((it) => (
|
|
||||||
<MangaCard manga={it} />
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return mapped;
|
|
||||||
}
|
|
||||||
|
|
||||||
function Extensions() {
|
|
||||||
let mapped;
|
|
||||||
const [extensions, setExtensions] = useState<IExtension[]>([]);
|
|
||||||
|
|
||||||
if (extensions.length === 0) {
|
|
||||||
mapped = <h3>wait</h3>;
|
|
||||||
fetch('http://127.0.0.1:4567/api/v1/extension/list')
|
|
||||||
.then((response) => response.json())
|
|
||||||
.then((data) => setExtensions(data));
|
|
||||||
} else {
|
|
||||||
mapped = extensions.map((it) => <ExtensionCard extension={it} />);
|
|
||||||
}
|
|
||||||
|
|
||||||
return <h2>{mapped}</h2>;
|
|
||||||
}
|
|
||||||
|
|
||||||
function Sources() {
|
|
||||||
let mapped;
|
|
||||||
const [sources, setSources] = useState<ISource[]>([]);
|
|
||||||
|
|
||||||
if (sources.length === 0) {
|
|
||||||
mapped = <h3>wait</h3>;
|
|
||||||
fetch('http://127.0.0.1:4567/api/v1/source/list')
|
|
||||||
.then((response) => response.json())
|
|
||||||
.then((data) => setSources(data));
|
|
||||||
} else {
|
|
||||||
mapped = sources.map((it) => <SourceCard source={it} />);
|
|
||||||
}
|
|
||||||
|
|
||||||
return <h2>{mapped}</h2>;
|
|
||||||
}
|
|
||||||
|
|
||||||
function Home() {
|
|
||||||
return (
|
|
||||||
<Button variant="contained" color="primary">
|
|
||||||
Hello World
|
|
||||||
</Button>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function App() {
|
export default function App() {
|
||||||
return (
|
return (
|
||||||
<Router>
|
<Router>
|
||||||
{/* <TemporaryDrawer/> */}
|
|
||||||
<NavBar />
|
<NavBar />
|
||||||
|
|
||||||
<Switch>
|
<Switch>
|
||||||
<Route path="/extensions">
|
<Route path="/extensions">
|
||||||
<Extensions />
|
<Extensions />
|
||||||
</Route>
|
</Route>
|
||||||
{/* eslint-disable-next-line react/no-children-prop */}
|
|
||||||
<Route path="/sources/:sourceId/popular">
|
<Route path="/sources/:sourceId/popular">
|
||||||
<MangaPage />
|
<MangaList popular />
|
||||||
|
</Route>
|
||||||
|
<Route path="/sources/:sourceId/latest">
|
||||||
|
<MangaList popular={false} />
|
||||||
</Route>
|
</Route>
|
||||||
<Route path="/sources">
|
<Route path="/sources">
|
||||||
<Sources />
|
<Sources />
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ export default function SourceCard(props: IProps) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div style={{ display: 'flex' }}>
|
<div style={{ display: 'flex' }}>
|
||||||
{supportsLatest && <Button variant="outlined">Latest</Button>}
|
{supportsLatest && <Button variant="outlined" style={{ marginLeft: 20 }} onClick={() => { window.location.href = `sources/${id}/latest`; }}>Latest</Button>}
|
||||||
<Button variant="outlined" style={{ marginLeft: 20 }} onClick={() => { window.location.href = `sources/${id}/popular`; }}>Browse</Button>
|
<Button variant="outlined" style={{ marginLeft: 20 }} onClick={() => { window.location.href = `sources/${id}/popular`; }}>Browse</Button>
|
||||||
</div>
|
</div>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
|
|||||||
21
webUI/react/src/screens/Extensions.tsx
Normal file
21
webUI/react/src/screens/Extensions.tsx
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import React, { useEffect, useState } from 'react';
|
||||||
|
import ExtensionCard from '../components/ExtensionCard';
|
||||||
|
|
||||||
|
export default function Extensions() {
|
||||||
|
let mapped;
|
||||||
|
const [extensions, setExtensions] = useState<IExtension[]>([]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
fetch('http://127.0.0.1:4567/api/v1/extension/list')
|
||||||
|
.then((response) => response.json())
|
||||||
|
.then((data) => setExtensions(data));
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
if (extensions.length === 0) {
|
||||||
|
mapped = <h3>wait</h3>;
|
||||||
|
} else {
|
||||||
|
mapped = extensions.map((it) => <ExtensionCard extension={it} />);
|
||||||
|
}
|
||||||
|
|
||||||
|
return <h2>{mapped}</h2>;
|
||||||
|
}
|
||||||
9
webUI/react/src/screens/Home.tsx
Normal file
9
webUI/react/src/screens/Home.tsx
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
export default function Home() {
|
||||||
|
return (
|
||||||
|
<h1>
|
||||||
|
Home
|
||||||
|
</h1>
|
||||||
|
);
|
||||||
|
}
|
||||||
37
webUI/react/src/screens/PopularManga.tsx
Normal file
37
webUI/react/src/screens/PopularManga.tsx
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
import React, { useEffect, useState } from 'react';
|
||||||
|
import { useParams } from 'react-router-dom';
|
||||||
|
import MangaCard from '../components/MangaCard';
|
||||||
|
|
||||||
|
interface IManga {
|
||||||
|
title: string
|
||||||
|
thumbnailUrl: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function MangaList(props: { popular: boolean }) {
|
||||||
|
const { sourceId } = useParams<{sourceId: string}>();
|
||||||
|
let mapped;
|
||||||
|
const [mangas, setMangas] = useState<IManga[]>([]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const sourceType = props.popular ? 'popular' : 'latest';
|
||||||
|
fetch(`http://127.0.0.1:4567/api/v1/source/${sourceId}/${sourceType}`)
|
||||||
|
.then((response) => response.json())
|
||||||
|
.then((data: { title: string, thumbnail_url: string }[]) => setMangas(
|
||||||
|
data.map((it) => ({ title: it.title, thumbnailUrl: it.thumbnail_url })),
|
||||||
|
));
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
if (mangas.length === 0) {
|
||||||
|
mapped = <h3>wait</h3>;
|
||||||
|
} else {
|
||||||
|
mapped = (
|
||||||
|
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(5, auto)', gridGap: '1em' }}>
|
||||||
|
{mangas.map((it) => (
|
||||||
|
<MangaCard manga={it} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return mapped;
|
||||||
|
}
|
||||||
21
webUI/react/src/screens/Sources.tsx
Normal file
21
webUI/react/src/screens/Sources.tsx
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import React, { useEffect, useState } from 'react';
|
||||||
|
import SourceCard from '../components/SourceCard';
|
||||||
|
|
||||||
|
export default function Sources() {
|
||||||
|
let mapped;
|
||||||
|
const [sources, setSources] = useState<ISource[]>([]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
fetch('http://127.0.0.1:4567/api/v1/source/list')
|
||||||
|
.then((response) => response.json())
|
||||||
|
.then((data) => setSources(data));
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
if (sources.length === 0) {
|
||||||
|
mapped = <h3>wait</h3>;
|
||||||
|
} else {
|
||||||
|
mapped = sources.map((it) => <SourceCard source={it} />);
|
||||||
|
}
|
||||||
|
|
||||||
|
return <h2>{mapped}</h2>;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user