2017-06-29 12:54:02 -06:00
|
|
|
import { generateReducer } from "../redux/generate_reducer";
|
|
|
|
import { FarmwareState } from "./interfaces";
|
|
|
|
import { TaggedResource } from "../resources/tagged_resources";
|
|
|
|
import { Actions } from "../constants";
|
|
|
|
|
|
|
|
export let farmwareState: FarmwareState = { currentImage: undefined };
|
|
|
|
|
|
|
|
export let famrwareReducer = generateReducer<FarmwareState>(farmwareState)
|
2017-11-07 16:38:30 -07:00
|
|
|
.add<TaggedResource>(Actions.INIT_RESOURCE, (s, { payload }) => {
|
|
|
|
if (payload.kind === "Image") {
|
|
|
|
s.currentImage = payload.uuid;
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
})
|
2017-06-29 12:54:02 -06:00
|
|
|
.add<string>(Actions.SELECT_IMAGE, (s, { payload }) => {
|
|
|
|
s.currentImage = payload;
|
|
|
|
return s;
|
|
|
|
})
|
|
|
|
.add<TaggedResource>(Actions.DESTROY_RESOURCE_OK, (s, { payload }) => {
|
2017-08-28 05:49:13 -06:00
|
|
|
const thatUUID = payload.uuid;
|
|
|
|
const thisUUID = s.currentImage;
|
2017-06-29 12:54:02 -06:00
|
|
|
if (thisUUID === thatUUID) { s.currentImage = undefined; }
|
|
|
|
return s;
|
|
|
|
});
|