stream-chat-react-native-core
Version:
The official React Native and Expo components for Stream Chat, a service for building chat applications
85 lines • 3.23 kB
JavaScript
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.usePollState = void 0;
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _react = require("react");
var _useEndVote = require("./useEndVote");
var _usePollStateStore2 = require("./usePollStateStore");
var _contexts = require("../../../contexts");
var selector = nextValue => ({
allowAnswers: nextValue.allow_answers,
allowUserSuggestedOptions: nextValue.allow_user_suggested_options,
answersCount: nextValue.answers_count,
createdBy: nextValue.created_by,
enforceUniqueVote: nextValue.enforce_unique_vote,
isClosed: nextValue.is_closed,
latestVotesByOption: nextValue.latest_votes_by_option,
maxVotedOptionIds: nextValue.maxVotedOptionIds,
maxVotesAllowed: nextValue.max_votes_allowed,
name: nextValue.name,
options: nextValue.options,
ownAnswer: nextValue.ownAnswer,
ownVotesByOptionId: nextValue.ownVotesByOptionId,
voteCountsByOption: nextValue.vote_counts_by_option,
votingVisibility: nextValue.voting_visibility,
voteCount: nextValue.vote_count
});
var usePollState = () => {
var _usePollContext = (0, _contexts.usePollContext)(),
message = _usePollContext.message,
poll = _usePollContext.poll;
var _usePollStateStore = (0, _usePollStateStore2.usePollStateStore)(selector),
allowAnswers = _usePollStateStore.allowAnswers,
allowUserSuggestedOptions = _usePollStateStore.allowUserSuggestedOptions,
answersCount = _usePollStateStore.answersCount,
createdBy = _usePollStateStore.createdBy,
enforceUniqueVote = _usePollStateStore.enforceUniqueVote,
isClosed = _usePollStateStore.isClosed,
latestVotesByOption = _usePollStateStore.latestVotesByOption,
maxVotedOptionIds = _usePollStateStore.maxVotedOptionIds,
maxVotesAllowed = _usePollStateStore.maxVotesAllowed,
name = _usePollStateStore.name,
options = _usePollStateStore.options,
ownAnswer = _usePollStateStore.ownAnswer,
ownVotesByOptionId = _usePollStateStore.ownVotesByOptionId,
voteCountsByOption = _usePollStateStore.voteCountsByOption,
votingVisibility = _usePollStateStore.votingVisibility,
voteCount = _usePollStateStore.voteCount;
var addOption = (0, _react.useCallback)(function () {
var _ref = (0, _asyncToGenerator2.default)(function* (optionText) {
yield poll.createOption({
text: optionText
});
});
return function (_x) {
return _ref.apply(this, arguments);
};
}(), [poll]);
var addComment = (0, _react.useCallback)(answerText => poll.addAnswer(answerText, message.id), [message.id, poll]);
var endVote = (0, _useEndVote.useEndVote)();
return {
addComment,
addOption,
allowAnswers,
allowUserSuggestedOptions,
answersCount,
createdBy,
endVote,
enforceUniqueVote,
isClosed,
latestVotesByOption,
maxVotedOptionIds,
maxVotesAllowed,
name,
options,
ownAnswer,
ownVotesByOptionId,
voteCountsByOption,
votingVisibility,
voteCount
};
};
exports.usePollState = usePollState;
//# sourceMappingURL=usePollState.js.map