2022-12-22 13:42:28 -05:00
|
|
|
import { useCallback } from 'react'
|
|
|
|
import useScopeValue from '../../../shared/hooks/use-scope-value'
|
2023-01-06 20:45:37 -05:00
|
|
|
import type { ProjectSettings } from '../utils/api'
|
2023-01-03 17:33:31 -05:00
|
|
|
import useRootDocId from './use-root-doc-id'
|
2023-01-06 20:45:37 -05:00
|
|
|
import useSaveProjectSettings from './use-save-project-settings'
|
2022-12-28 12:02:43 -05:00
|
|
|
import useSetSpellCheckLanguage from './use-set-spell-check-language'
|
2022-12-22 13:42:28 -05:00
|
|
|
|
2023-01-03 12:29:09 -05:00
|
|
|
export default function useProjectWideSettings() {
|
2022-12-22 13:42:28 -05:00
|
|
|
// The value will be undefined on mount
|
2023-01-06 20:45:37 -05:00
|
|
|
const [project] = useScopeValue<ProjectSettings | undefined>('project', true)
|
|
|
|
const saveProjectSettings = useSaveProjectSettings()
|
2022-12-22 13:42:28 -05:00
|
|
|
|
|
|
|
const setCompiler = useCallback(
|
2023-01-06 20:45:37 -05:00
|
|
|
(newCompiler: ProjectSettings['compiler']) => {
|
2023-01-06 20:52:30 -05:00
|
|
|
saveProjectSettings('compiler', newCompiler).catch(console.error)
|
2022-12-22 13:42:28 -05:00
|
|
|
},
|
2023-01-06 20:45:37 -05:00
|
|
|
[saveProjectSettings]
|
2022-12-22 13:42:28 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
const setImageName = useCallback(
|
2023-01-06 20:45:37 -05:00
|
|
|
(newImageName: ProjectSettings['imageName']) => {
|
2023-01-06 20:52:30 -05:00
|
|
|
saveProjectSettings('imageName', newImageName).catch(console.error)
|
2022-12-22 13:42:28 -05:00
|
|
|
},
|
2023-01-06 20:45:37 -05:00
|
|
|
[saveProjectSettings]
|
2022-12-22 13:42:28 -05:00
|
|
|
)
|
|
|
|
|
2023-01-03 17:33:31 -05:00
|
|
|
const { setRootDocId, rootDocId } = useRootDocId()
|
2023-01-03 12:04:34 -05:00
|
|
|
const setSpellCheckLanguage = useSetSpellCheckLanguage()
|
2022-12-22 13:42:28 -05:00
|
|
|
|
|
|
|
return {
|
|
|
|
compiler: project?.compiler,
|
|
|
|
setCompiler,
|
|
|
|
imageName: project?.imageName,
|
|
|
|
setImageName,
|
2023-01-03 17:33:31 -05:00
|
|
|
rootDocId,
|
2022-12-22 13:42:28 -05:00
|
|
|
setRootDocId,
|
|
|
|
spellCheckLanguage: project?.spellCheckLanguage,
|
|
|
|
setSpellCheckLanguage,
|
|
|
|
}
|
|
|
|
}
|