mirror of
https://github.com/C9Glax/tranga-website.git
synced 2025-05-15 02:53:00 +02:00
Make ApiUri persistent
This commit is contained in:
parent
6173d16edc
commit
3ad7fbfad2
@ -3,7 +3,7 @@ import './App.css'
|
||||
import Settings from "./Settings.tsx";
|
||||
import Header from "./Header.tsx";
|
||||
import {Badge, Box, Button, Card, CardContent, CardCover, Typography} from "@mui/joy";
|
||||
import {useState} from "react";
|
||||
import {useEffect, useState} from "react";
|
||||
import {ApiUriContext} from "./api/fetchApi.tsx";
|
||||
import Search from './Components/Search.tsx';
|
||||
import MangaList from "./Components/MangaList.tsx";
|
||||
@ -14,7 +14,13 @@ export default function App () {
|
||||
const [showSearch, setShowSearch] = useState<boolean>(false);
|
||||
const [apiConnected, setApiConnected] = useState<boolean>(false);
|
||||
|
||||
const [apiUri, setApiUri] = useState<string>(window.location.href.substring(0, window.location.href.lastIndexOf("/")));
|
||||
const apiUriStr = localStorage.getItem("apiUri") ?? window.location.href.substring(0, window.location.href.lastIndexOf("/"));
|
||||
|
||||
const [apiUri, setApiUri] = useState<string>(apiUriStr);
|
||||
|
||||
useEffect(() => {
|
||||
localStorage.setItem("apiUri", apiUri);
|
||||
}, [apiUri]);
|
||||
|
||||
return (
|
||||
<ApiUriContext.Provider value={apiUri}>
|
||||
|
@ -17,7 +17,7 @@ export default function MangaList({connected, children}: {connected: boolean, ch
|
||||
if(!connected)
|
||||
return;
|
||||
GetJobsWithType(apiUri, JobType.DownloadAvailableChaptersJob).then((jl) => setJobList(jl as IDownloadAvailableChaptersJob[]));
|
||||
},[apiUri]);
|
||||
},[apiUri,connected]);
|
||||
|
||||
const deleteJob = useCallback((jobId: string) => {
|
||||
DeleteJob(apiUri, jobId).finally(() => getJobList());
|
||||
@ -27,17 +27,24 @@ export default function MangaList({connected, children}: {connected: boolean, ch
|
||||
getJobList();
|
||||
}, [apiUri]);
|
||||
|
||||
const timerRef = React.useRef<ReturnType<typeof setInterval>>(undefined);
|
||||
useEffect(() => {
|
||||
updateTimer();
|
||||
getJobList();
|
||||
}, [connected]);
|
||||
|
||||
const timerRef = React.useRef<ReturnType<typeof setInterval>>(undefined);
|
||||
const updateTimer = () => {
|
||||
if(!connected){
|
||||
console.debug("Clear timer");
|
||||
clearTimeout(timerRef.current);
|
||||
return;
|
||||
}else{
|
||||
console.debug("Add timer");
|
||||
timerRef.current = setInterval(() => {
|
||||
getJobList();
|
||||
}, 2000);
|
||||
}
|
||||
}, [connected,]);
|
||||
}
|
||||
|
||||
return(
|
||||
<Stack direction="row" spacing={1} flexWrap={"wrap"}>
|
||||
|
@ -44,6 +44,7 @@ export default function Settings({open, setOpen, setApiUri, setConnected}:{open:
|
||||
|
||||
const [apiUriAccordionOpen, setApiUriAccordionOpen] = React.useState(true);
|
||||
const [checking, setChecking] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
OnCheckConnection(apiUri);
|
||||
}, []);
|
||||
@ -57,10 +58,13 @@ export default function Settings({open, setOpen, setApiUri, setConnected}:{open:
|
||||
}
|
||||
|
||||
const OnCheckConnection = (uri: string) => {
|
||||
console.log("Checking connection...");
|
||||
setChecking(true);
|
||||
checkConnection(uri)
|
||||
.then((result) => {
|
||||
setConnected(result);
|
||||
if(result)
|
||||
console.log("Connected!");
|
||||
setApiUriAccordionOpen(!result);
|
||||
setApiUriColor(result ? "success" : "danger");
|
||||
if(result)
|
||||
|
Loading…
x
Reference in New Issue
Block a user