uhh maybe now the alerta will work

This commit is contained in:
Cloudburst 2022-10-02 21:37:57 +02:00 committed by GitHub
parent 9bef6357f8
commit 6b75370283
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -12,20 +12,14 @@ import { IconContext } from "react-icons";
const IndexPage = () => { const IndexPage = () => {
const [repos, setRepos] = useState(null); const [repos, setRepos] = useState(null);
const [afterTimeout, setAfterTimeout] = useState(false); const [hadError, setHadError] = useState(false);
useEffect(() => { useEffect(() => {
setTimeout(() => { fetch("https://raw.githubusercontent.com/recloudstream/cs-repos/master/repos-db.json", { signal: AbortSignal.timeout(5000) })
setAfterTimeout(true) .catch(err => { setHadError(true) })
}, 5000);
fetch("https://raw.githubusercontent.com/recloudstream/cs-repos/master/repos-db.json")
.catch(err => {
setAfterTimeout(true)
})
.then(r => r.json()) .then(r => r.json())
.then(data => { .then(setRepos)
setRepos(data) .catch(err => { setHadError(true) })
})
}, [setRepos]) }, [setRepos])
return <Layout> return <Layout>
@ -47,7 +41,7 @@ const IndexPage = () => {
</div> </div>
</div> </div>
</div> </div>
{(!repos && !afterTimeout) && {(!repos && !setHadError) &&
<div class="alert shadow-lg w-full mx-10 md:w-2/3 mb-5"> <div class="alert shadow-lg w-full mx-10 md:w-2/3 mb-5">
<div> <div>
<span>Fetching data...</span> <span>Fetching data...</span>
@ -60,7 +54,7 @@ const IndexPage = () => {
{repos.map((it, index) => <RepoCard repoData={it} key={index} isFirst={index===0}/>)} {repos.map((it, index) => <RepoCard repoData={it} key={index} isFirst={index===0}/>)}
</> </>
} }
{(!repos && afterTimeout) && {(!repos && setHadError) &&
<div class="alert alert-error shadow-lg w-full mx-10 md:w-2/3 mb-5"> <div class="alert alert-error shadow-lg w-full mx-10 md:w-2/3 mb-5">
<div> <div>
<BiErrorAlt /> <BiErrorAlt />