..
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 | import React, { useEffect, useState } from 'react'
import { useRouter } from 'next/router'
import ConfigType from '../../common/types/configType'
import { RepoQueryResponse } from '../../common/github/repoQuery'
import ConfigContext from '../contexts/ConfigContext'
import { DEFAULT_CONFIG } from '../../common/configHelper'
import Config from './configuration/config'
import Preview from './preview/preview'
import toast from './toaster'
type MainWrapperProps = {
response: RepoQueryResponse
}
const MainWrapper = ({ response }: MainWrapperProps) => {
const router = useRouter()
const [config, setConfig] = useState<ConfigType>(DEFAULT_CONFIG)
const setConfigHelper = (config: ConfigType) => {
setConfig(config)
}
useEffect(() => {
if (!response || !response.repository) {
router.push('/')
toast.error('Please enter a valid GitHub repository.')
}
}, [response, router])
if (response && response.repository) {
const { repository } = response
return (
<ConfigContext.Provider value={{ config, setConfig: setConfigHelper }}>
<div className="flex flex-col lg:flex-row w-full justify-center items-center lg:justify-evenly">
<div className="hero w-fit">
<Preview />
</div>
<div className="hero w-fit">
<Config repository={repository} />
</div>
</div>
</ConfigContext.Provider>
)
} else {
return null
}
}
export default MainWrapper
|
|