Added base handled for job decode and watcher start/top

This commit is contained in:
Patrick Fic
2020-10-14 11:26:10 -07:00
parent 953ea832e2
commit e7614942e5
25 changed files with 285 additions and 189 deletions

View File

@@ -1,49 +1,36 @@
import ApplicationActionTypes from "./application.types";
import _ from "lodash";
const INITIAL_STATE = {
rooms: [],
images: {
id: [],
},
watcherStatus: "Not Started",
watchedPaths: [],
watcherError: null,
};
const applicationReducer = (state = INITIAL_STATE, action) => {
switch (action.type) {
case ApplicationActionTypes.SET_ROOMS:
case ApplicationActionTypes.SET_WATCHED_PATHS:
return {
...state,
rooms: _.unionBy(state.rooms, action.payload, "id"),
watchedPaths: action.payload,
};
case ApplicationActionTypes.ADD_ROOM:
case ApplicationActionTypes.ADD_WATCHED_PATH:
return {
...state,
rooms: _.unionBy(state.rooms, [action.payload], "id"),
watchedPaths: [...state.watchedPaths, action.payload],
};
case ApplicationActionTypes.ADD_IMAGES_TO_ROOM:
case ApplicationActionTypes.REMOVE_WATCHED_PATH:
return {
...state,
images: {
...state.images,
[action.payload.roomId]: _.unionBy(
state.images[action.payload.roomId] || [],
action.payload.images,
"filename"
),
},
watchedPaths: state.watchedPaths.filter((p) => p !== action.payload),
};
case ApplicationActionTypes.REMOVE_ROOM:
case ApplicationActionTypes.SET_WATCHER_STATUS:
return {
...state,
rooms: state.rooms.filter((r) => r.id !== action.payload),
watcherStatus: action.payload,
};
case ApplicationActionTypes.MARK_ROOM_NA:
case ApplicationActionTypes.SET_WATCHER_ERROR:
return {
...state,
rooms: state.rooms.map((room) =>
room.id === action.payload ? { ...room, na: true } : room
),
watcherError: action.payload,
};
default:
return state;