mirror of
https://github.com/C9Glax/tranga-website.git
synced 2025-05-20 05:03:02 +02:00
MangaConnectorContext
This commit is contained in:
parent
9fa57eacdb
commit
0193077377
@ -8,6 +8,9 @@ import {ApiUriContext} from "./api/fetchApi.tsx";
|
||||
import Search from './Components/Search.tsx';
|
||||
import MangaList from "./Components/MangaList.tsx";
|
||||
import {CardHeight, CardWidth} from "./Components/Manga.tsx";
|
||||
import {MangaConnectorContext} from "./api/Contexts/MangaConnectorContext.tsx";
|
||||
import IMangaConnector from "./api/types/IMangaConnector.ts";
|
||||
import {GetAllConnectors} from "./api/MangaConnector.tsx";
|
||||
|
||||
export default function App () {
|
||||
|
||||
@ -23,8 +26,16 @@ export default function App () {
|
||||
localStorage.setItem("apiUri", apiUri);
|
||||
}, [apiUri]);
|
||||
|
||||
const [mangaConnectors, setMangaConnectors] = useState<IMangaConnector[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
if(!apiConnected) return;
|
||||
GetAllConnectors(apiUri).then(setMangaConnectors);
|
||||
}, [apiConnected]);
|
||||
|
||||
return (
|
||||
<ApiUriContext.Provider value={apiUri}>
|
||||
<MangaConnectorContext value={mangaConnectors}>
|
||||
<Sheet className={"app"}>
|
||||
<Header>
|
||||
<Badge color={"danger"} invisible={apiConnected} badgeContent={"!"}>
|
||||
@ -55,6 +66,7 @@ export default function App () {
|
||||
</MangaList>
|
||||
</Sheet>
|
||||
</Sheet>
|
||||
</MangaConnectorContext>
|
||||
</ApiUriContext.Provider>
|
||||
);
|
||||
}
|
||||
|
@ -12,8 +12,7 @@ import {ApiUriContext, getData} from "../api/fetchApi.tsx";
|
||||
import {ReleaseStatusToPalette} from "../api/types/EnumMangaReleaseStatus.ts";
|
||||
import {SxProps} from "@mui/joy/styles/types";
|
||||
import MangaPopup from "./MangaPopup.tsx";
|
||||
import IMangaConnector from "../api/types/IMangaConnector.ts";
|
||||
import {GetConnector} from "../api/MangaConnector.tsx";
|
||||
import {MangaConnectorContext} from "../api/Contexts/MangaConnectorContext.tsx";
|
||||
|
||||
export function MangaFromId({mangaId, children} : { mangaId: string, children?: ReactElement<any, any> | ReactElement<any, any>[] | undefined }){
|
||||
const [manga, setManga] = useState<IManga>();
|
||||
@ -44,13 +43,13 @@ export function Manga({manga: manga, children} : { manga: IManga, children?: Rea
|
||||
const CoverRef = useRef<HTMLImageElement>(null);
|
||||
|
||||
const apiUri = useContext(ApiUriContext);
|
||||
const mangaConnectors = useContext(MangaConnectorContext);
|
||||
|
||||
const [expanded, setExpanded] = useState(false);
|
||||
const [mangaConnector, setMangaConnector] = useState<IMangaConnector | undefined>(undefined);
|
||||
const mangaConnector = mangaConnectors.find(all => all.name == manga.mangaConnectorName);
|
||||
|
||||
useEffect(() => {
|
||||
LoadMangaCover();
|
||||
LoadMangaConnector();
|
||||
}, [manga]);
|
||||
|
||||
const LoadMangaCover = useCallback(() => {
|
||||
@ -66,10 +65,6 @@ export function Manga({manga: manga, children} : { manga: IManga, children?: Rea
|
||||
});
|
||||
}, [manga, apiUri])
|
||||
|
||||
const LoadMangaConnector = useCallback(() => {
|
||||
GetConnector(apiUri, manga.mangaConnectorName).then(setMangaConnector);
|
||||
}, [manga, apiUri]);
|
||||
|
||||
const coverSx : SxProps = {
|
||||
height: CardHeight + "px",
|
||||
width: CardWidth + "px",
|
||||
|
Loading…
x
Reference in New Issue
Block a user