2022-03-31 07:22:36 -04:00
|
|
|
import { createContext, useContext, useState } from 'react'
|
2021-06-16 05:32:38 -04:00
|
|
|
import PropTypes from 'prop-types'
|
2022-03-31 07:22:36 -04:00
|
|
|
import { getMockIde } from './mock/mock-ide'
|
2021-06-16 05:32:38 -04:00
|
|
|
|
|
|
|
const IdeContext = createContext()
|
|
|
|
|
|
|
|
IdeContext.Provider.propTypes = {
|
|
|
|
value: PropTypes.shape({
|
|
|
|
$scope: PropTypes.object.isRequired,
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
|
|
|
|
export function useIdeContext() {
|
|
|
|
const context = useContext(IdeContext)
|
|
|
|
|
|
|
|
if (!context) {
|
|
|
|
throw new Error('useIdeContext is only available inside IdeProvider')
|
|
|
|
}
|
|
|
|
|
|
|
|
return context
|
|
|
|
}
|
|
|
|
|
|
|
|
export function IdeProvider({ ide, children }) {
|
2022-03-31 07:22:36 -04:00
|
|
|
const [value] = useState(() => ide || getMockIde())
|
|
|
|
|
|
|
|
return <IdeContext.Provider value={value}>{children}</IdeContext.Provider>
|
2021-06-16 05:32:38 -04:00
|
|
|
}
|
|
|
|
IdeProvider.propTypes = {
|
|
|
|
children: PropTypes.any.isRequired,
|
|
|
|
ide: PropTypes.shape({
|
|
|
|
$scope: PropTypes.object.isRequired,
|
2022-03-31 07:22:36 -04:00
|
|
|
}),
|
2021-06-16 05:32:38 -04:00
|
|
|
}
|