..
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59 | import React from 'react'
import { useRouter } from 'next/router'
import { MdErrorOutline } from 'react-icons/md'
import MainWrapper from './mainWrapper'
import {
getRepoDetails,
RepoQueryResponse
} from '../../common/github/repoQuery'
type Props = {
error: Error | null
props: RepoQueryResponse | undefined
}
const MainRenderer = () => {
const router = useRouter()
const path = router.asPath.split('?')[0]
const [, owner, name] = path.split('/')
const [{ error, props }, setProps] = React.useState<Props>({
error: null,
props: undefined
})
React.useEffect(() => {
if (owner && owner.charAt(0) !== '[') {
getRepoDetails(owner, name)
.then((props) => setProps({ error: null, props }))
.catch((error) => setProps({ error, props: undefined }))
}
}, [owner, name])
return (
<main className="hero">
{error ? (
<div className="hero-content">
<div className="alert alert-error shadow-lg">
<div>
<MdErrorOutline className="w-6 h-6" />
<span>{error.message}</span>
</div>
</div>
</div>
) : !props ? (
<div className="hero-content">
<progress className="progress progress-primary w-56"></progress>
</div>
) : (
<div className="hero-content p-0 w-full max-w-full">
<MainWrapper response={props} />
</div>
)}
</main>
)
}
export default MainRenderer
|
|