-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from imkarimkarim/addFeature
add cheat (i wish they didnt asked this feature)
- Loading branch information
Showing
13 changed files
with
409 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
.cheatEditor > .MuiFormControl-root:nth-child(1), | ||
.cheatEditor > .MuiFormControl-root:nth-child(2), | ||
.cheatEditor > .MuiFormControl-root:nth-child(3), | ||
.cheatEditor > .expenseInput { | ||
width: 170px; | ||
} | ||
|
||
.cheat-wrapper .hint { | ||
margin: 5px 0; | ||
} | ||
|
||
.cheat-wrapper .hint:first-child { | ||
margin-bottom: 20px; | ||
} | ||
.cheat-wrapper .deleteCheats { | ||
margin-top: 20px; | ||
} | ||
.cheat-wrapper { | ||
display: flex; | ||
flex-direction: column; | ||
position: absolute; | ||
right: 0; | ||
margin: 170px; | ||
width: 50%; | ||
z-index: 8; | ||
background: #fff; | ||
border-radius: 5px; | ||
padding: 3%; | ||
box-shadow: 0 0 100px 500px #0000003f; | ||
} | ||
|
||
.cheatEditor { | ||
display: flex; | ||
justify-content: space-between; | ||
width: 100%; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import React, { useState, useEffect, useRef, useContext } from "react"; | ||
import DoneIcon from "@material-ui/icons/Done"; | ||
const { ipcRenderer } = require("electron"); | ||
import Button from "@material-ui/core/Button"; | ||
import TextField from "@material-ui/core/TextField"; | ||
import Input from "../Input.jsx"; | ||
import ExpenseInput from "../ExpenseInput.jsx"; | ||
import { NotifContext } from "../../Contexts/NotifContext.jsx"; | ||
import "./Cheat.css"; | ||
import { convertToIntIfIsNumber } from "../../utils.js"; | ||
|
||
// TODO: also up/down with arrow keys | ||
|
||
const Cheat = React.memo(({ productId, setCountI }) => { | ||
const [amount, setAmount] = useState(""); | ||
const [weight, setWeight] = useState(""); | ||
const [price, setPrice] = useState(""); | ||
const [edited, setEdited] = useState(false); | ||
const { pushNotif } = useContext(NotifContext); | ||
const init = useRef(true); | ||
|
||
const cheatProduct = () => { | ||
ipcRenderer.send("cheatProduct", { | ||
productId: productId, | ||
cheat: { | ||
amount: amount, | ||
weight: weight, | ||
price: price, | ||
}, | ||
}); | ||
}; | ||
|
||
const removeCheatProduct = () => { | ||
ipcRenderer.send("removeCheatProduct", productId); | ||
}; | ||
|
||
useEffect(() => { | ||
ipcRenderer.on("cheatProduct", (event, cheatStatus) => { | ||
if (cheatStatus.status !== null) { | ||
if (cheatStatus.status === true) { | ||
pushNotif("success", cheatStatus.message); | ||
setCountI(-1); | ||
} else if (cheatStatus.status === false) { | ||
pushNotif("error", cheatStatus.message); | ||
} | ||
} | ||
}); | ||
|
||
ipcRenderer.on("removeCheatProduct", (event, cheatStatus) => { | ||
if (cheatStatus.status !== null && cheatStatus.status === true) { | ||
pushNotif("success", cheatStatus.message); | ||
setCountI(-1); | ||
} | ||
}); | ||
// clean up | ||
return () => { | ||
ipcRenderer.removeAllListeners("cheatProduct"); | ||
}; | ||
}); | ||
|
||
return productId && !edited ? ( | ||
<div className="cheat-wrapper"> | ||
<span className="hint"> | ||
مقادیر دلخواه را با دقت وارد کنید | (تغییر بار {productId}) | ||
</span> | ||
<div className="cheatEditor"> | ||
<Input | ||
value={amount} | ||
label="تعداد*" | ||
fun={(e) => { | ||
setAmount(convertToIntIfIsNumber(e.target.value)); | ||
}} | ||
/> | ||
<Input | ||
value={weight} | ||
label="وزن*" | ||
fun={(e) => { | ||
setWeight(convertToIntIfIsNumber(e.target.value)); | ||
}} | ||
/> | ||
<ExpenseInput | ||
value={price} | ||
label="فی فروش*" | ||
fun={(e) => { | ||
setPrice(convertToIntIfIsNumber(e.target.value)); | ||
}} | ||
/> | ||
<Button | ||
className="newFactorAddProductInputButton" | ||
disabled={ | ||
!( | ||
amount.toString().length >= 1 && | ||
weight.toString().length >= 1 && | ||
price.toString().length >= 1 | ||
) | ||
} | ||
onClick={cheatProduct} | ||
variant="outlined" | ||
color="primary" | ||
> | ||
<DoneIcon /> | ||
</Button> | ||
</div> | ||
<Button | ||
className="deleteCheats" | ||
onClick={removeCheatProduct} | ||
variant="outlined" | ||
color="secondary" | ||
> | ||
حذف مقادیر دلخواه | ||
</Button> | ||
</div> | ||
) : ( | ||
<div></div> | ||
); | ||
}); | ||
|
||
export default Cheat; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.