2022-12-23 18:43:26 -05:00
|
|
|
import { useCallback } from 'react'
|
|
|
|
import {
|
|
|
|
FontFamily,
|
|
|
|
LineHeight,
|
|
|
|
} from '../../../../../modules/source-editor/frontend/js/extensions/theme'
|
|
|
|
import { Keybindings, PdfViewer } from '../../../../../types/project-settings'
|
|
|
|
import useScopeValue from '../../../shared/hooks/use-scope-value'
|
|
|
|
import useSetOverallTheme from './use-set-overall-theme'
|
|
|
|
import useSaveUserSettings from './use-save-user-settings'
|
|
|
|
import type { UserSettingsScope } from '../utils/api'
|
|
|
|
|
|
|
|
export default function useUserWideSettings() {
|
|
|
|
const saveUserSettings = useSaveUserSettings()
|
2022-12-28 12:17:44 -05:00
|
|
|
const [userSettings] = useScopeValue<UserSettingsScope | undefined>('settings', true)
|
2022-12-23 18:43:26 -05:00
|
|
|
|
|
|
|
const setOverallTheme = useSetOverallTheme()
|
|
|
|
const setAutoComplete = useCallback(
|
|
|
|
(autoComplete: boolean) => {
|
|
|
|
saveUserSettings<boolean>('autoComplete', autoComplete)
|
|
|
|
},
|
|
|
|
[saveUserSettings]
|
|
|
|
)
|
|
|
|
|
|
|
|
const setAutoPairDelimiters = useCallback(
|
|
|
|
(autoPairDelimiters: boolean) => {
|
|
|
|
saveUserSettings<boolean>('autoPairDelimiters', autoPairDelimiters)
|
|
|
|
},
|
|
|
|
[saveUserSettings]
|
|
|
|
)
|
|
|
|
|
|
|
|
const setSyntaxValidation = useCallback(
|
|
|
|
(syntaxValidation: boolean) => {
|
|
|
|
saveUserSettings<boolean>('syntaxValidation', syntaxValidation)
|
|
|
|
},
|
|
|
|
[saveUserSettings]
|
|
|
|
)
|
|
|
|
|
|
|
|
const setEditorTheme = useCallback(
|
|
|
|
(editorTheme: string) => {
|
|
|
|
saveUserSettings<string>('editorTheme', editorTheme)
|
|
|
|
},
|
|
|
|
[saveUserSettings]
|
|
|
|
)
|
|
|
|
|
|
|
|
const setMode = useCallback(
|
|
|
|
(mode: Keybindings) => {
|
|
|
|
saveUserSettings<Keybindings>('mode', mode)
|
|
|
|
},
|
|
|
|
[saveUserSettings]
|
|
|
|
)
|
|
|
|
|
|
|
|
const setFontSize = useCallback(
|
|
|
|
(fontSize: string) => {
|
|
|
|
saveUserSettings<string>('fontSize', fontSize)
|
|
|
|
},
|
|
|
|
[saveUserSettings]
|
|
|
|
)
|
|
|
|
|
|
|
|
const setFontFamily = useCallback(
|
|
|
|
(fontFamily: FontFamily) => {
|
|
|
|
saveUserSettings<FontFamily>('fontFamily', fontFamily)
|
|
|
|
},
|
|
|
|
[saveUserSettings]
|
|
|
|
)
|
|
|
|
|
|
|
|
const setLineHeight = useCallback(
|
|
|
|
(lineHeight: LineHeight) => {
|
|
|
|
saveUserSettings<LineHeight>('lineHeight', lineHeight)
|
|
|
|
},
|
|
|
|
[saveUserSettings]
|
|
|
|
)
|
|
|
|
|
|
|
|
const setPdfViewer = useCallback(
|
|
|
|
(pdfViewer: PdfViewer) => {
|
|
|
|
saveUserSettings<PdfViewer>('pdfViewer', pdfViewer)
|
|
|
|
},
|
|
|
|
[saveUserSettings]
|
|
|
|
)
|
|
|
|
|
|
|
|
return {
|
2022-12-28 12:17:44 -05:00
|
|
|
autoComplete: userSettings?.autoComplete,
|
2022-12-23 18:43:26 -05:00
|
|
|
setAutoComplete,
|
2022-12-28 12:17:44 -05:00
|
|
|
autoPairDelimiters: userSettings?.autoPairDelimiters,
|
2022-12-23 18:43:26 -05:00
|
|
|
setAutoPairDelimiters,
|
2022-12-28 12:17:44 -05:00
|
|
|
syntaxValidation: userSettings?.syntaxValidation,
|
2022-12-23 18:43:26 -05:00
|
|
|
setSyntaxValidation,
|
2022-12-28 12:17:44 -05:00
|
|
|
editorTheme: userSettings?.editorTheme,
|
2022-12-23 18:43:26 -05:00
|
|
|
setEditorTheme,
|
2022-12-28 12:17:44 -05:00
|
|
|
overallTheme: userSettings?.overallTheme,
|
2022-12-23 18:43:26 -05:00
|
|
|
setOverallTheme,
|
2022-12-28 12:17:44 -05:00
|
|
|
mode: userSettings?.mode,
|
2022-12-23 18:43:26 -05:00
|
|
|
setMode,
|
2022-12-28 12:17:44 -05:00
|
|
|
fontSize: userSettings?.fontSize,
|
2022-12-23 18:43:26 -05:00
|
|
|
setFontSize,
|
2022-12-28 12:17:44 -05:00
|
|
|
fontFamily: userSettings?.fontFamily,
|
2022-12-23 18:43:26 -05:00
|
|
|
setFontFamily,
|
2022-12-28 12:17:44 -05:00
|
|
|
lineHeight: userSettings?.lineHeight,
|
2022-12-23 18:43:26 -05:00
|
|
|
setLineHeight,
|
2022-12-28 12:17:44 -05:00
|
|
|
pdfViewer: userSettings?.pdfViewer,
|
2022-12-23 18:43:26 -05:00
|
|
|
setPdfViewer,
|
|
|
|
}
|
|
|
|
}
|