1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-25 14:34:19 +00:00

🐛 Fix box repositories being stuck in loading

This commit is contained in:
Stefano Pigozzi 2021-05-10 14:13:12 +02:00
parent 0b9b5e301a
commit d9ea43c9b4
Signed by untrusted user who does not match committer: steffo
GPG key ID: 6965406171929D01
3 changed files with 16 additions and 13 deletions

View file

@ -18,18 +18,15 @@ import useDataImmediately from "../../hooks/useDataImmediately"
*/ */
export default function BoxRepositoriesActive({ ...props }) { export default function BoxRepositoriesActive({ ...props }) {
const {user, fetchDataAuth} = useContext(ContextUser) const {user, fetchDataAuth} = useContext(ContextUser)
const {data, started, loading, error} = useDataImmediately(fetchDataAuth, "GET", "/api/v1/repositories/", { const {data, error, loading, fetchNow} = useDataImmediately(fetchDataAuth, "GET", "/api/v1/repositories/", {
"onlyActive": true, "onlyActive": true,
}) })
let contents; let contents;
if(!started || loading) { if(error) {
contents = <Loading/>
}
else if(error) {
contents = <BoxAlert color={"Red"}>{error.toString()}</BoxAlert> contents = <BoxAlert color={"Red"}>{error.toString()}</BoxAlert>
} }
else { else if(data) {
let repositories = [...data["owner"], ...data["spectator"]] let repositories = [...data["owner"], ...data["spectator"]]
if(repositories.length > 0) { if(repositories.length > 0) {
contents = repositories.map(repo => ( contents = repositories.map(repo => (
@ -46,6 +43,9 @@ export default function BoxRepositoriesActive({ ...props }) {
contents = <i>There's nothing here.</i> contents = <i>There's nothing here.</i>
} }
} }
else {
contents = <Loading/>
}
return ( return (
<BoxFull header={"Your active repositories"} {...props}> <BoxFull header={"Your active repositories"} {...props}>

View file

@ -22,13 +22,10 @@ export default function BoxRepositoriesArchived({ ...props }) {
}) })
let contents; let contents;
if(!started || loading) { if(error) {
contents = <Loading/>
}
else if(error) {
contents = <BoxAlert color={"Red"}>{error.toString()}</BoxAlert> contents = <BoxAlert color={"Red"}>{error.toString()}</BoxAlert>
} }
else { else if(data) {
let repositories = [...data["owner"], ...data["spectator"]] let repositories = [...data["owner"], ...data["spectator"]]
if(repositories.length > 0) { if(repositories.length > 0) {
contents = repositories.map(repo => ( contents = repositories.map(repo => (
@ -45,6 +42,9 @@ export default function BoxRepositoriesArchived({ ...props }) {
contents = <i>There's nothing here.</i> contents = <i>There's nothing here.</i>
} }
} }
else {
contents = <Loading/>
}
return ( return (
<BoxFull header={"Your archived repositories"} {...props}> <BoxFull header={"Your archived repositories"} {...props}>

View file

@ -20,16 +20,19 @@ export default function useData(fetchData, method, path, body, init) {
*/ */
const load = useCallback( const load = useCallback(
async () => { async () => {
console.debug(`Trying to ${method} ${path}...`) console.debug(`Loading ${method} ${path}...`)
setLoading(true) setLoading(true)
console.debug(`Fetching ${method} ${path}...`)
try { try {
const _data = await fetchData(method, path, body, init) const _data = await fetchData(method, path, body, init)
console.debug(`Displaying data of ${method} ${path}: `, _data)
setData(_data) setData(_data)
} catch(e) { } catch(e) {
console.debug(`Displaying error of ${method} ${path}: `, e)
setError(e) setError(e)
} finally { } finally {
console.debug(`Stopping loading of ${method} ${path}...`)
setLoading(false) setLoading(false)
} }
}, },