From 6cb607ed7a4563abc6e002328a41c3625c4a12f9 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Wed, 5 Jul 2023 20:40:01 -0700 Subject: [PATCH] Handle numbers and value=0 better --- components/common/InputTableField/index.tsx | 10 +++-- components/party/EditPartyModal/index.tsx | 48 +++++++++++++-------- 2 files changed, 37 insertions(+), 21 deletions(-) diff --git a/components/common/InputTableField/index.tsx b/components/common/InputTableField/index.tsx index 8a53c4e6..2ec2a44c 100644 --- a/components/common/InputTableField/index.tsx +++ b/components/common/InputTableField/index.tsx @@ -14,7 +14,7 @@ interface Props imageAlt?: string imageClass?: string imageSrc?: string[] - onValueChange: (value?: string) => void + onValueChange: (value?: string | number | readonly string[]) => void } const InputTableField = ({ @@ -25,10 +25,12 @@ const InputTableField = ({ imageSrc, ...props }: Props) => { - const [inputValue, setInputValue] = useState('') + const [inputValue, setInputValue] = useState< + string | number | readonly string[] + >() useEffect(() => { - if (props.value) setInputValue(`${props.value}`) + if (props.value !== undefined) setInputValue(props.value) }, [props.value]) useEffect(() => { @@ -54,7 +56,7 @@ const InputTableField = ({ ) { @@ -298,7 +298,6 @@ const EditPartyModal = ({ function hasBeenModified() { const nameChanged = name !== party.name && !(name === '' && party.name === undefined) - const descriptionChanged = description !== party.description && !(description === '' && party.description === undefined) @@ -313,6 +312,21 @@ const EditPartyModal = ({ const buttonCountChanged = buttonCount !== party.buttonCount const chainCountChanged = chainCount !== party.chainCount + // Debugging for if you need to check if a value is being changed + // console.log(` + // nameChanged: ${nameChanged}\n + // descriptionChanged: ${descriptionChanged}\n + // raidChanged: ${raidChanged}\n + // chargeAttackChanged: ${chargeAttackChanged}\n + // fullAutoChanged: ${fullAutoChanged}\n + // autoGuardChanged: ${autoGuardChanged}\n + // autoSummonChanged: ${autoSummonChanged}\n + // clearTimeChanged: ${clearTimeChanged}\n + // turnCountChanged: ${turnCountChanged}\n + // buttonCountChanged: ${buttonCountChanged}\n + // chainCountChanged: ${chainCountChanged}\n + // `) + return ( nameChanged || descriptionChanged || @@ -339,9 +353,9 @@ const EditPartyModal = ({ setFullAuto(party.fullAuto) setChargeAttack(party.chargeAttack) setClearTime(party.clearTime) - if (party.turnCount) setTurnCount(party.turnCount) - if (party.buttonCount) setButtonCount(party.buttonCount) - if (party.chainCount) setChainCount(party.chainCount) + if (party.turnCount !== undefined) setTurnCount(party.turnCount) + if (party.buttonCount !== undefined) setButtonCount(party.buttonCount) + if (party.chainCount !== undefined) setChainCount(party.chainCount) } async function updateDetails(event: React.MouseEvent) {