@livelike/react-native
Version:
LiveLike React Native package
59 lines (58 loc) • 2.47 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.LLQuizWidgetSubmitButton = LLQuizWidgetSubmitButton;
var _react = _interopRequireWildcard(require("react"));
var _LLWidgetFooter = require("../LLWidgetFooter");
var _hooks = require("../../hooks");
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function LLQuizWidgetSubmitButton(_ref) {
let {
widgetId,
styles,
onPress
} = _ref;
const {
onInteractionSubmit
} = (0, _hooks.useWidgetSubmitAction)({
widgetId
});
const widgetChoices = (0, _hooks.useWidgetChoices)({
widgetId
});
const selectedOptionIndex = (0, _hooks.useWidgetSelectedOptionIndex)({
widgetId
});
const widgetDisabled = (0, _hooks.useIsWidgetDisabled)({
widgetId
});
const isEndWidgetUIPhase = (0, _hooks.useIsEndWidgetUIPhase)({
widgetId
});
const onSubmit = (0, _react.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.default.createElement(_LLWidgetFooter.LLWidgetSubmitButtonComponent, {
disabled: widgetDisabled || isInvalidSelectedOptionIndex(selectedOptionIndex),
onPress: onSubmit,
styles: styles
});
}
function isInvalidSelectedOptionIndex(selectedOptionIndex) {
return selectedOptionIndex === undefined || selectedOptionIndex < 0;
}
//# sourceMappingURL=LLQuizWidgetSubmitButton.js.map