diff --git a/webUI/react/.gitignore b/webUI/react/.gitignore index 6b02b559..24daa585 100644 --- a/webUI/react/.gitignore +++ b/webUI/react/.gitignore @@ -1,2 +1,3 @@ node_modules/ .eslintcache +.vscode diff --git a/webUI/react/src/App.tsx b/webUI/react/src/App.tsx index 39e780ec..87d98b2d 100644 --- a/webUI/react/src/App.tsx +++ b/webUI/react/src/App.tsx @@ -1,97 +1,27 @@ -import React, { useEffect, useState } from 'react'; +import React from 'react'; import { - BrowserRouter as Router, - Switch, - Route, - useParams, + BrowserRouter as Router, Route, Switch, } from 'react-router-dom'; -import Button from '@material-ui/core/Button'; import NavBar from './components/NavBar'; -import ExtensionCard from './components/ExtensionCard'; -import SourceCard from './components/SourceCard'; -import MangaCard from './components/MangaCard'; - -function MangaPage() { - const { sourceId } = useParams<{sourceId: string}>(); - let mapped; - const [mangas, setMangas] = useState([]); - - 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 =

wait

; - } else { - mapped = ( -
- {mangas.map((it) => ( - - ))} -
- ); - } - - return mapped; -} - -function Extensions() { - let mapped; - const [extensions, setExtensions] = useState([]); - - if (extensions.length === 0) { - mapped =

wait

; - fetch('http://127.0.0.1:4567/api/v1/extension/list') - .then((response) => response.json()) - .then((data) => setExtensions(data)); - } else { - mapped = extensions.map((it) => ); - } - - return

{mapped}

; -} - -function Sources() { - let mapped; - const [sources, setSources] = useState([]); - - if (sources.length === 0) { - mapped =

wait

; - fetch('http://127.0.0.1:4567/api/v1/source/list') - .then((response) => response.json()) - .then((data) => setSources(data)); - } else { - mapped = sources.map((it) => ); - } - - return

{mapped}

; -} - -function Home() { - return ( - - ); -} +import Home from './screens/Home'; +import Sources from './screens/Sources'; +import Extensions from './screens/Extensions'; +import MangaList from './screens/PopularManga'; export default function App() { return ( - {/* */} - {/* eslint-disable-next-line react/no-children-prop */} - + + + + diff --git a/webUI/react/src/components/SourceCard.tsx b/webUI/react/src/components/SourceCard.tsx index 530d1e28..60aacb65 100644 --- a/webUI/react/src/components/SourceCard.tsx +++ b/webUI/react/src/components/SourceCard.tsx @@ -65,7 +65,7 @@ export default function SourceCard(props: IProps) {
- {supportsLatest && } + {supportsLatest && }
diff --git a/webUI/react/src/screens/Extensions.tsx b/webUI/react/src/screens/Extensions.tsx new file mode 100644 index 00000000..51622fd0 --- /dev/null +++ b/webUI/react/src/screens/Extensions.tsx @@ -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([]); + + 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 =

wait

; + } else { + mapped = extensions.map((it) => ); + } + + return

{mapped}

; +} diff --git a/webUI/react/src/screens/Home.tsx b/webUI/react/src/screens/Home.tsx new file mode 100644 index 00000000..08edfc25 --- /dev/null +++ b/webUI/react/src/screens/Home.tsx @@ -0,0 +1,9 @@ +import React from 'react'; + +export default function Home() { + return ( +

+ Home +

+ ); +} diff --git a/webUI/react/src/screens/PopularManga.tsx b/webUI/react/src/screens/PopularManga.tsx new file mode 100644 index 00000000..fa311e92 --- /dev/null +++ b/webUI/react/src/screens/PopularManga.tsx @@ -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([]); + + 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 =

wait

; + } else { + mapped = ( +
+ {mangas.map((it) => ( + + ))} +
+ ); + } + + return mapped; +} diff --git a/webUI/react/src/screens/Sources.tsx b/webUI/react/src/screens/Sources.tsx new file mode 100644 index 00000000..96d2cd52 --- /dev/null +++ b/webUI/react/src/screens/Sources.tsx @@ -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([]); + + 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 =

wait

; + } else { + mapped = sources.map((it) => ); + } + + return

{mapped}

; +}