From 22703ffa1fb9cbd8fe21bce81adb43ef5b61ba4d Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Thu, 24 Feb 2022 05:17:25 -0500 Subject: [PATCH] this form sucks --- .../EventMatchPredicateBuilderComponent.tsx | 6 ++++-- .../subforms/BitsCheermoteNameExactMatchForm.tsx | 8 +++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/storyteller/src/pages/tts_configs/event_match_predicate_builder/EventMatchPredicateBuilderComponent.tsx b/packages/storyteller/src/pages/tts_configs/event_match_predicate_builder/EventMatchPredicateBuilderComponent.tsx index e9c6798d9a..027286cac8 100644 --- a/packages/storyteller/src/pages/tts_configs/event_match_predicate_builder/EventMatchPredicateBuilderComponent.tsx +++ b/packages/storyteller/src/pages/tts_configs/event_match_predicate_builder/EventMatchPredicateBuilderComponent.tsx @@ -9,6 +9,9 @@ import { BitsSpendThresholdForm } from './subforms/BitsSpendThresholdForm'; import { ChannelPointsRewardNameExactMatchForm } from './subforms/ChannelPointsRewardNameExactMatchForm'; import { ChannelPointsRuleType } from './types/ChannelPointsRuleType'; +// TODO: Don't duplicate +const CHEER_REGEX = /^([A-Za-z]+)(\d+)?$/; + interface EventMatchPredicateBuilderComponentProps { // CANNOT BE CHANGED AFTER CREATION twitchEventCategory: TwitchEventCategory, @@ -207,14 +210,13 @@ function EventMatchPredicateBuilderComponent(props: EventMatchPredicateBuilderCo switch (bitsRuleType) { case BitsRuleType.BitsCheermoteNameExactMatch: matchingRulesForm = ; break; case BitsRuleType.BitsCheermotePrefixSpendThreshold: matchingRulesForm = void, + updateMinimumBitsSpent: (minimumSpent: number) => void, // NB: Technically not a field, but we can parse it out! }; function BitsCheermoteNameExactMatchForm(props: BitsCheermoteNameExactMatchProps) { @@ -65,7 +66,11 @@ function BitsCheermoteNameExactMatchForm(props: BitsCheermoteNameExactMatchProps setCheerPrefix(matches[1]); // First match group if (matches.length == 3 && matches[2] !== undefined) { // NB: Second match group can be 'undefined' if no number is present. (Zero-width matching?) - setBitsValue(parseInt(matches[2])); // Second match group + const maybeBits = parseInt(matches[2]); + if (!isNaN(maybeBits)) { + setBitsValue(maybeBits); // Second match group + props.updateMinimumBitsSpent(maybeBits); // NB: Technically not in this form, but helps when switching + } } } @@ -82,6 +87,7 @@ function BitsCheermoteNameExactMatchForm(props: BitsCheermoteNameExactMatchProps const cheerValue = `${prefix}${bits}`; setManualCheerValue(cheerValue); props.updateCheerNameOrPrefix(cheerValue); + props.updateMinimumBitsSpent(bits); // NB: Technically not in this form, but helps when switching } return (