Poll
This commit is contained in:
@@ -15,14 +15,14 @@ const store = reactive({
|
||||
});
|
||||
const { currentPoll } = storeToRefs(store.poll);
|
||||
const { currentPollOptions } = storeToRefs(store.pollOptions);
|
||||
const { currentPollResponses } = storeToRefs(store.pollResponse);
|
||||
// const { currentPollResponses } = storeToRefs(store.pollResponse);
|
||||
const poll = reactive<Poll | any>({});
|
||||
const options = ref<PollOption[] | any[]>([]);
|
||||
|
||||
async function loadData() {
|
||||
await store.poll.fetchById(String(props.dataId));
|
||||
await store.pollOptions.fetchByPollId(String(props.dataId));
|
||||
await store.pollResponse.fetchByPollId(String(props.dataId));
|
||||
// await store.pollResponse.fetchByPollId(String(props.dataId));
|
||||
assignData();
|
||||
}
|
||||
|
||||
@@ -78,14 +78,17 @@ async function submitVote() {
|
||||
switch (poll.type) {
|
||||
case 1:
|
||||
if(singleSelect.value >= 0) {
|
||||
totalResponses.value = options.value?.reduce((sum, option) => sum + Number(option.responseCount ?? 0), 1);
|
||||
options?.value?.forEach((option: PollOption | any) => {
|
||||
if (option.id === singleSelect.value) {
|
||||
option.responseCount = (option.responseCount ?? 0) + 1;
|
||||
const result = await store.pollResponse.create({ optionId: singleSelect.value })
|
||||
if(result?.id) {
|
||||
totalResponses.value = options.value?.reduce((sum, option) => sum + Number(option.responseCount ?? 0), 1);
|
||||
options?.value?.forEach((option: PollOption | any) => {
|
||||
if (option.id === singleSelect.value) {
|
||||
option.responseCount = (option.responseCount ?? 0) + 1;
|
||||
}
|
||||
option.percentage = Number(((option.responseCount / totalResponses.value) * 100).toFixed(1));
|
||||
alreadyVoted.value = true
|
||||
});
|
||||
}
|
||||
option.percentage = Number(((option.responseCount / totalResponses.value) * 100).toFixed(1));
|
||||
alreadyVoted.value = true
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user