Add implementation
This commit is contained in:
39
dist/server/ssr/assets/poll-R5-eIJ_b.js
vendored
Normal file
39
dist/server/ssr/assets/poll-R5-eIJ_b.js
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
function createPoll(title) {
|
||||
return {
|
||||
title,
|
||||
options: []
|
||||
};
|
||||
}
|
||||
function addOption(poll, text) {
|
||||
poll.options.push({
|
||||
id: crypto.randomUUID(),
|
||||
text,
|
||||
votes: []
|
||||
});
|
||||
}
|
||||
function hasVoted(poll, optionId, peerId) {
|
||||
const option = poll.options.find((o) => o.id === optionId);
|
||||
if (!option) return false;
|
||||
return option.votes.includes(peerId);
|
||||
}
|
||||
function vote(poll, optionId, peerId) {
|
||||
const option = poll.options.find((o) => o.id === optionId);
|
||||
if (!option) return;
|
||||
if (option.votes.includes(peerId)) return;
|
||||
option.votes.push(peerId);
|
||||
}
|
||||
function unvote(poll, optionId, peerId) {
|
||||
const option = poll.options.find((o) => o.id === optionId);
|
||||
if (!option) return;
|
||||
const idx = option.votes.indexOf(peerId);
|
||||
if (idx !== -1) {
|
||||
option.votes.splice(idx, 1);
|
||||
}
|
||||
}
|
||||
export {
|
||||
addOption as a,
|
||||
createPoll as c,
|
||||
hasVoted as h,
|
||||
unvote as u,
|
||||
vote as v
|
||||
};
|
||||
Reference in New Issue
Block a user