create / open simulations
This commit is contained in:
parent
057c2268ac
commit
097c44e86e
43 changed files with 596 additions and 84 deletions
src/modules/create-simulation/stores
|
@ -0,0 +1,46 @@
|
|||
import { BehaviorSubject, Subject } from 'rxjs'
|
||||
import { take } from 'rxjs/operators'
|
||||
import { simulationMode } from '../../saving/types/SimulationSave'
|
||||
import { InputStore } from '../../input/stores/InputStore'
|
||||
|
||||
export type CreateSimulationStoreAction = 'quit' | 'submit'
|
||||
|
||||
export const CreateSimulationStore = {
|
||||
create: async () => {
|
||||
CreateSimulationStore.open()
|
||||
|
||||
const action = await CreateSimulationStore.actions
|
||||
.pipe(take(1))
|
||||
.toPromise()
|
||||
|
||||
CreateSimulationStore.close()
|
||||
|
||||
if (action === 'quit') {
|
||||
return null
|
||||
}
|
||||
|
||||
const name = await InputStore.get(
|
||||
'What do you want your simulation to be called?'
|
||||
)
|
||||
|
||||
if (!name) {
|
||||
return null
|
||||
}
|
||||
|
||||
return {
|
||||
mode: CreateSimulationStore.data.output.value,
|
||||
name
|
||||
}
|
||||
},
|
||||
open() {
|
||||
CreateSimulationStore.data.open.next(true)
|
||||
},
|
||||
close() {
|
||||
CreateSimulationStore.data.open.next(false)
|
||||
},
|
||||
data: {
|
||||
open: new BehaviorSubject(false),
|
||||
output: new BehaviorSubject<simulationMode>('project')
|
||||
},
|
||||
actions: new Subject<CreateSimulationStoreAction>()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue