@livelike/react-native
Version:
LiveLike React Native package
40 lines • 1.39 kB
JavaScript
import { CHOICE_WIDGET_KIND } from '@livelike/javascript';
import { useMemo } from 'react';
import { useWidgetChoices } from './useWidgetChoices';
import { useWidgetInteractions } from './useWidgetInteractions';
import { useWidgetOptions } from './useWidgetOptions';
export function useInteractedWidgetOption(_ref) {
let {
widgetId
} = _ref;
const widgetInteractions = useWidgetInteractions({
widgetId
});
const widgetOptions = useWidgetOptions({
widgetId
});
const widgetChoices = useWidgetChoices({
widgetId
});
return useMemo(() => {
if (!(widgetInteractions !== null && widgetInteractions !== void 0 && widgetInteractions.length)) {
return undefined;
}
if (CHOICE_WIDGET_KIND.includes(widgetInteractions[0].widget_kind)) {
if (!(widgetChoices !== null && widgetChoices !== void 0 && widgetChoices.length)) {
return undefined;
}
return widgetChoices.find(option => option.id === widgetInteractions[0].choice_id);
}
if (!(widgetOptions !== null && widgetOptions !== void 0 && widgetOptions.length)) {
return undefined;
}
return widgetOptions.find(option => widgetInteractions.find(_ref2 => {
let {
option_id
} = _ref2;
return option.id === option_id;
}));
}, [widgetInteractions, widgetOptions]);
}
//# sourceMappingURL=useInteractedWidgetOption.js.map