Up to date CRA Started by Patrick Fic
This commit is contained in:
30
src/redux/application/application.actions.js
Normal file
30
src/redux/application/application.actions.js
Normal file
@@ -0,0 +1,30 @@
|
||||
import ApplicationActionTypes from "./application.types";
|
||||
|
||||
export const setRooms = (rooms) => ({
|
||||
type: ApplicationActionTypes.SET_ROOMS,
|
||||
payload: rooms,
|
||||
});
|
||||
|
||||
export const addRoom = (room) => ({
|
||||
type: ApplicationActionTypes.ADD_ROOM,
|
||||
payload: room,
|
||||
});
|
||||
|
||||
export const addImages = ({ roomId, images }) => ({
|
||||
type: ApplicationActionTypes.ADD_IMAGES_TO_ROOM,
|
||||
payload: { roomId, images },
|
||||
});
|
||||
|
||||
export const removeRoom = (roomId) => ({
|
||||
type: ApplicationActionTypes.REMOVE_ROOM,
|
||||
payload: roomId,
|
||||
});
|
||||
|
||||
export const markNa = (roomId) => ({
|
||||
type: ApplicationActionTypes.MARK_ROOM_NA,
|
||||
payload: roomId,
|
||||
});
|
||||
export const joinRoom = (roomId) => ({
|
||||
type: ApplicationActionTypes.JOIN_ROOM,
|
||||
payload: roomId,
|
||||
});
|
||||
53
src/redux/application/application.reducer.js
Normal file
53
src/redux/application/application.reducer.js
Normal file
@@ -0,0 +1,53 @@
|
||||
import ApplicationActionTypes from "./application.types";
|
||||
import _ from "lodash";
|
||||
const INITIAL_STATE = {
|
||||
rooms: [],
|
||||
images: {
|
||||
id: [],
|
||||
},
|
||||
};
|
||||
|
||||
const applicationReducer = (state = INITIAL_STATE, action) => {
|
||||
switch (action.type) {
|
||||
case ApplicationActionTypes.SET_ROOMS:
|
||||
return {
|
||||
...state,
|
||||
rooms: _.unionBy(state.rooms, action.payload, "id"),
|
||||
};
|
||||
case ApplicationActionTypes.ADD_ROOM:
|
||||
return {
|
||||
...state,
|
||||
rooms: _.unionBy(state.rooms, [action.payload], "id"),
|
||||
};
|
||||
case ApplicationActionTypes.ADD_IMAGES_TO_ROOM:
|
||||
return {
|
||||
...state,
|
||||
images: {
|
||||
...state.images,
|
||||
[action.payload.roomId]: _.unionBy(
|
||||
state.images[action.payload.roomId] || [],
|
||||
action.payload.images,
|
||||
|
||||
"filename"
|
||||
),
|
||||
},
|
||||
};
|
||||
case ApplicationActionTypes.REMOVE_ROOM:
|
||||
return {
|
||||
...state,
|
||||
rooms: state.rooms.filter((r) => r.id !== action.payload),
|
||||
};
|
||||
|
||||
case ApplicationActionTypes.MARK_ROOM_NA:
|
||||
return {
|
||||
...state,
|
||||
rooms: state.rooms.map((room) =>
|
||||
room.id === action.payload ? { ...room, na: true } : room
|
||||
),
|
||||
};
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
|
||||
export default applicationReducer;
|
||||
40
src/redux/application/application.sagas.js
Normal file
40
src/redux/application/application.sagas.js
Normal file
@@ -0,0 +1,40 @@
|
||||
import { all, call, takeLatest } from "redux-saga/effects";
|
||||
import ApplicationActionTypes from "./application.types";
|
||||
export function* onJoinRoom() {
|
||||
yield takeLatest(ApplicationActionTypes.JOIN_ROOM, joinRoom);
|
||||
}
|
||||
export function* joinRoom({ payload: roomId }) {
|
||||
// console.log("function*joinRoom -> roomId", roomId);
|
||||
// //TH eactual function
|
||||
// const state = yield select();
|
||||
// const room = state.application.rooms.filter((r) => r.id === roomId)[0];
|
||||
// yield put(addImages({ roomId: null, images: [] }));
|
||||
// if (room) {
|
||||
// socket.emit(
|
||||
// "join",
|
||||
// {
|
||||
// roomName: room.name,
|
||||
// parentRoomName: room.parentName,
|
||||
// password: Math.round(Math.random() * 1000).toString(),
|
||||
// },
|
||||
// co.wrap(function* (payload) {
|
||||
// console.log("Checking Room", payload);
|
||||
// if (payload.room && payload.room.id) {
|
||||
// console.log("about to put");
|
||||
// yield put(
|
||||
// addImages({
|
||||
// roomId: payload.room.id,
|
||||
// images: payload.room.medias,
|
||||
// })
|
||||
// );
|
||||
// } else {
|
||||
// yield put(markNa(room.id));
|
||||
// }
|
||||
// })
|
||||
// );
|
||||
// }
|
||||
}
|
||||
|
||||
export function* applicationSagas() {
|
||||
yield all([call(onJoinRoom)]);
|
||||
}
|
||||
13
src/redux/application/application.selectors.js
Normal file
13
src/redux/application/application.selectors.js
Normal file
@@ -0,0 +1,13 @@
|
||||
import { createSelector } from "reselect";
|
||||
|
||||
const selectApplication = (state) => state.application;
|
||||
|
||||
export const selectRooms = createSelector(
|
||||
[selectApplication],
|
||||
(application) => application.rooms
|
||||
);
|
||||
|
||||
export const selectImages = createSelector(
|
||||
[selectApplication],
|
||||
(application) => application.images
|
||||
);
|
||||
9
src/redux/application/application.types.js
Normal file
9
src/redux/application/application.types.js
Normal file
@@ -0,0 +1,9 @@
|
||||
const ApplicationActionTypes = {
|
||||
SET_ROOMS: "SET_ROOMS",
|
||||
ADD_ROOM: "ADD_ROOM",
|
||||
ADD_IMAGES_TO_ROOM: "ADD_IMAGES_TO_ROOM",
|
||||
REMOVE_ROOM: "REMOVE_ROOM",
|
||||
MARK_ROOM_NA: "MARK_ROOM_NA",
|
||||
JOIN_ROOM: "JOIN_ROOM",
|
||||
};
|
||||
export default ApplicationActionTypes;
|
||||
Reference in New Issue
Block a user