import { faArrowRotateBack, faXmark } from '@fortawesome/free-solid-svg-icons' import { ActionButton } from '../components/ActionButton' import { AppHeader } from '../components/AppHeader' import { open } from '@tauri-apps/api/dialog' import { BaseUnit, DEFAULT_PROJECT_NAME, baseUnits, } from '../machines/settingsMachine' import { Toggle } from '../components/Toggle/Toggle' import { useLocation, useNavigate, useRouteLoaderData } from 'react-router-dom' import { useHotkeys } from 'react-hotkeys-hook' import { IndexLoaderData, paths } from '../Router' import { Themes } from '../lib/theme' import { useGlobalStateContext } from 'hooks/useGlobalStateContext' import { CameraSystem, cameraSystems, cameraMouseDragGuards, } from 'lib/cameraControls' import { UnitSystem } from 'machines/settingsMachine' import { useDotDotSlash } from 'hooks/useDotDotSlash' import { createNewProject, getNextProjectIndex, getProjectsInDir, interpolateProjectNameWithIndex, } from 'lib/tauriFS' import { ONBOARDING_PROJECT_NAME } from './Onboarding' import { sep } from '@tauri-apps/api/path' import { bracket } from 'lib/exampleKcl' export const Settings = () => { const loaderData = (useRouteLoaderData(paths.FILE) as IndexLoaderData) || undefined const navigate = useNavigate() const location = useLocation() const isFileSettings = location.pathname.includes(paths.FILE) const dotDotSlash = useDotDotSlash() useHotkeys('esc', () => navigate(dotDotSlash())) const { settings: { send, state: { context: { baseUnit, cameraControls, defaultDirectory, defaultProjectName, showDebugPanel, theme, unitSystem, }, }, }, } = useGlobalStateContext() async function handleDirectorySelection() { const newDirectory = await open({ directory: true, defaultPath: defaultDirectory || paths.INDEX, title: 'Choose a new default directory', }) if (newDirectory && newDirectory !== null && !Array.isArray(newDirectory)) { send({ type: 'Set Default Directory', data: { defaultDirectory: newDirectory }, }) } } async function restartOnboarding() { send({ type: 'Set Onboarding Status', data: { onboardingStatus: '' }, }) if (isFileSettings) { navigate(dotDotSlash(1) + paths.ONBOARDING.INDEX) } else { await createAndOpenNewProject() } } async function createAndOpenNewProject() { const projects = await getProjectsInDir(defaultDirectory) const nextIndex = await getNextProjectIndex( ONBOARDING_PROJECT_NAME, projects ) const name = interpolateProjectNameWithIndex( ONBOARDING_PROJECT_NAME, nextIndex ) const newFile = await createNewProject( defaultDirectory + sep + name, bracket ) navigate(`${paths.FILE}/${encodeURIComponent(newFile.path)}`) } return (
Don't see the feature you want? Check to see if it's on{' '} our roadmap , and start a discussion if you don't see it! Your feedback will help us prioritize what to build next.
{description}