Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a settings annotation to all new files #5313

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
22 changes: 20 additions & 2 deletions src/components/FileMachineProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ import { useSettingsAuthContext } from 'hooks/useSettingsAuthContext'
import { markOnce } from 'lib/performance'
import { commandBarActor } from 'machines/commandBarMachine'
import { useToken } from 'machines/appMachine'
import { unit } from '@kittycad/lib/dist/types/src'
import { changeKclSettings, unitLengthToUnitLen } from 'lang/wasm'
import { err } from 'lib/trap'

type MachineContext<T extends AnyStateMachine> = {
state: StateFrom<T>
Expand Down Expand Up @@ -159,7 +162,14 @@ export const FileMachineProvider = ({
createdPath
)
} else {
await window.electron.writeFile(createdPath, input.content ?? '')
const codeToWrite = changeKclSettings(input.content ?? '', {
defaultLengthUnits: unitLengthToUnitLen(
settings.context.modeling.defaultUnit.current
),
defaultAngleUnits: { type: 'Degrees' },
})
if (err(codeToWrite)) return Promise.reject(codeToWrite)
await window.electron.writeFile(createdPath, codeToWrite)
}
}

Expand Down Expand Up @@ -188,7 +198,15 @@ export const FileMachineProvider = ({
})
createdName = name
createdPath = path
await window.electron.writeFile(createdPath, input.content ?? '')

const codeToWrite = changeKclSettings(input.content ?? '', {
defaultLengthUnits: unitLengthToUnitLen(
settings.context.modeling.defaultUnit.current
),
defaultAngleUnits: { type: 'Degrees' },
})
if (err(codeToWrite)) return Promise.reject(codeToWrite)
await window.electron.writeFile(createdPath, codeToWrite)
}

return {
Expand Down
20 changes: 18 additions & 2 deletions src/components/ProjectsContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import {
} from 'lib/constants'
import { codeManager, kclManager } from 'lib/singletons'
import { Project } from 'lib/project'
import { changeKclSettings, unitLengthToUnitLen } from 'lang/wasm'
import { err } from 'lib/trap'

type MachineContext<T extends AnyStateMachine> = {
state?: StateFrom<T>
Expand Down Expand Up @@ -122,7 +124,14 @@ const ProjectsContextWeb = ({ children }: { children: React.ReactNode }) => {
createFile: fromPromise(async ({ input }) => {
// Browser version doesn't navigate, just overwrites the current file
clearImportSearchParams()
codeManager.updateCodeStateEditor(input.code || '')
const codeToWrite = changeKclSettings(input.code ?? '', {
defaultLengthUnits: unitLengthToUnitLen(
settings.modeling.defaultUnit.current
),
defaultAngleUnits: { type: 'Degrees' },
})
if (err(codeToWrite)) return Promise.reject(codeToWrite)
codeManager.updateCodeStateEditor(codeToWrite)
await codeManager.writeToFile()
await kclManager.executeCode(true)

Expand Down Expand Up @@ -406,7 +415,14 @@ const ProjectsContextDesktop = ({
})

fileName = name
await window.electron.writeFile(path, input.code || '')
const codeToWrite = changeKclSettings(input.code ?? '', {
defaultLengthUnits: unitLengthToUnitLen(
settings.modeling.defaultUnit.current
),
defaultAngleUnits: { type: 'Degrees' },
})
if (err(codeToWrite)) return Promise.reject(codeToWrite)
await window.electron.writeFile(path, codeToWrite)

return {
message,
Expand Down
Loading