Added base handled for job decode and watcher start/top
This commit is contained in:
@@ -2,14 +2,13 @@ const { ipcMain } = require("electron");
|
||||
const { StartWatcher, StopWatcher } = require("./file-watcher");
|
||||
const ipcTypes = require("../../src/ipc.types").default;
|
||||
|
||||
ipcMain.on(ipcTypes.filewatcher.start, async (event, arg) => {
|
||||
console.log(ipcTypes.filewatcher.start);
|
||||
ipcMain.on(ipcTypes.fileWatcher.toMain.start, async (event, arg) => {
|
||||
const filePaths = StartWatcher();
|
||||
event.sender.send(ipcTypes.filewatcher.startSuccess, filePaths);
|
||||
event.sender.send(ipcTypes.fileWatcher.toRenderer.startSuccess, filePaths);
|
||||
event.sender.send(ipcTypes.fileWatcher.toRenderer.filepathsList, filePaths);
|
||||
});
|
||||
|
||||
ipcMain.on(ipcTypes.filewatcher.stop, async (event, arg) => {
|
||||
console.log(ipcTypes.filewatcher.start);
|
||||
ipcMain.on(ipcTypes.fileWatcher.toMain.stop, async (event, arg) => {
|
||||
StopWatcher();
|
||||
event.sender.send(ipcTypes.filewatcher.start, { success: true });
|
||||
event.sender.send(ipcTypes.fileWatcher.toRenderer.stopSuccess);
|
||||
});
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
const chokidar = require("chokidar");
|
||||
const { file } = require("electron-settings");
|
||||
const { ipcMain } = require("electron");
|
||||
const settings = require("electron-settings");
|
||||
const { default: ipcTypes } = require("../../src/ipc.types");
|
||||
|
||||
var watcher;
|
||||
|
||||
@@ -34,6 +35,7 @@ function StartWatcher() {
|
||||
})
|
||||
.on("error", function (error) {
|
||||
console.log("Error happened", error);
|
||||
ipcMain.emit(ipcTypes.fileWatcher.toRenderer.error, error);
|
||||
})
|
||||
.on("ready", onWatcherReady)
|
||||
.on("raw", function (event, path, details) {
|
||||
@@ -44,14 +46,14 @@ function StartWatcher() {
|
||||
}
|
||||
|
||||
function onWatcherReady() {
|
||||
console.info(
|
||||
"From here can you check for real changes, the initial scan has been completed."
|
||||
);
|
||||
console.log("Ready!");
|
||||
ipcMain.emit(ipcTypes.fileWatcher.toRenderer.startSuccess);
|
||||
}
|
||||
|
||||
async function StopWatcher() {
|
||||
await watcher.close();
|
||||
console.log("closed", watcher);
|
||||
ipcMain.emit(ipcTypes.fileWatcher.toRenderer.stopSuccess);
|
||||
console.log("Watcher Stopped!", watcher);
|
||||
}
|
||||
|
||||
exports.StartWatcher = StartWatcher;
|
||||
|
||||
@@ -2,27 +2,25 @@ const { ipcMain, dialog } = require("electron");
|
||||
const { mainWindow } = require("./main");
|
||||
const settings = require("electron-settings");
|
||||
const { DecodeEstimate } = require("./decoder/decoder");
|
||||
const ipcTypes = require("../src/ipc.types");
|
||||
//Import Ipc Handlers
|
||||
require("./file-watcher/file-watcher-ipc");
|
||||
|
||||
console.log("*** Added IPC Handlers ***");
|
||||
|
||||
ipcMain.on(
|
||||
ipcTypes.default.fileWatcher.toMain.filepathsGet,
|
||||
async (event, object) => {
|
||||
const filePaths = await settings.get("filePaths");
|
||||
event.reply(
|
||||
ipcTypes.default.fileWatcher.toRenderer.filepathsList,
|
||||
filePaths
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
ipcMain.on("test", async (event, object) => {
|
||||
console.log("Received test IPC Command");
|
||||
const job = await DecodeEstimate("C:\\VPS\\EMS\\687_3_A.AD1");
|
||||
|
||||
event.reply("test-success", { status: 0, message: null, data: job });
|
||||
});
|
||||
|
||||
// ipcMain.on("test-start", async (event, arg) => {
|
||||
// console.log("Test Start Inbound.", arg);
|
||||
// const result = await dialog.showOpenDialog(mainWindow, {
|
||||
// properties: ["openDirectory"],
|
||||
// });
|
||||
// await settings.set("filePaths", [
|
||||
// ...result.filePaths,
|
||||
// ...(await settings.get("filePaths")),
|
||||
// ]);
|
||||
// console.log(await settings.get("filePaths"));
|
||||
// event.sender.send("test-success", { success: true });
|
||||
// });
|
||||
@@ -3,7 +3,7 @@ const { app, BrowserWindow } = require("electron");
|
||||
const isDev = require("electron-is-dev");
|
||||
const settings = require("electron-settings");
|
||||
|
||||
require("./ipc-handler");
|
||||
require("./ipc-main-handler");
|
||||
|
||||
// Conditionally include the dev tools installer to load React Dev Tools
|
||||
let installExtension, REACT_DEVELOPER_TOOLS;
|
||||
|
||||
@@ -7,6 +7,7 @@ contextBridge.exposeInMainWorld("ipcRenderer", {
|
||||
// whitelist channels
|
||||
// let validChannels = ["toMain"];
|
||||
// if (validChannels.includes(channel)) {
|
||||
console.log("ipcRenderer Send", channel);
|
||||
ipcRenderer.send(channel, data);
|
||||
//}
|
||||
},
|
||||
|
||||
@@ -7,9 +7,9 @@ import { createStructuredSelector } from "reselect";
|
||||
import RoutesPage from "../components/pages/routes/routes.page";
|
||||
import SignInPage from "../components/pages/sign-in/sign-in.page";
|
||||
import client from "../graphql/GraphQLClient";
|
||||
import "../ipc/ipc-renderer-handler";
|
||||
import { checkUserSession } from "../redux/user/user.actions";
|
||||
import { selectCurrentUser } from "../redux/user/user.selectors";
|
||||
import "../ipc/ipc-init";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
currentUser: selectCurrentUser,
|
||||
|
||||
23
src/components/atoms/watcher-status/watcher-status.atom.jsx
Normal file
23
src/components/atoms/watcher-status/watcher-status.atom.jsx
Normal file
@@ -0,0 +1,23 @@
|
||||
import { Alert } from "antd";
|
||||
import React from "react";
|
||||
import { connect } from "react-redux";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import {
|
||||
selectWatcherError,
|
||||
selectWatcherStatus,
|
||||
} from "../../../redux/application/application.selectors";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
watcherStatus: selectWatcherStatus,
|
||||
watcherError: selectWatcherError,
|
||||
});
|
||||
|
||||
export function WatcherStatusAtom({ watcherStatus, watcherError }) {
|
||||
return (
|
||||
<div>
|
||||
{watcherStatus}
|
||||
{watcherError && <Alert message={watcherError} />}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
export default connect(mapStateToProps, null)(WatcherStatusAtom);
|
||||
@@ -0,0 +1,6 @@
|
||||
import { List } from "antd";
|
||||
import React from "react";
|
||||
|
||||
export default function FilePathMolecule(item) {
|
||||
return <List.Item title={item}>{item}</List.Item>;
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import { UserOutlined } from "@ant-design/icons";
|
||||
import { Menu } from "antd";
|
||||
import React from "react";
|
||||
import { connect } from "react-redux";
|
||||
@@ -9,7 +10,11 @@ const mapDispatchToProps = (dispatch) => ({
|
||||
|
||||
export function SiderSignOut({ signOutStart, ...restProps }) {
|
||||
return (
|
||||
<Menu.Item {...restProps} onClick={() => signOutStart()}>
|
||||
<Menu.Item
|
||||
icon={<UserOutlined />}
|
||||
{...restProps}
|
||||
onClick={() => signOutStart()}
|
||||
>
|
||||
Sign Out
|
||||
</Menu.Item>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { Button } from "antd";
|
||||
import React from "react";
|
||||
import ipcTypes from "../../../ipc.types";
|
||||
const { ipcRenderer } = window;
|
||||
|
||||
export default function WatcherStartMolecule() {
|
||||
const handleClick = () => {
|
||||
ipcRenderer.send(ipcTypes.default.fileWatcher.toMain.start);
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Button onClick={handleClick}>Start Watcher</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { Button } from "antd";
|
||||
import React from "react";
|
||||
import ipcTypes from "../../../ipc.types";
|
||||
const { ipcRenderer } = window;
|
||||
|
||||
export default function WatcherStopMolecule() {
|
||||
const handleClick = () => {
|
||||
ipcRenderer.send(ipcTypes.default.fileWatcher.toMain.stop);
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Button onClick={handleClick}>Stop Watcher</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import { List } from "antd";
|
||||
import React, { useEffect } from "react";
|
||||
import { connect } from "react-redux";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import ipcTypes from "../../../ipc.types";
|
||||
import { selectWatchedPaths } from "../../../redux/application/application.selectors";
|
||||
import FilepathItemMolecule from "../../molecules/filepath-item/filepath-item.molecule";
|
||||
const { ipcRenderer } = window;
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
watchedPaths: selectWatchedPaths,
|
||||
});
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
//setUserLanguage: language => dispatch(setUserLanguage(language))
|
||||
});
|
||||
|
||||
export function FilePathsList({ watchedPaths }) {
|
||||
//On Rdner, send request to get file paths to main.
|
||||
useEffect(() => {
|
||||
ipcRenderer.send(ipcTypes.default.fileWatcher.toMain.filepathsGet);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div>
|
||||
File Paths
|
||||
<List dataSource={watchedPaths} renderItem={FilepathItemMolecule} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(FilePathsList);
|
||||
@@ -1,36 +1,18 @@
|
||||
import {
|
||||
DesktopOutlined,
|
||||
FileOutlined,
|
||||
PieChartOutlined,
|
||||
TeamOutlined,
|
||||
UserOutlined,
|
||||
} from "@ant-design/icons";
|
||||
import { PieChartOutlined, SettingFilled } from "@ant-design/icons";
|
||||
import { Menu } from "antd";
|
||||
import React from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import SiderSignOut from "../../molecules/sider-sign-out/sider-sign-out.molecule";
|
||||
|
||||
const { SubMenu } = Menu;
|
||||
|
||||
export default function SiderMenuOrganism() {
|
||||
return (
|
||||
<Menu defaultSelectedKeys={["1"]} mode="inline">
|
||||
<Menu.Item key="1" icon={<PieChartOutlined />}>
|
||||
<Link to="/">Jobs</Link>
|
||||
</Menu.Item>
|
||||
<Menu.Item key="2" icon={<DesktopOutlined />}>
|
||||
<Link to="/nope">Jobs Not Working</Link>
|
||||
<Menu.Item key="2" icon={<SettingFilled />}>
|
||||
<Link to="/settings">Settings</Link>
|
||||
</Menu.Item>
|
||||
<SubMenu key="sub1" icon={<UserOutlined />} title="User">
|
||||
<Menu.Item key="3">Tom</Menu.Item>
|
||||
<Menu.Item key="4">Bill</Menu.Item>
|
||||
<Menu.Item key="5">Alex</Menu.Item>
|
||||
</SubMenu>
|
||||
<SubMenu key="sub2" icon={<TeamOutlined />} title="Team">
|
||||
<Menu.Item key="6">Team 1</Menu.Item>
|
||||
<Menu.Item key="8">Team 2</Menu.Item>
|
||||
</SubMenu>
|
||||
<Menu.Item key="9" icon={<FileOutlined />} />
|
||||
<SiderSignOut />
|
||||
</Menu>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import React from "react";
|
||||
import WatcherStatusAtom from "../../atoms/watcher-status/watcher-status.atom";
|
||||
import WatcherStartMolecule from "../../molecules/watcher-start/watcher-start.molecule";
|
||||
import WatcherStopMolecule from "../../molecules/watcher-stop/watcher-stop.molecule";
|
||||
|
||||
export default function WatcherManagerOrganism() {
|
||||
return (
|
||||
<div>
|
||||
<WatcherStatusAtom />
|
||||
<WatcherStartMolecule />
|
||||
<WatcherStopMolecule />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,47 +1,31 @@
|
||||
import { Button } from "antd";
|
||||
import React, { useEffect } from "react";
|
||||
import React from "react";
|
||||
import { connect } from "react-redux";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import ipcTypes from "../../../ipc.types";
|
||||
|
||||
const { ipcRenderer } = window;
|
||||
//const { ipcRenderer } = window;
|
||||
//const settings = window.require("electron-settings");
|
||||
|
||||
const mapStateToProps = createStructuredSelector({});
|
||||
const mapDispatchToProps = (dispatch) => ({});
|
||||
|
||||
export function JobsPage() {
|
||||
useEffect(() => {
|
||||
ipcRenderer.on("test-success", (event, obj) => {
|
||||
console.log("Test Success", obj);
|
||||
});
|
||||
// useEffect(() => {
|
||||
// ipcRenderer.on("test-success", (event, obj) => {
|
||||
// console.log("Test Success", obj);
|
||||
// });
|
||||
|
||||
// Cleanup the listener events so that memory leaks are avoided.
|
||||
return function cleanup() {
|
||||
ipcRenderer.removeAllListeners(
|
||||
"test-success",
|
||||
ipcTypes.default.filewatcher.startSuccess
|
||||
);
|
||||
};
|
||||
}, []);
|
||||
// // Cleanup the listener events so that memory leaks are avoided.
|
||||
// return function cleanup() {
|
||||
// ipcRenderer.removeAllListeners(
|
||||
// "test-success",
|
||||
// ipcTypes.default.filewatcher.startSuccess
|
||||
// );
|
||||
// };
|
||||
// }, []);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div>Welcome to your new react app. asdas sd</div>
|
||||
<Button
|
||||
onClick={() => {
|
||||
ipcRenderer.send("test", { test: true });
|
||||
}}
|
||||
>
|
||||
TEST
|
||||
</Button>
|
||||
<Button
|
||||
onClick={() => {
|
||||
ipcRenderer.send(ipcTypes.default.filewatcher.start);
|
||||
}}
|
||||
>
|
||||
Start Watcher
|
||||
</Button>
|
||||
<div>Welcome to your new react app. </div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import { Route, Switch } from "react-router-dom";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import SiderMenuOrganism from "../../organisms/sider-menu/sider-menu.organism";
|
||||
import Jobs from "../jobs/jobs.page";
|
||||
import SettingsPage from "../settings/settings.page";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({});
|
||||
const mapDispatchToProps = (dispatch) => ({});
|
||||
@@ -19,6 +20,7 @@ export function RoutesPage() {
|
||||
<Layout.Content style={{ margin: "1rem" }}>
|
||||
<Switch>
|
||||
<Route exact path="/" component={Jobs} />
|
||||
<Route exact path="/settings" component={SettingsPage} />
|
||||
</Switch>
|
||||
</Layout.Content>
|
||||
</Layout>
|
||||
|
||||
19
src/components/pages/settings/settings.page.jsx
Normal file
19
src/components/pages/settings/settings.page.jsx
Normal file
@@ -0,0 +1,19 @@
|
||||
import React from "react";
|
||||
import FilePathsListOrganism from "../../organisms/filepaths-list/filepaths-list.organism";
|
||||
import WatcherManagerOrganism from "../../organisms/watcher-manager/watcher-manager.organism";
|
||||
export default function SettingsPage() {
|
||||
return (
|
||||
<div>
|
||||
<FilePathsListOrganism />
|
||||
<WatcherManagerOrganism />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// <Button
|
||||
// onClick={() => {
|
||||
// ipcRenderer.send(ipcTypes.default.filewatcher.start);
|
||||
// }}
|
||||
// >
|
||||
// Start Watcher
|
||||
// </Button>
|
||||
@@ -2,10 +2,25 @@ exports.default = {
|
||||
test: {
|
||||
start: "test-start",
|
||||
},
|
||||
filewatcher: {
|
||||
start: "filewatcher__start",
|
||||
startSuccess: "filewatcher__start-success",
|
||||
startFailure: "filewatcher__start-failure",
|
||||
stop: "filewatcher__stop",
|
||||
fileWatcher: {
|
||||
toMain: {
|
||||
filepathsGet: "filewatcher__filepathsget",
|
||||
start: "filewatcher__start",
|
||||
stop: "filewatcher__stop",
|
||||
},
|
||||
toRenderer: {
|
||||
filepathsList: "filewatcher__filepathslist",
|
||||
startSuccess: "filewatcher__start-success",
|
||||
startFailure: "filewatcher__start-failure",
|
||||
stopSuccess: "filewatcher__stop-success",
|
||||
error: "filewatcher__error",
|
||||
},
|
||||
},
|
||||
estimate: {
|
||||
toRenderer: {
|
||||
estimateDecodeStart: "estimatedecode__start",
|
||||
estimateDecodeSuccess: "estimatedecode__success",
|
||||
estimateDecodeFailure: "estimatedecode__failure",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
import ipcTypes from "../ipc.types";
|
||||
// import { store } from "../redux/store";
|
||||
// import { signOutStart } from "../redux/user/user.actions";
|
||||
const { ipcRenderer } = window;
|
||||
|
||||
console.log("----Initializing IPC Listeners in React App.");
|
||||
|
||||
ipcRenderer.on(ipcTypes.default.filewatcher.startSuccess, (event, ...obj) => {
|
||||
console.log(ipcTypes.default.filewatcher.startSuccess, event, obj);
|
||||
|
||||
// store.dispatch(signOutStart());
|
||||
});
|
||||
37
src/ipc/ipc-renderer-handler.js
Normal file
37
src/ipc/ipc-renderer-handler.js
Normal file
@@ -0,0 +1,37 @@
|
||||
import ipcTypes from "../ipc.types";
|
||||
import {
|
||||
setWatchedPaths,
|
||||
setWatcherStatus,
|
||||
} from "../redux/application/application.actions";
|
||||
import { store } from "../redux/store";
|
||||
const { ipcRenderer } = window;
|
||||
|
||||
console.log("----Initializing IPC Listeners in React App.");
|
||||
|
||||
ipcRenderer.on(
|
||||
ipcTypes.default.fileWatcher.toRenderer.filepathsList,
|
||||
(event, ...obj) => {
|
||||
store.dispatch(setWatchedPaths(obj));
|
||||
}
|
||||
);
|
||||
|
||||
//Filewatcher Section
|
||||
ipcRenderer.on(
|
||||
ipcTypes.default.fileWatcher.toRenderer.startSuccess,
|
||||
(event, ...obj) => {
|
||||
store.dispatch(setWatcherStatus("READY!"));
|
||||
}
|
||||
);
|
||||
ipcRenderer.on(
|
||||
ipcTypes.default.fileWatcher.toRenderer.stopSuccess,
|
||||
(event, ...obj) => {
|
||||
store.dispatch(setWatcherStatus("STOPPED"));
|
||||
}
|
||||
);
|
||||
|
||||
ipcRenderer.on(
|
||||
ipcTypes.default.fileWatcher.toRenderer.error,
|
||||
(event, ...obj) => {
|
||||
store.dispatch(setWatcherStatus(obj));
|
||||
}
|
||||
);
|
||||
@@ -1,30 +1,25 @@
|
||||
import ApplicationActionTypes from "./application.types";
|
||||
|
||||
export const setRooms = (rooms) => ({
|
||||
type: ApplicationActionTypes.SET_ROOMS,
|
||||
payload: rooms,
|
||||
export const setWatchedPaths = (watchedPaths) => ({
|
||||
type: ApplicationActionTypes.SET_WATCHED_PATHS,
|
||||
payload: watchedPaths,
|
||||
});
|
||||
|
||||
export const addRoom = (room) => ({
|
||||
type: ApplicationActionTypes.ADD_ROOM,
|
||||
payload: room,
|
||||
export const addWatchedPath = (path) => ({
|
||||
type: ApplicationActionTypes.ADD_WATCHED_PATH,
|
||||
payload: path,
|
||||
});
|
||||
|
||||
export const addImages = ({ roomId, images }) => ({
|
||||
type: ApplicationActionTypes.ADD_IMAGES_TO_ROOM,
|
||||
payload: { roomId, images },
|
||||
export const removeWatchedPath = (path) => ({
|
||||
type: ApplicationActionTypes.REMOVE_WATCHED_PATH,
|
||||
payload: path,
|
||||
});
|
||||
|
||||
export const removeRoom = (roomId) => ({
|
||||
type: ApplicationActionTypes.REMOVE_ROOM,
|
||||
payload: roomId,
|
||||
export const setWatcherStatus = (status) => ({
|
||||
type: ApplicationActionTypes.SET_WATCHER_STATUS,
|
||||
payload: status,
|
||||
});
|
||||
|
||||
export const markNa = (roomId) => ({
|
||||
type: ApplicationActionTypes.MARK_ROOM_NA,
|
||||
payload: roomId,
|
||||
});
|
||||
export const joinRoom = (roomId) => ({
|
||||
type: ApplicationActionTypes.JOIN_ROOM,
|
||||
payload: roomId,
|
||||
export const setWatcherError = (error) => ({
|
||||
type: ApplicationActionTypes.SET_WATCHER_ERROR,
|
||||
payload: error,
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1,40 +1,13 @@
|
||||
import { all, call, takeLatest } from "redux-saga/effects";
|
||||
//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* onJoinRoom() {
|
||||
// yield takeLatest(ApplicationActionTypes.JOIN_ROOM, joinRoom);
|
||||
// }
|
||||
// export function* joinRoom({ payload: roomId }) {
|
||||
// // console.log("function*joinRoom -> roomId", roomId);
|
||||
// }
|
||||
|
||||
export function* applicationSagas() {
|
||||
yield all([call(onJoinRoom)]);
|
||||
//yield all([call(onJoinRoom)]);
|
||||
}
|
||||
|
||||
@@ -2,12 +2,17 @@ import { createSelector } from "reselect";
|
||||
|
||||
const selectApplication = (state) => state.application;
|
||||
|
||||
export const selectRooms = createSelector(
|
||||
export const selectWatcherStatus = createSelector(
|
||||
[selectApplication],
|
||||
(application) => application.rooms
|
||||
(application) => application.watcherStatus
|
||||
);
|
||||
|
||||
export const selectImages = createSelector(
|
||||
export const selectWatchedPaths = createSelector(
|
||||
[selectApplication],
|
||||
(application) => application.images
|
||||
(application) => application.watchedPaths
|
||||
);
|
||||
|
||||
export const selectWatcherError = createSelector(
|
||||
[selectApplication],
|
||||
(application) => application.watcherError
|
||||
);
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
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",
|
||||
SET_WATCHED_PATHS: "SET_WATCHED_PATHS",
|
||||
ADD_WATCHED_PATH: "ADD_WATCHED_PATH",
|
||||
REMOVE_WATCHED_PATH: "REMOVE_WATCHED_PATH",
|
||||
SET_WATCHER_STATUS: "SET_WATCHER_STATUS",
|
||||
SET_WATCHER_ERROR: "SET_WATCHER_ERROR",
|
||||
};
|
||||
export default ApplicationActionTypes;
|
||||
|
||||
Reference in New Issue
Block a user