From e3d0380e6fc9005f021ce9eabc62e65a34c19599 Mon Sep 17 00:00:00 2001 From: M Fahru Date: Tue, 3 Jan 2023 10:46:37 -0700 Subject: [PATCH] Remove multiple source of type imports; add `type` on type imports. GitOrigin-RevId: a6630bb284c456bfbe61901f7331cdd3c13c7f8b --- ...-project-wide-settings-socket-listener.tsx | 7 +++--- .../hooks/use-project-wide-settings.tsx | 7 +++--- .../hooks/use-set-overall-theme.tsx | 13 +++++------ .../hooks/use-set-root-doc-id.tsx | 6 ++--- .../hooks/use-set-spell-check-language.tsx | 13 +++++++---- .../hooks/use-user-wide-settings.tsx | 23 ++++++++----------- 6 files changed, 33 insertions(+), 36 deletions(-) diff --git a/services/web/frontend/js/features/editor-left-menu/hooks/use-project-wide-settings-socket-listener.tsx b/services/web/frontend/js/features/editor-left-menu/hooks/use-project-wide-settings-socket-listener.tsx index 9d75fb6b60..822375c4d8 100644 --- a/services/web/frontend/js/features/editor-left-menu/hooks/use-project-wide-settings-socket-listener.tsx +++ b/services/web/frontend/js/features/editor-left-menu/hooks/use-project-wide-settings-socket-listener.tsx @@ -1,5 +1,4 @@ import { useCallback, useEffect } from 'react' -import { ProjectCompiler } from '../../../../../types/project-settings' import { useIdeContext } from '../../../shared/context/ide-context' import useScopeValue from '../../../shared/hooks/use-scope-value' import type { ProjectSettingsScope } from '../utils/api' @@ -12,7 +11,7 @@ export default function useProjectWideSettingsSocketListener() { >('project', true) const setCompiler = useCallback( - (compiler: ProjectCompiler) => { + (compiler: ProjectSettingsScope['compiler']) => { if (projectScope) { setProjectScope({ ...projectScope, compiler }) } @@ -21,7 +20,7 @@ export default function useProjectWideSettingsSocketListener() { ) const setImageName = useCallback( - (imageName: string) => { + (imageName: ProjectSettingsScope['imageName']) => { if (projectScope) { setProjectScope({ ...projectScope, imageName }) } @@ -30,7 +29,7 @@ export default function useProjectWideSettingsSocketListener() { ) const setSpellCheckLanguage = useCallback( - (spellCheckLanguage: string) => { + (spellCheckLanguage: ProjectSettingsScope['spellCheckLanguage']) => { if (projectScope) { setProjectScope({ ...projectScope, spellCheckLanguage }) } diff --git a/services/web/frontend/js/features/editor-left-menu/hooks/use-project-wide-settings.tsx b/services/web/frontend/js/features/editor-left-menu/hooks/use-project-wide-settings.tsx index 3899ac1885..1e051d253a 100644 --- a/services/web/frontend/js/features/editor-left-menu/hooks/use-project-wide-settings.tsx +++ b/services/web/frontend/js/features/editor-left-menu/hooks/use-project-wide-settings.tsx @@ -1,8 +1,7 @@ import { useCallback } from 'react' -import { ProjectCompiler } from '../../../../../types/project-settings' import { useProjectContext } from '../../../shared/context/project-context' import useScopeValue from '../../../shared/hooks/use-scope-value' -import { ProjectSettingsScope, saveProjectSettings } from '../utils/api' +import { type ProjectSettingsScope, saveProjectSettings } from '../utils/api' import useSetRootDocId from './use-set-root-doc-id' import useSetSpellCheckLanguage from './use-set-spell-check-language' @@ -15,7 +14,7 @@ export default function useProjectWideSettings() { const { _id: projectId } = useProjectContext() const setCompiler = useCallback( - (compiler: ProjectCompiler) => { + (compiler: ProjectSettingsScope['compiler']) => { const allowUpdate = project?.compiler if (allowUpdate) { @@ -27,7 +26,7 @@ export default function useProjectWideSettings() { ) const setImageName = useCallback( - (imageName: string) => { + (imageName: ProjectSettingsScope['imageName']) => { const allowUpdate = project?.imageName if (allowUpdate) { diff --git a/services/web/frontend/js/features/editor-left-menu/hooks/use-set-overall-theme.tsx b/services/web/frontend/js/features/editor-left-menu/hooks/use-set-overall-theme.tsx index ae26458c33..8b52a3835a 100644 --- a/services/web/frontend/js/features/editor-left-menu/hooks/use-set-overall-theme.tsx +++ b/services/web/frontend/js/features/editor-left-menu/hooks/use-set-overall-theme.tsx @@ -1,18 +1,17 @@ import { useCallback, useEffect, useState } from 'react' import _ from 'lodash' -import { OverallTheme } from '../../../../../modules/source-editor/frontend/js/extensions/theme' import useScopeValue from '../../../shared/hooks/use-scope-value' -import { OverallThemeMeta } from '../../../../../types/project-settings' -import { saveUserSettings } from '../utils/api' +import type { OverallThemeMeta } from '../../../../../types/project-settings' +import { saveUserSettings, type UserSettingsScope } from '../utils/api' export default function useSetOverallTheme() { const [chosenTheme, setChosenTheme] = useState(null) const [loadingStyleSheet, setLoadingStyleSheet] = useScopeValue( 'ui.loadingStyleSheet' ) - const [overallThemeScope, setOverallThemeScope] = useScopeValue( - 'settings.overallTheme' - ) + const [overallThemeScope, setOverallThemeScope] = useScopeValue< + UserSettingsScope['overallTheme'] + >('settings.overallTheme') useEffect(() => { const docHeadEl = document.querySelector('head') @@ -45,7 +44,7 @@ export default function useSetOverallTheme() { }, [loadingStyleSheet, setLoadingStyleSheet, chosenTheme?.path]) const setOverallTheme = useCallback( - (overallTheme: OverallTheme) => { + (overallTheme: UserSettingsScope['overallTheme']) => { if (overallThemeScope !== overallTheme) { const chosenTheme = _.find( window.overallThemes, diff --git a/services/web/frontend/js/features/editor-left-menu/hooks/use-set-root-doc-id.tsx b/services/web/frontend/js/features/editor-left-menu/hooks/use-set-root-doc-id.tsx index 173b2bbfe2..720a8b76ab 100644 --- a/services/web/frontend/js/features/editor-left-menu/hooks/use-set-root-doc-id.tsx +++ b/services/web/frontend/js/features/editor-left-menu/hooks/use-set-root-doc-id.tsx @@ -2,16 +2,16 @@ import { useCallback } from 'react' import { useEditorContext } from '../../../shared/context/editor-context' import { useProjectContext } from '../../../shared/context/project-context' import useScopeValue from '../../../shared/hooks/use-scope-value' -import { saveProjectSettings } from '../utils/api' +import { type ProjectSettingsScope, saveProjectSettings } from '../utils/api' export default function useSetRootDocId() { const [rootDocIdScope, setRootDocIdScope] = - useScopeValue('project.rootDoc_id') + useScopeValue('project.rootDoc_id') const { permissionsLevel } = useEditorContext() const { _id: projectId } = useProjectContext() const setRootDocId = useCallback( - async (rootDocId: string) => { + async (rootDocId: ProjectSettingsScope['rootDoc_id']) => { const allowUpdate = typeof rootDocIdScope !== 'undefined' && permissionsLevel !== 'readOnly' && diff --git a/services/web/frontend/js/features/editor-left-menu/hooks/use-set-spell-check-language.tsx b/services/web/frontend/js/features/editor-left-menu/hooks/use-set-spell-check-language.tsx index 3e8adfb8f8..db8cc14245 100644 --- a/services/web/frontend/js/features/editor-left-menu/hooks/use-set-spell-check-language.tsx +++ b/services/web/frontend/js/features/editor-left-menu/hooks/use-set-spell-check-language.tsx @@ -2,15 +2,20 @@ import { useCallback } from 'react' import { sendMB } from '../../../infrastructure/event-tracking' import { useProjectContext } from '../../../shared/context/project-context' import useScopeValue from '../../../shared/hooks/use-scope-value' -import { saveProjectSettings, saveUserSettings } from '../utils/api' +import { + type ProjectSettingsScope, + saveProjectSettings, + saveUserSettings, +} from '../utils/api' export default function useSetSpellCheckLanguage() { - const [spellCheckLanguageScope, setSpellCheckLanguageScope] = - useScopeValue('project.spellCheckLanguage') + const [spellCheckLanguageScope, setSpellCheckLanguageScope] = useScopeValue< + ProjectSettingsScope['spellCheckLanguage'] + >('project.spellCheckLanguage') const { _id: projectId } = useProjectContext() const setSpellCheckLanguage = useCallback( - (spellCheckLanguage: string) => { + (spellCheckLanguage: ProjectSettingsScope['spellCheckLanguage']) => { const allowUpdate = spellCheckLanguage && spellCheckLanguage !== spellCheckLanguageScope diff --git a/services/web/frontend/js/features/editor-left-menu/hooks/use-user-wide-settings.tsx b/services/web/frontend/js/features/editor-left-menu/hooks/use-user-wide-settings.tsx index 272e514b37..ba7c9b8bde 100644 --- a/services/web/frontend/js/features/editor-left-menu/hooks/use-user-wide-settings.tsx +++ b/services/web/frontend/js/features/editor-left-menu/hooks/use-user-wide-settings.tsx @@ -1,9 +1,4 @@ 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' @@ -20,63 +15,63 @@ export default function useUserWideSettings() { const setOverallTheme = useSetOverallTheme() const setAutoComplete = useCallback( - (autoComplete: boolean) => { + (autoComplete: UserSettingsScope['autoComplete']) => { saveUserSettings('autoComplete', autoComplete) }, [saveUserSettings] ) const setAutoPairDelimiters = useCallback( - (autoPairDelimiters: boolean) => { + (autoPairDelimiters: UserSettingsScope['autoPairDelimiters']) => { saveUserSettings('autoPairDelimiters', autoPairDelimiters) }, [saveUserSettings] ) const setSyntaxValidation = useCallback( - (syntaxValidation: boolean) => { + (syntaxValidation: UserSettingsScope['syntaxValidation']) => { saveUserSettings('syntaxValidation', syntaxValidation) }, [saveUserSettings] ) const setEditorTheme = useCallback( - (editorTheme: string) => { + (editorTheme: UserSettingsScope['editorTheme']) => { saveUserSettings('editorTheme', editorTheme) }, [saveUserSettings] ) const setMode = useCallback( - (mode: Keybindings) => { + (mode: UserSettingsScope['mode']) => { saveUserSettings('mode', mode) }, [saveUserSettings] ) const setFontSize = useCallback( - (fontSize: string) => { + (fontSize: UserSettingsScope['fontSize']) => { saveUserSettings('fontSize', fontSize) }, [saveUserSettings] ) const setFontFamily = useCallback( - (fontFamily: FontFamily) => { + (fontFamily: UserSettingsScope['fontFamily']) => { saveUserSettings('fontFamily', fontFamily) }, [saveUserSettings] ) const setLineHeight = useCallback( - (lineHeight: LineHeight) => { + (lineHeight: UserSettingsScope['lineHeight']) => { saveUserSettings('lineHeight', lineHeight) }, [saveUserSettings] ) const setPdfViewer = useCallback( - (pdfViewer: PdfViewer) => { + (pdfViewer: UserSettingsScope['pdfViewer']) => { saveUserSettings('pdfViewer', pdfViewer) }, [saveUserSettings]