Move settings types and initial values to lib/settings (#1698)
This commit is contained in:
@ -23,10 +23,8 @@ import { metadata } from 'tauri-plugin-fs-extra-api'
|
|||||||
import DownloadAppBanner from './components/DownloadAppBanner'
|
import DownloadAppBanner from './components/DownloadAppBanner'
|
||||||
import { WasmErrBanner } from './components/WasmErrBanner'
|
import { WasmErrBanner } from './components/WasmErrBanner'
|
||||||
import { SettingsAuthProvider } from './components/SettingsAuthProvider'
|
import { SettingsAuthProvider } from './components/SettingsAuthProvider'
|
||||||
import {
|
import { settingsMachine } from './machines/settingsMachine'
|
||||||
SETTINGS_PERSIST_KEY,
|
import { SETTINGS_PERSIST_KEY } from './lib/settings'
|
||||||
settingsMachine,
|
|
||||||
} from './machines/settingsMachine'
|
|
||||||
import { ContextFrom } from 'xstate'
|
import { ContextFrom } from 'xstate'
|
||||||
import CommandBarProvider, {
|
import CommandBarProvider, {
|
||||||
CommandBar,
|
CommandBar,
|
||||||
|
@ -24,7 +24,7 @@ import { useModelingContext } from 'hooks/useModelingContext'
|
|||||||
import * as TWEEN from '@tweenjs/tween.js'
|
import * as TWEEN from '@tweenjs/tween.js'
|
||||||
import { SourceRange } from 'lang/wasm'
|
import { SourceRange } from 'lang/wasm'
|
||||||
import { Axis } from 'lib/selections'
|
import { Axis } from 'lib/selections'
|
||||||
import { BaseUnit, SETTINGS_PERSIST_KEY } from 'machines/settingsMachine'
|
import { BaseUnit, SETTINGS_PERSIST_KEY } from 'lib/settings'
|
||||||
import { CameraControls } from './CameraControls'
|
import { CameraControls } from './CameraControls'
|
||||||
|
|
||||||
type SendType = ReturnType<typeof useModelingContext>['send']
|
type SendType = ReturnType<typeof useModelingContext>['send']
|
||||||
|
@ -5,7 +5,8 @@ import { authMachine, TOKEN_PERSIST_KEY } from '../machines/authMachine'
|
|||||||
import withBaseUrl from '../lib/withBaseURL'
|
import withBaseUrl from '../lib/withBaseURL'
|
||||||
import React, { createContext, useEffect, useRef } from 'react'
|
import React, { createContext, useEffect, useRef } from 'react'
|
||||||
import useStateMachineCommands from '../hooks/useStateMachineCommands'
|
import useStateMachineCommands from '../hooks/useStateMachineCommands'
|
||||||
import { SETTINGS_PERSIST_KEY, settingsMachine } from 'machines/settingsMachine'
|
import { settingsMachine } from 'machines/settingsMachine'
|
||||||
|
import { SETTINGS_PERSIST_KEY } from 'lib/settings'
|
||||||
import { toast } from 'react-hot-toast'
|
import { toast } from 'react-hot-toast'
|
||||||
import { setThemeClass, Themes } from 'lib/theme'
|
import { setThemeClass, Themes } from 'lib/theme'
|
||||||
import {
|
import {
|
||||||
|
@ -1,11 +1,6 @@
|
|||||||
import { CommandSetConfig } from '../commandTypes'
|
import { CommandSetConfig } from '../commandTypes'
|
||||||
import {
|
import { BaseUnit, Toggle, UnitSystem, baseUnitsUnion } from 'lib/settings'
|
||||||
BaseUnit,
|
import { settingsMachine } from 'machines/settingsMachine'
|
||||||
Toggle,
|
|
||||||
UnitSystem,
|
|
||||||
baseUnitsUnion,
|
|
||||||
settingsMachine,
|
|
||||||
} from 'machines/settingsMachine'
|
|
||||||
import { CameraSystem, cameraSystems } from '../cameraControls'
|
import { CameraSystem, cameraSystems } from '../cameraControls'
|
||||||
import { Themes } from '../theme'
|
import { Themes } from '../theme'
|
||||||
|
|
||||||
|
47
src/lib/settings.ts
Normal file
47
src/lib/settings.ts
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
import { type Models } from '@kittycad/lib'
|
||||||
|
import { CameraSystem } from './cameraControls'
|
||||||
|
import { Themes } from './theme'
|
||||||
|
|
||||||
|
export const DEFAULT_PROJECT_NAME = 'project-$nnn'
|
||||||
|
export const SETTINGS_PERSIST_KEY = 'SETTINGS_PERSIST_KEY'
|
||||||
|
export const SETTINGS_FILE_NAME = 'settings.json'
|
||||||
|
|
||||||
|
export enum UnitSystem {
|
||||||
|
Imperial = 'imperial',
|
||||||
|
Metric = 'metric',
|
||||||
|
}
|
||||||
|
|
||||||
|
export const baseUnits = {
|
||||||
|
imperial: ['in', 'ft', 'yd'],
|
||||||
|
metric: ['mm', 'cm', 'm'],
|
||||||
|
} as const
|
||||||
|
|
||||||
|
export type BaseUnit = Models['UnitLength_type']
|
||||||
|
|
||||||
|
export const baseUnitsUnion = Object.values(baseUnits).flatMap((v) => v)
|
||||||
|
|
||||||
|
export type Toggle = 'On' | 'Off'
|
||||||
|
|
||||||
|
export type SettingsMachineContext = {
|
||||||
|
baseUnit: BaseUnit
|
||||||
|
cameraControls: CameraSystem
|
||||||
|
defaultDirectory: string
|
||||||
|
defaultProjectName: string
|
||||||
|
onboardingStatus: string
|
||||||
|
showDebugPanel: boolean
|
||||||
|
textWrapping: Toggle
|
||||||
|
theme: Themes
|
||||||
|
unitSystem: UnitSystem
|
||||||
|
}
|
||||||
|
|
||||||
|
export const initialSettings: SettingsMachineContext = {
|
||||||
|
baseUnit: 'mm' as BaseUnit,
|
||||||
|
cameraControls: 'KittyCAD' as CameraSystem,
|
||||||
|
defaultDirectory: '',
|
||||||
|
defaultProjectName: DEFAULT_PROJECT_NAME,
|
||||||
|
onboardingStatus: '',
|
||||||
|
showDebugPanel: false,
|
||||||
|
textWrapping: 'On' as Toggle,
|
||||||
|
theme: Themes.System,
|
||||||
|
unitSystem: UnitSystem.Metric,
|
||||||
|
}
|
@ -1,44 +1,19 @@
|
|||||||
import { assign, createMachine } from 'xstate'
|
import { assign, createMachine } from 'xstate'
|
||||||
import { Themes, getSystemTheme, setThemeClass } from '../lib/theme'
|
import { Themes, getSystemTheme, setThemeClass } from '../lib/theme'
|
||||||
import { CameraSystem } from 'lib/cameraControls'
|
import { CameraSystem } from 'lib/cameraControls'
|
||||||
import { Models } from '@kittycad/lib'
|
import {
|
||||||
|
BaseUnit,
|
||||||
|
DEFAULT_PROJECT_NAME,
|
||||||
|
SETTINGS_PERSIST_KEY,
|
||||||
|
SettingsMachineContext,
|
||||||
|
Toggle,
|
||||||
|
UnitSystem,
|
||||||
|
} from 'lib/settings'
|
||||||
|
|
||||||
const kclManagerPromise = import('lang/KclSingleton').then(
|
const kclManagerPromise = import('lang/KclSingleton').then(
|
||||||
(module) => module.kclManager
|
(module) => module.kclManager
|
||||||
)
|
)
|
||||||
|
|
||||||
export const DEFAULT_PROJECT_NAME = 'project-$nnn'
|
|
||||||
|
|
||||||
export enum UnitSystem {
|
|
||||||
Imperial = 'imperial',
|
|
||||||
Metric = 'metric',
|
|
||||||
}
|
|
||||||
|
|
||||||
export const baseUnits = {
|
|
||||||
imperial: ['in', 'ft', 'yd'],
|
|
||||||
metric: ['mm', 'cm', 'm'],
|
|
||||||
} as const
|
|
||||||
|
|
||||||
export type BaseUnit = Models['UnitLength_type']
|
|
||||||
|
|
||||||
export const baseUnitsUnion = Object.values(baseUnits).flatMap((v) => v)
|
|
||||||
|
|
||||||
export type Toggle = 'On' | 'Off'
|
|
||||||
|
|
||||||
export const SETTINGS_PERSIST_KEY = 'SETTINGS_PERSIST_KEY'
|
|
||||||
|
|
||||||
type SettingsMachineContext = {
|
|
||||||
baseUnit: BaseUnit
|
|
||||||
cameraControls: CameraSystem
|
|
||||||
defaultDirectory: string
|
|
||||||
defaultProjectName: string
|
|
||||||
onboardingStatus: string
|
|
||||||
showDebugPanel: boolean
|
|
||||||
textWrapping: Toggle
|
|
||||||
theme: Themes
|
|
||||||
unitSystem: UnitSystem
|
|
||||||
}
|
|
||||||
|
|
||||||
export const settingsMachine = createMachine(
|
export const settingsMachine = createMachine(
|
||||||
{
|
{
|
||||||
/** @xstate-layout N4IgpgJg5mDOIC5QGUwBc0EsB2VYDpMIAbMAYlTQAIAVACzAFswBtABgF1FQAHAe1iYsfbNxAAPRAA42+AEwB2KQFYAzGznKAnADZli1QBoQAT2kBGKfm37lOned3nzqgL6vjlLLgJFSFdCoAETAAMwBDAFdiagAFACc+ACswAGNqADlw5nYuJBB+QWFRfMkEABY5fDYa2rra83LjMwQdLWV8BXLyuxlVLU1Ld090bzxCEnJKYLComODMeLS0PniTXLFCoUwRMTK7fC1zNql7NgUjtnKjU0RlBSqpLVUVPVUda60tYZAvHHG-F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import useStateMachineCommands from '../hooks/useStateMachineCommands'
|
import useStateMachineCommands from '../hooks/useStateMachineCommands'
|
||||||
import { useSettingsAuthContext } from 'hooks/useSettingsAuthContext'
|
import { useSettingsAuthContext } from 'hooks/useSettingsAuthContext'
|
||||||
import { useCommandsContext } from 'hooks/useCommandsContext'
|
import { useCommandsContext } from 'hooks/useCommandsContext'
|
||||||
import { DEFAULT_PROJECT_NAME } from 'machines/settingsMachine'
|
import { DEFAULT_PROJECT_NAME } from 'lib/settings'
|
||||||
import { sep } from '@tauri-apps/api/path'
|
import { sep } from '@tauri-apps/api/path'
|
||||||
import { homeCommandBarConfig } from 'lib/commandBarConfigs/homeCommandConfig'
|
import { homeCommandBarConfig } from 'lib/commandBarConfigs/homeCommandConfig'
|
||||||
import { useHotkeys } from 'react-hotkeys-hook'
|
import { useHotkeys } from 'react-hotkeys-hook'
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
import { faArrowRight, faXmark } from '@fortawesome/free-solid-svg-icons'
|
import { faArrowRight, faXmark } from '@fortawesome/free-solid-svg-icons'
|
||||||
import { BaseUnit, baseUnits } from '../../machines/settingsMachine'
|
import { BaseUnit, baseUnits, UnitSystem } from 'lib/settings'
|
||||||
import { ActionButton } from '../../components/ActionButton'
|
import { ActionButton } from 'components/ActionButton'
|
||||||
import { SettingsSection } from '../Settings'
|
import { SettingsSection } from '../Settings'
|
||||||
import { Toggle } from '../../components/Toggle/Toggle'
|
import { Toggle } from 'components/Toggle/Toggle'
|
||||||
import { useDismiss, useNextClick } from '.'
|
import { useDismiss, useNextClick } from '.'
|
||||||
import { onboardingPaths } from 'routes/Onboarding/paths'
|
import { onboardingPaths } from 'routes/Onboarding/paths'
|
||||||
import { useSettingsAuthContext } from 'hooks/useSettingsAuthContext'
|
import { useSettingsAuthContext } from 'hooks/useSettingsAuthContext'
|
||||||
import { UnitSystem } from 'machines/settingsMachine'
|
|
||||||
|
|
||||||
export default function Units() {
|
export default function Units() {
|
||||||
const dismiss = useDismiss()
|
const dismiss = useDismiss()
|
||||||
|
@ -2,12 +2,8 @@ import { faArrowRotateBack, faXmark } from '@fortawesome/free-solid-svg-icons'
|
|||||||
import { ActionButton } from '../components/ActionButton'
|
import { ActionButton } from '../components/ActionButton'
|
||||||
import { AppHeader } from '../components/AppHeader'
|
import { AppHeader } from '../components/AppHeader'
|
||||||
import { open } from '@tauri-apps/api/dialog'
|
import { open } from '@tauri-apps/api/dialog'
|
||||||
import {
|
import { BaseUnit, DEFAULT_PROJECT_NAME, baseUnits } from 'lib/settings'
|
||||||
BaseUnit,
|
import { Toggle } from 'components/Toggle/Toggle'
|
||||||
DEFAULT_PROJECT_NAME,
|
|
||||||
baseUnits,
|
|
||||||
} from '../machines/settingsMachine'
|
|
||||||
import { Toggle } from '../components/Toggle/Toggle'
|
|
||||||
import { useLocation, useNavigate, useRouteLoaderData } from 'react-router-dom'
|
import { useLocation, useNavigate, useRouteLoaderData } from 'react-router-dom'
|
||||||
import { useHotkeys } from 'react-hotkeys-hook'
|
import { useHotkeys } from 'react-hotkeys-hook'
|
||||||
import { type IndexLoaderData } from 'lib/types'
|
import { type IndexLoaderData } from 'lib/types'
|
||||||
@ -19,7 +15,7 @@ import {
|
|||||||
cameraSystems,
|
cameraSystems,
|
||||||
cameraMouseDragGuards,
|
cameraMouseDragGuards,
|
||||||
} from 'lib/cameraControls'
|
} from 'lib/cameraControls'
|
||||||
import { UnitSystem } from 'machines/settingsMachine'
|
import { UnitSystem } from 'lib/settings'
|
||||||
import { useDotDotSlash } from 'hooks/useDotDotSlash'
|
import { useDotDotSlash } from 'hooks/useDotDotSlash'
|
||||||
import {
|
import {
|
||||||
createNewProject,
|
createNewProject,
|
||||||
|
Reference in New Issue
Block a user