This commit is contained in:
Frank Noirot
2024-10-28 14:28:43 -04:00
parent 74c9596506
commit 8ede8bc1e6
2 changed files with 68 additions and 63 deletions

View File

@ -2,7 +2,9 @@ import { InteractionMapMachineContext } from 'components/InteractionMapMachinePr
export const useInteractionMapContext = () => {
const interactionMapActor = InteractionMapMachineContext.useActorRef()
const interactionMapState = InteractionMapMachineContext.useSelector((state) => state)
const interactionMapState = InteractionMapMachineContext.useSelector(
(state) => state
)
return {
actor: interactionMapActor,
send: interactionMapActor.send,

View File

@ -229,14 +229,13 @@ export const interactionMapMachine = setup({
reject()
} else {
// return the last-added, available exact match
resolve(
availableExactMatches[availableExactMatches.length - 1][1]
)
resolve(availableExactMatches[availableExactMatches.length - 1][1])
}
})
}
),
'Execute keymap action': fromPromise(async ({ input }: { input: InteractionMapItem}) => {
'Execute keymap action': fromPromise(
async ({ input }: { input: InteractionMapItem }) => {
try {
console.log('Executing action', input)
input.action()
@ -244,11 +243,15 @@ export const interactionMapMachine = setup({
console.error(error)
toast.error('There was an error executing the action.')
}
}),
}
),
},
guards: {
'There are prefix matches': ({ event }) => {
return event.type === 'xstate.error.actor.resolveHotkeyByPrefix' && event.data !== undefined
return (
event.type === 'xstate.error.actor.resolveHotkeyByPrefix' &&
event.data !== undefined
)
},
},
}).createMachine({