From ace042e9e6d035c63ca4e8a3df7a99e8cebf29a9 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Fri, 25 Feb 2022 03:09:26 -0500 Subject: [PATCH] cleaning up --- .../tts_configs/TtsConfigsEditRulePage.tsx | 66 ++++--------------- .../EventMatchPredicateBuilderComponent.tsx | 18 +---- 2 files changed, 14 insertions(+), 70 deletions(-) diff --git a/packages/storyteller/src/pages/tts_configs/TtsConfigsEditRulePage.tsx b/packages/storyteller/src/pages/tts_configs/TtsConfigsEditRulePage.tsx index 7c90f8742b..66d0959471 100644 --- a/packages/storyteller/src/pages/tts_configs/TtsConfigsEditRulePage.tsx +++ b/packages/storyteller/src/pages/tts_configs/TtsConfigsEditRulePage.tsx @@ -9,12 +9,9 @@ import { faAngleLeft, faSave } from '@fortawesome/free-solid-svg-icons'; import { EventMatchPredicate } from '@storyteller/components/src/api/storyteller/twitch_event_rules/shared/EventMatchPredicate'; import { EventResponse } from '@storyteller/components/src/api/storyteller/twitch_event_rules/shared/EventResponse'; import { TtsModelListItem } from '@storyteller/components/src/api/tts/ListTtsModels'; -import { TwitchEventCategory } from '@storyteller/components/src/api/storyteller/twitch_event_rules/shared/TwitchEventCategory'; import { EventResponseType } from './event_response_builder/EventResponseType'; import { EventResponseComponent } from './event_response_builder/EventResponseComponent'; -import { BitsRuleType } from './event_match_predicate_builder/types/BitsRuleType'; import { EventMatchPredicateBuilderComponent } from './event_match_predicate_builder/EventMatchPredicateBuilderComponent'; -import { CheerState } from './event_match_predicate_builder/CheerState'; interface Props { sessionWrapper: SessionWrapper, @@ -40,23 +37,16 @@ function TtsConfigsEditRulePage(props: Props) { // ========== In-Progress Model Edits ========== const [modifiedEventMatchPredicate, setModifiedEventMatchPredicate] = useState({}); + const [modifiedEventResponse, setModifiedEventResponse] = useState({}); + const [ruleIsDisabled, setRuleIsDisabled] = useState(false); // ========== ??? ========== // TODO: GET RID OF THIS const [eventResponseType, setEventResponseType] = useState(EventResponseType.TtsSingleVoice); - - // TODO: GET RID OF THIS const [ttsModelToken, setTtsModelToken] = useState(''); - // ===== Field values (final) ===== - - // TODO: GET RID OF non-"new" (see above) - const [eventMatchPredicate, setEventMatchPredicate] = useState({}); - const [eventResponse, setEventResponse] = useState({}); - const [ruleIsDisabled, setRuleIsDisabled] = useState(false); - const getTwitchEventRule = useCallback(async (token: string) => { const response = await GetTwitchEventRule(token); @@ -68,36 +58,10 @@ function TtsConfigsEditRulePage(props: Props) { // In-progress modifications setModifiedEventMatchPredicate(response.twitch_event_rule.event_match_predicate); - - // TODO REMOVE - setEventMatchPredicate(response.twitch_event_rule.event_match_predicate); - setEventResponse(response.twitch_event_rule.event_response); + setModifiedEventResponse(response.twitch_event_rule.event_response); setRuleIsDisabled(response.twitch_event_rule.rule_is_disabled); - let serverBitsRuleType = BitsRuleType.BitsCheermoteNameExactMatch; - - switch (response.twitch_event_rule.event_category) { - case TwitchEventCategory.Bits: - if (!!response.twitch_event_rule.event_match_predicate.bits_cheermote_name_exact_match) { - serverBitsRuleType = BitsRuleType.BitsCheermoteNameExactMatch; - } else if (!!response.twitch_event_rule.event_match_predicate.bits_cheermote_prefix_spend_threshold) { - serverBitsRuleType = BitsRuleType.BitsCheermotePrefixSpendThreshold; - //setMinimumBitsSpent(response.twitch_event_rule.event_match_predicate.bits_cheermote_prefix_spend_threshold.minimum_bits_spent); - } else if (!!response.twitch_event_rule.event_match_predicate.bits_spend_threshold) { - serverBitsRuleType = BitsRuleType.BitsSpendThreshold; - //setMinimumBitsSpent(response.twitch_event_rule.event_match_predicate.bits_spend_threshold.minimum_bits_spent); - } - break; - case TwitchEventCategory.ChannelPoints: // NB: Only one rule type - if (!!response.twitch_event_rule.event_match_predicate.channel_points_reward_name_exact_match) { - //setRewardName(response.twitch_event_rule.event_match_predicate.channel_points_reward_name_exact_match.reward_name); - } - break; - case TwitchEventCategory.ChatCommand: // TODO: Not yet supported - default: - break; - } - + // TODO: MOVE THIS if (!!response.twitch_event_rule.event_response.tts_single_voice) { setEventResponseType(EventResponseType.TtsSingleVoice); setTtsModelToken(response.twitch_event_rule.event_response.tts_single_voice.tts_model_token) @@ -129,7 +93,6 @@ function TtsConfigsEditRulePage(props: Props) { } setTtsModelToken(token); - setEventResponse(response); } const updateModifiedEventMatchPredicate = (predicate: EventMatchPredicate) => { @@ -139,13 +102,16 @@ function TtsConfigsEditRulePage(props: Props) { const handleFormSubmit = async (ev: React.FormEvent) : Promise => { ev.preventDefault(); - if (eventMatchPredicate === undefined || eventResponse === undefined) { - return false; - } + // TODO + // TODO + // TODO + + let newEventMatchPredicate = {}; + let newEventResponse = {}; const request = { - event_match_predicate: eventMatchPredicate, - event_response: eventResponse, + event_match_predicate: newEventMatchPredicate, + event_response: newEventResponse, rule_is_disabled: ruleIsDisabled, }; @@ -176,7 +142,7 @@ function TtsConfigsEditRulePage(props: Props) { // Updated in UI event_match_predicate: modifiedEventMatchPredicate, - event_response: eventResponse, + event_response: modifiedEventResponse, rule_is_disabled: ruleIsDisabled, }; @@ -197,7 +163,6 @@ function TtsConfigsEditRulePage(props: Props) { updateModifiedEventMatchPredicate={updateModifiedEventMatchPredicate} allTtsModels={props.allTtsModels} allTtsModelsByToken={props.allTtsModelsByToken} - />
@@ -235,9 +200,4 @@ function TtsConfigsEditRulePage(props: Props) { ) } -interface BitsSpendThresholdFormProps { -}; - - - export { TtsConfigsEditRulePage } \ No newline at end of file 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 e2afb389f8..d57c9007a5 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 @@ -10,7 +10,7 @@ import { ChannelPointsRewardNameExactMatchForm } from './subforms/ChannelPointsR import { ChannelPointsRuleType } from './types/ChannelPointsRuleType'; import { CheerUtil } from '../../../twitch/CheerUtil'; import { CheerState, CheerStateIsCustom, CheerStateIsOfficial, cheerStateToPredicate, predicateToCheerState } from './CheerState'; -import { CHEER_LOOKUP_MAP, CHEER_PREFIXES } from '../../../twitch/Cheers'; +import { CHEER_LOOKUP_MAP } from '../../../twitch/Cheers'; interface EventMatchPredicateBuilderComponentProps { // CANNOT BE CHANGED AFTER CREATION @@ -38,11 +38,6 @@ function EventMatchPredicateBuilderComponent(props: EventMatchPredicateBuilderCo // New, and remove everything else: const [cheerState, setCheerState] = useState({}); - - - - - // Used in: @@ -50,17 +45,11 @@ function EventMatchPredicateBuilderComponent(props: EventMatchPredicateBuilderCo // BitsCheermotePrefixSpendThreshold const [cheerNameOrPrefix, setCheerNameOrPrefix] = useState(''); // TODO: DIE -// // Used in: -// // BitsSpendThreshold -// // BitsCheermotePrefixSpendThreshold -// const [minimumBitsSpent, setMinimumBitsSpent] = useState(1); // TODO: DIE - // Shared state for : // BitsSpendThreshold // BitsCheermoteNameExactMatch // BitsCheermotePrefixSpendThreshold const [bitsValue, setBitsValue] = useState(1); - const [cheerPrefix, setCheerPrefix] = useState(''); // Used in: // ChannelPointsRewardNameExactMatch @@ -117,17 +106,12 @@ function EventMatchPredicateBuilderComponent(props: EventMatchPredicateBuilderCo if (!!cheerAndBitsV) { let { cheerPrefix, bitValue } = CheerUtil.parseCheerString(cheerAndBitsV); - setCheerPrefix(cheerPrefix || ''); setBitsValue(bitValue || 1); setCheerNameOrPrefix(cheerAndBitsV); // TODO: DIE } if (!!bitsV) { setBitsValue(bitsV || 1); } - if (!!cheerPrefixV) { - setCheerPrefix(cheerPrefixV || ''); - } - setBitsRuleType(newBitsRuleType); setChannelPointsRuleType(newChannelPointsRuleType);