summaryrefslogtreecommitdiff
path: root/opendc-web/opendc-web-ui/src/redux/actions/interaction-level.js
blob: 8381eeef05c43a7b2f8a3ee44b991f434afc2358 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
export const GO_FROM_BUILDING_TO_ROOM = 'GO_FROM_BUILDING_TO_ROOM'
export const GO_FROM_ROOM_TO_RACK = 'GO_FROM_ROOM_TO_RACK'
export const GO_FROM_RACK_TO_MACHINE = 'GO_FROM_RACK_TO_MACHINE'
export const GO_DOWN_ONE_INTERACTION_LEVEL = 'GO_DOWN_ONE_INTERACTION_LEVEL'

export function goToRoom(roomId) {
    return {
        type: GO_FROM_BUILDING_TO_ROOM,
        roomId,
    }
}

export function goFromBuildingToRoom(roomId) {
    return (dispatch, getState) => {
        const { interactionLevel } = getState()
        if (interactionLevel.mode !== 'BUILDING') {
            return
        }

        dispatch({
            type: GO_FROM_BUILDING_TO_ROOM,
            roomId,
        })
    }
}

export function goFromRoomToRack(tileId) {
    return (dispatch, getState) => {
        const { interactionLevel } = getState()
        if (interactionLevel.mode !== 'ROOM') {
            return
        }
        dispatch({
            type: GO_FROM_ROOM_TO_RACK,
            tileId,
        })
    }
}

export function goFromRackToMachine(position) {
    return (dispatch, getState) => {
        const { interactionLevel } = getState()
        if (interactionLevel.mode !== 'RACK') {
            return
        }
        dispatch({
            type: GO_FROM_RACK_TO_MACHINE,
            position,
        })
    }
}

export function goDownOneInteractionLevel() {
    return {
        type: GO_DOWN_ONE_INTERACTION_LEVEL,
    }
}