Implemented job upload

This commit is contained in:
Patrick Fic
2020-10-14 17:08:47 -07:00
parent e7614942e5
commit 0a3c87a6f2
25 changed files with 347 additions and 131 deletions

View File

@@ -0,0 +1,11 @@
import { Button } from "antd";
import React from "react";
import ipcTypes from "../../../ipc.types";
const { ipcRenderer } = window;
export default function FilepathAddMolecule() {
const handleClick = () => {
ipcRenderer.send(ipcTypes.default.fileWatcher.toMain.addPath);
};
return <Button onClick={handleClick}>Add Path</Button>;
}

View File

@@ -1,6 +1,6 @@
import { List } from "antd";
import React from "react";
export default function FilePathMolecule(item) {
return <List.Item title={item}>{item}</List.Item>;
export default function FilePathMolecule(item, index) {
return <List.Item key={index}>{item}</List.Item>;
}

View File

@@ -4,6 +4,7 @@ import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import ipcTypes from "../../../ipc.types";
import { selectWatchedPaths } from "../../../redux/application/application.selectors";
import FilepathAddMolecule from "../../molecules/filepath-add/filepath-add.molecule";
import FilepathItemMolecule from "../../molecules/filepath-item/filepath-item.molecule";
const { ipcRenderer } = window;
@@ -24,6 +25,7 @@ export function FilePathsList({ watchedPaths }) {
<div>
File Paths
<List dataSource={watchedPaths} renderItem={FilepathItemMolecule} />
<FilepathAddMolecule />
</div>
);
}

View File

@@ -1,8 +1,9 @@
import { Button } from "antd";
import React from "react";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
//const { ipcRenderer } = window;
const { ipcRenderer } = window;
//const settings = window.require("electron-settings");
const mapStateToProps = createStructuredSelector({});
@@ -26,6 +27,7 @@ export function JobsPage() {
return (
<div>
<div>Welcome to your new react app. </div>
<Button onClick={() => ipcRenderer.send("test")}>Send Test IPC</Button>
</div>
);
}

View File

@@ -12,18 +12,12 @@ const mapDispatchToProps = (dispatch) => ({});
export function App() {
useEffect(() => {
ipcRenderer.on("test-success", (event, obj) => {
console.log("Test Success", obj);
});
ipcRenderer.on(ipcTypes.default.filewatcher.startSuccess, (event, obj) => {
console.log(ipcTypes.default.filewatcher.startSuccess, obj);
ipcRenderer.on("not a real channel", (event, obj) => {
console.log("not a real channel", obj);
});
// Cleanup the listener events so that memory leaks are avoided.
return function cleanup() {
ipcRenderer.removeAllListeners(
"test-success",
ipcTypes.default.filewatcher.startSuccess
);
ipcRenderer.removeAllListeners("not a real channel");
};
}, []);

View File

@@ -0,0 +1,26 @@
import gql from "graphql-tag";
export const INSERT_NEW_JOB = gql`
mutation INSERT_JOB($job: [jobs_insert_input!]!) {
insert_jobs(objects: $job) {
returning {
id
}
}
}
`;
// on_conflict: {
// constraint: jobs_clm_no_bodyshopid_key
// update_columns: [
// ins_co_nm
// clm_no
// clm_total
// ownr_ln
// ownr_fn
// v_vin
// v_make_desc
// v_model_desc
// v_type
// ]
// }

View File

@@ -1,4 +1,5 @@
exports.default = {
webcontent: "webcontent-send",
test: {
start: "test-start",
},
@@ -7,6 +8,7 @@ exports.default = {
filepathsGet: "filewatcher__filepathsget",
start: "filewatcher__start",
stop: "filewatcher__stop",
addPath: "filewatcher__addPath",
},
toRenderer: {
filepathsList: "filewatcher__filepathslist",

View File

@@ -0,0 +1,16 @@
import client from "../graphql/GraphQLClient";
import { INSERT_NEW_JOB } from "../graphql/jobs.queries";
import { store } from "../redux/store";
export async function UpsertEstimate(job) {
const shopId = store.getState().user.bodyshop.id;
console.log("UpsertEstimate -> shopId", shopId);
const result = await client.mutate({
mutation: INSERT_NEW_JOB,
variables: {
job: { ...job, bodyshopid: shopId },
},
});
console.log("UpsertEstimate -> result", result);
}

View File

@@ -4,9 +4,15 @@ import {
setWatcherStatus,
} from "../redux/application/application.actions";
import { store } from "../redux/store";
import { message } from "antd";
import { UpsertEstimate } from "./ipc-estimate-utils";
const { ipcRenderer } = window;
console.log("----Initializing IPC Listeners in React App.");
ipcRenderer.on("test-toRenderer", (event, obj) => {
console.log("test-toRenderer", obj);
});
ipcRenderer.on(
ipcTypes.default.fileWatcher.toRenderer.filepathsList,
@@ -15,10 +21,12 @@ ipcRenderer.on(
}
);
//Filewatcher Section
//Filewatcher Status Section
ipcRenderer.on(
ipcTypes.default.fileWatcher.toRenderer.startSuccess,
(event, ...obj) => {
console.log("Watcher ready.");
message.success("Watcher started!");
store.dispatch(setWatcherStatus("READY!"));
}
);
@@ -28,10 +36,25 @@ ipcRenderer.on(
store.dispatch(setWatcherStatus("STOPPED"));
}
);
ipcRenderer.on(
ipcTypes.default.fileWatcher.toRenderer.error,
(event, ...obj) => {
store.dispatch(setWatcherStatus(obj));
}
);
//Estimate Section
ipcRenderer.on(
ipcTypes.default.estimate.toRenderer.estimateDecodeStart,
(event, ...obj) => {
console.log("Decoding started!");
}
);
ipcRenderer.on(
ipcTypes.default.estimate.toRenderer.estimateDecodeSuccess,
async (event, ...obj) => {
console.log("Decoding success!", obj[0]);
await UpsertEstimate(obj[0]);
}
);

View File

@@ -1,5 +1,5 @@
//import { all, call, takeLatest } from "redux-saga/effects";
import ApplicationActionTypes from "./application.types";
//import ApplicationActionTypes from "./application.types";
// export function* onJoinRoom() {
// yield takeLatest(ApplicationActionTypes.JOIN_ROOM, joinRoom);

View File

@@ -7,7 +7,7 @@ import userReducer from "./user/user.reducer";
const persistConfig = {
key: "root",
storage,
// blacklist: ["application"],
blacklist: ["application"],
};
const rootReducer = combineReducers({