summaryrefslogtreecommitdiff
path: root/opendc-web/opendc-web-ui/src/redux/sagas/prefabs.js
blob: ec6793914940c423b6e41080afffce8ab2dfb115 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import { call, put, select, getContext } from 'redux-saga/effects'
import { addToStore } from '../actions/objects'
import { addPrefab } from '../../api/prefabs'
import { getRackById } from './objects'

export function* onAddPrefab(action) {
    try {
        const currentRackId = yield select((state) => state.objects.tile[state.interactionLevel.tileId].rackId)
        const currentRackJson = yield getRackById(currentRackId, false)
        const auth = yield getContext('auth')
        const prefab = yield call(addPrefab, auth, { name: action.name, rack: currentRackJson })
        yield put(addToStore('prefab', prefab))
    } catch (error) {
        console.error(error)
    }
}