2025-04-09 09:46:30 -05:00
|
|
|
import { PATHS } from '@src/lib/paths'
|
|
|
|
import { systemIOActor } from '@src/machines/appMachine'
|
|
|
|
import { useSelector } from '@xstate/react'
|
|
|
|
import { useEffect } from 'react'
|
|
|
|
import { useNavigate } from 'react-router-dom'
|
|
|
|
import {
|
|
|
|
NO_PROJECT_DIRECTORY,
|
2025-04-09 14:47:54 -06:00
|
|
|
SystemIOMachineEvents
|
2025-04-09 09:46:30 -05:00
|
|
|
} from '@src/machines/systemIO/utils'
|
2025-04-09 14:47:54 -06:00
|
|
|
export const useRequestedProjectName = () => useSelector(systemIOActor, (state) => state.context.requestedProjectName)
|
|
|
|
export const useProjectDirectoryPath = () => useSelector(systemIOActor, (state) => state.context.projectDirectoryPath)
|
2025-04-09 09:46:30 -05:00
|
|
|
|
|
|
|
|
|
|
|
export function SystemIOMachineLogicListener() {
|
2025-04-09 14:47:54 -06:00
|
|
|
const requestedProjectName = useRequestedProjectName()
|
|
|
|
const projectDirectoryPath = useProjectDirectoryPath()
|
|
|
|
const navigate = useNavigate()
|
2025-04-09 09:46:30 -05:00
|
|
|
useEffect(() => {
|
2025-04-14 11:28:08 -06:00
|
|
|
if (!requestedProjectName.name) {return}
|
2025-04-09 14:47:54 -06:00
|
|
|
let projectPathWithoutSpecificKCLFile =
|
2025-04-14 11:28:08 -06:00
|
|
|
projectDirectoryPath + window.electron.path.sep + requestedProjectName.name
|
2025-04-09 14:47:54 -06:00
|
|
|
const requestedPath = `${PATHS.FILE}/${encodeURIComponent(
|
|
|
|
projectPathWithoutSpecificKCLFile
|
2025-04-09 09:46:30 -05:00
|
|
|
)}`
|
2025-04-09 14:47:54 -06:00
|
|
|
navigate(requestedPath)
|
|
|
|
}, [requestedProjectName])
|
2025-04-09 09:46:30 -05:00
|
|
|
return null
|
|
|
|
}
|