From aa6b86e6e62d49944cd4c631d95dc80026c0df20 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Wed, 23 Feb 2022 05:13:31 -0500 Subject: [PATCH] retain cheer name / prefix --- .../tts_configs/TtsConfigsEditRulePage.tsx | 21 +++++++++++++++---- .../BitsCheermoteNameExactMatchForm.tsx | 8 +++++-- .../BitsCheermotePrefixSpendThresholdForm.tsx | 21 +++++++------------ 3 files changed, 30 insertions(+), 20 deletions(-) diff --git a/packages/storyteller/src/pages/tts_configs/TtsConfigsEditRulePage.tsx b/packages/storyteller/src/pages/tts_configs/TtsConfigsEditRulePage.tsx index 4c5a3cd8d9..48566b9b0a 100644 --- a/packages/storyteller/src/pages/tts_configs/TtsConfigsEditRulePage.tsx +++ b/packages/storyteller/src/pages/tts_configs/TtsConfigsEditRulePage.tsx @@ -36,9 +36,12 @@ function TtsConfigsEditRulePage(props: Props) { // The rule types differ per category and the user can change them const [bitsRuleType, setBitsRuleType] = useState(BitsRuleType.BitsCheermoteNameExactMatch); - const [channelPointsRuleType, setChannelPointsRuleType] = useState(ChannelPointsRuleType.ChannelPointsRewardNameExactMatch); + //const [channelPointsRuleType, setChannelPointsRuleType] = useState(ChannelPointsRuleType.ChannelPointsRewardNameExactMatch); - // Field values + // Field values (editing) + const [cheerNameOrPrefix, setCheerNameOrPrefix] = useState(''); + + // Field values (final) const [eventMatchPredicate, setEventMatchPredicate] = useState(undefined); const [eventResponse, setEventResponse] = useState(undefined); const [ruleIsDisabled, setRuleIsDisabled] = useState(false); @@ -89,6 +92,10 @@ function TtsConfigsEditRulePage(props: Props) { return true; } + const updateCheerNameOrPrefix = (nameOrPrefix: string) => { + setCheerNameOrPrefix(nameOrPrefix); + } + const handleFormSubmit = async (ev: React.FormEvent) : Promise => { ev.preventDefault(); @@ -124,10 +131,16 @@ function TtsConfigsEditRulePage(props: Props) { if (twitchEventCategory === TwitchEventCategory.Bits) { switch (bitsRuleType) { case BitsRuleType.BitsCheermoteNameExactMatch: - ruleTypeForm = ; + ruleTypeForm = ; break; case BitsRuleType.BitsCheermotePrefixSpendThreshold: - ruleTypeForm = + ruleTypeForm = break; case BitsRuleType.BitsSpendThreshold: ruleTypeForm = ; diff --git a/packages/storyteller/src/pages/tts_configs/components/BitsCheermoteNameExactMatchForm.tsx b/packages/storyteller/src/pages/tts_configs/components/BitsCheermoteNameExactMatchForm.tsx index 60df279ba5..032f2e5307 100644 --- a/packages/storyteller/src/pages/tts_configs/components/BitsCheermoteNameExactMatchForm.tsx +++ b/packages/storyteller/src/pages/tts_configs/components/BitsCheermoteNameExactMatchForm.tsx @@ -4,12 +4,14 @@ import { faGem } from '@fortawesome/free-solid-svg-icons'; import { CHEER_BIT_LEVELS, CHEER_PREFIXES } from '../../../twitch/Cheers'; interface BitsCheermoteNameExactMatchProps { + cheerName: string, + updateCheerNameOrPrefix: (cheerNameOrPrefix: string) => void, }; function BitsCheermoteNameExactMatchForm(props: BitsCheermoteNameExactMatchProps) { - const [cheerPrefix, setCheerPrefix] = useState(); + const [cheerPrefix, setCheerPrefix] = useState(props.cheerName); const [bitsValue, setBitsValue] = useState(1); - const [manualCheerValue, setManualCheerValue] = useState(""); + const [manualCheerValue, setManualCheerValue] = useState(props.cheerName); const updateCheerPrefix = (ev: React.FormEvent) : boolean => { const value = (ev.target as HTMLSelectElement).value; @@ -29,6 +31,7 @@ function BitsCheermoteNameExactMatchForm(props: BitsCheermoteNameExactMatchProps const updateTextCheerValue = (ev: React.FormEvent) : boolean => { const value = (ev.target as HTMLInputElement).value; setManualCheerValue(value); + props.updateCheerNameOrPrefix(value); return true; } @@ -39,6 +42,7 @@ function BitsCheermoteNameExactMatchForm(props: BitsCheermoteNameExactMatchProps } const cheerValue = `${prefix}${bits}`; setManualCheerValue(cheerValue); + props.updateCheerNameOrPrefix(cheerValue); } return ( diff --git a/packages/storyteller/src/pages/tts_configs/components/BitsCheermotePrefixSpendThresholdForm.tsx b/packages/storyteller/src/pages/tts_configs/components/BitsCheermotePrefixSpendThresholdForm.tsx index 29fdb01c5c..1fc7fd00e4 100644 --- a/packages/storyteller/src/pages/tts_configs/components/BitsCheermotePrefixSpendThresholdForm.tsx +++ b/packages/storyteller/src/pages/tts_configs/components/BitsCheermotePrefixSpendThresholdForm.tsx @@ -4,11 +4,13 @@ import { faGem } from '@fortawesome/free-solid-svg-icons'; import { CHEER_BIT_LEVELS, CHEER_PREFIXES } from '../../../twitch/Cheers'; interface BitsCheermotePrefixSpendThresholdProps { + cheerPrefix: string, + updateCheerNameOrPrefix: (cheerNameOrPrefix: string) => void, }; function BitsCheermotePrefixSpendThresholdForm(props: BitsCheermotePrefixSpendThresholdProps) { - const [cheerPrefix, setCheerPrefix] = useState(); - const [customCheerPrefix, setCustomCheerPrefix] = useState(""); + const [cheerPrefix, setCheerPrefix] = useState(props.cheerPrefix); + const [customCheerPrefix, setCustomCheerPrefix] = useState(props.cheerPrefix); const [bitsValue, setBitsValue] = useState(1); const [customBitsValue, setCustomBitsValue] = useState(1); @@ -20,27 +22,21 @@ function BitsCheermotePrefixSpendThresholdForm(props: BitsCheermotePrefixSpendTh return true; } - const updateBitsValue = (ev: React.FormEvent) : boolean => { - const value = (ev.target as HTMLSelectElement).value; - const numericValue = parseInt(value); - setBitsValue(numericValue); - recalcuateFieldValue(cheerPrefix, numericValue); - return true; - } - const updateTextCheerValue = (ev: React.FormEvent) : boolean => { const value = (ev.target as HTMLInputElement).value; setCustomCheerPrefix(value); + props.updateCheerNameOrPrefix(value); return true; } // When the dropdowns are used, replace any manual text entry. - const recalcuateFieldValue = (prefix: string|undefined, bits: number) => { + const recalcuateFieldValue = (prefix: string, bits: number) => { if (prefix === undefined) { return; } const cheerValue = `${prefix}`; setCustomCheerPrefix(cheerValue); + props.updateCheerNameOrPrefix(cheerValue); } const handleBitSelect = (ev: React.FormEvent) : boolean => { @@ -57,7 +53,6 @@ function BitsCheermotePrefixSpendThresholdForm(props: BitsCheermotePrefixSpendTh return true; } - return ( <>
@@ -115,8 +110,6 @@ function BitsCheermotePrefixSpendThresholdForm(props: BitsCheermotePrefixSpendTh
- -

Bits spent