stream-chat-react-native-core
Version:
The official React Native and Expo components for Stream Chat, a service for building chat applications
39 lines • 1.67 kB
JavaScript
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.usePollVoteToggle = void 0;
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _usePollStateStore2 = require("./usePollStateStore");
var _contexts = require("../../../contexts");
var _hooks = require("../../../hooks");
var _Notifications = require("../../Notifications");
var ownVotesSelector = state => ({
ownVotesByOptionId: state.ownVotesByOptionId
});
var usePollVoteToggle = () => {
var _usePollContext = (0, _contexts.usePollContext)(),
message = _usePollContext.message,
poll = _usePollContext.poll;
var _useNotificationApi = (0, _Notifications.useNotificationApi)(),
runWithNotificationTarget = _useNotificationApi.runWithNotificationTarget;
var _usePollStateStore = (0, _usePollStateStore2.usePollStateStore)(ownVotesSelector),
ownVotesByOptionId = _usePollStateStore.ownVotesByOptionId;
return (0, _hooks.useStableCallback)(function () {
var _ref = (0, _asyncToGenerator2.default)(function* (optionId) {
yield runWithNotificationTarget((0, _asyncToGenerator2.default)(function* () {
var existingVoteId = ownVotesByOptionId[optionId]?.id;
if (existingVoteId) {
yield poll.removeVote(existingVoteId, message.id);
} else {
yield poll.castVote(optionId, message.id);
}
}));
});
return function (_x) {
return _ref.apply(this, arguments);
};
}());
};
exports.usePollVoteToggle = usePollVoteToggle;
//# sourceMappingURL=usePollVoteToggle.js.map