Files
modeling-app/src/machines/systemIO/systemIOMachineWeb.ts
Frank Noirot 2d77aa0d36 Revert "Make onboarding optional, able to be ignored on desktop" (#6610)
Revert "Make onboarding optional, able to be ignored on desktop (#6564)"

This reverts commit 820082d7f2.
2025-04-30 21:58:11 -04:00

51 lines
1.8 KiB
TypeScript

import { systemIOMachine } from '@src/machines/systemIO/systemIOMachine'
import type { SystemIOContext } from '@src/machines/systemIO/utils'
import { SystemIOMachineActors } from '@src/machines/systemIO/utils'
import { fromPromise } from 'xstate'
import { newKclFile } from '@src/lang/project'
import { readLocalStorageProjectSettingsFile } from '@src/lib/settings/settingsUtils'
import { err } from '@src/lib/trap'
import { DEFAULT_DEFAULT_LENGTH_UNIT } from '@src/lib/constants'
import type { AppMachineContext } from '@src/lib/types'
export const systemIOMachineWeb = systemIOMachine.provide({
actors: {
[SystemIOMachineActors.createKCLFile]: fromPromise(
async ({
input,
}: {
input: {
context: SystemIOContext
requestedProjectName: string
requestedFileName: string
requestedCode: string
rootContext: AppMachineContext
}
}) => {
// Browser version doesn't navigate, just overwrites the current file
// clearImportSearchParams()
const projectSettings = readLocalStorageProjectSettingsFile()
if (err(projectSettings)) {
return Promise.reject(
'Unable to read project settings from local storage'
)
}
const codeToWrite = newKclFile(
input.requestedCode,
projectSettings?.settings?.modeling?.base_unit ||
DEFAULT_DEFAULT_LENGTH_UNIT
)
if (err(codeToWrite)) return Promise.reject(codeToWrite)
input.rootContext.codeManager.updateCodeStateEditor(codeToWrite)
await input.rootContext.codeManager.writeToFile()
await input.rootContext.kclManager.executeCode()
return {
message: 'File overwritten successfully',
fileName: input.requestedFileName,
projectName: '',
}
}
),
},
})