2017-06-29 12:54:02 -06:00
|
|
|
import { SequenceReducerState } from "./interfaces";
|
|
|
|
import { generateReducer } from "../redux/generate_reducer";
|
2018-08-01 07:03:35 -06:00
|
|
|
import { TaggedResource } from "farmbot";
|
2017-06-29 12:54:02 -06:00
|
|
|
import { Actions } from "../constants";
|
|
|
|
|
|
|
|
export const initialState: SequenceReducerState = {
|
2019-01-12 05:25:02 -07:00
|
|
|
current: undefined,
|
|
|
|
menuOpen: false,
|
2019-04-09 19:45:59 -06:00
|
|
|
stepIndex: undefined,
|
2017-06-29 12:54:02 -06:00
|
|
|
};
|
|
|
|
|
2019-12-10 12:53:20 -07:00
|
|
|
export const sequenceReducer = generateReducer<SequenceReducerState>(initialState)
|
2017-06-29 12:54:02 -06:00
|
|
|
.add<TaggedResource>(Actions.DESTROY_RESOURCE_OK, (s, { payload }) => {
|
|
|
|
switch (payload.uuid) {
|
|
|
|
case s.current:
|
|
|
|
s.current = undefined;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
})
|
2017-07-07 09:03:52 -06:00
|
|
|
.add<string>(Actions.SELECT_SEQUENCE, function (s, { payload }) {
|
2017-06-29 12:54:02 -06:00
|
|
|
s.current = payload;
|
|
|
|
return s;
|
2019-01-12 05:25:02 -07:00
|
|
|
})
|
|
|
|
.add<boolean>(Actions.SET_SEQUENCE_POPUP_STATE, function (s, { payload }) {
|
|
|
|
s.menuOpen = payload;
|
|
|
|
return s;
|
2019-04-09 19:45:59 -06:00
|
|
|
})
|
2019-09-23 12:56:35 -06:00
|
|
|
.add<number | undefined>(Actions.SET_SEQUENCE_STEP_POSITION,
|
|
|
|
function (s, { payload }) {
|
|
|
|
s.stepIndex = payload;
|
|
|
|
return s;
|
|
|
|
});
|