UNPKG

@livelike/react-native

Version:

LiveLike React Native package

51 lines 1.55 kB
import React, { useCallback } from 'react'; import { LLWidgetSubmitButtonComponent } from '../LLWidgetFooter'; import { useIsEndWidgetUIPhase, useIsWidgetDisabled, useWidgetChoices, useWidgetSelectedOptionIndex, useWidgetSubmitAction } from '../../hooks'; export function LLQuizWidgetSubmitButton(_ref) { let { widgetId, styles, onPress } = _ref; const { onInteractionSubmit } = useWidgetSubmitAction({ widgetId }); const widgetChoices = useWidgetChoices({ widgetId }); const selectedOptionIndex = useWidgetSelectedOptionIndex({ widgetId }); const widgetDisabled = useIsWidgetDisabled({ widgetId }); const isEndWidgetUIPhase = useIsEndWidgetUIPhase({ widgetId }); const onSubmit = useCallback(() => { if (isInvalidSelectedOptionIndex(selectedOptionIndex)) { return; } onPress === null || onPress === void 0 || onPress({ selectedOptionIndex }); const interactionItem = widgetChoices[selectedOptionIndex]; onInteractionSubmit({ interactionItem }); }, [widgetChoices, selectedOptionIndex]); if (isEndWidgetUIPhase) { return undefined; } return /*#__PURE__*/React.createElement(LLWidgetSubmitButtonComponent, { disabled: widgetDisabled || isInvalidSelectedOptionIndex(selectedOptionIndex), onPress: onSubmit, styles: styles }); } function isInvalidSelectedOptionIndex(selectedOptionIndex) { return selectedOptionIndex === undefined || selectedOptionIndex < 0; } //# sourceMappingURL=LLQuizWidgetSubmitButton.js.map