Skip to content

Commit 2cb3649

Browse files
Merge pull request #1 from zweidenker/Vote-Once
Use localStorage to check if a user has already voted for a particula…
2 parents 1ce42c1 + 66ea9a8 commit 2cb3649

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

index.html

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@
211211
</div>
212212

213213
<script>
214+
const DEFAULT_POLLY_URL = 'https://app.apptivegrid.de/api/users/62398e23b8b578b35b971df0/spaces/66bcc1d7f549cad6d6dbf2be/grids/66bcc1dcf549ca6236dbf2c4/entities/BqWFtLCV6KM?layout=key';
215+
214216
const thumb = document.getElementById('thumb');
215217
const needle = document.getElementById('needle');
216218
const valueDisplay = document.getElementById('valueDisplay');
@@ -310,6 +312,7 @@
310312
hasSubmitted = true; // Mark as submitted
311313
drawCircles();
312314
calculatePercentages(entity);
315+
setVoteSubmitted();
313316
})
314317
.catch(error => {
315318
console.error('Failed to post data:', error);
@@ -427,7 +430,7 @@
427430
});
428431
document.addEventListener("DOMContentLoaded", function() {
429432
const urlParams = new URLSearchParams(window.location.search);
430-
const url = urlParams.get('url') || 'https://app.apptivegrid.de/api/users/62398e23b8b578b35b971df0/spaces/66bcc1d7f549cad6d6dbf2be/grids/66bcc1dcf549ca6236dbf2c4/entities/BqWFtLCV6KM?layout=key';
433+
const url = urlParams.get('url') || DEFAULT_POLLY_URL;
431434
const username = urlParams.get('username') || '23bd064465e583233eab7807507a715c';
432435
const password = urlParams.get('password') || 'a7hkqxt2qj8rfverccyzn4agt';
433436

@@ -452,7 +455,9 @@
452455
document.getElementById('question').textContent = data['question'] || 'No question found in response.';
453456
document.getElementById('answer1').textContent = data['answer_1'] || 'No answer_1 found in response.';
454457
document.getElementById('answer2').textContent = data['answer_2'] || 'No answer_2 found in response.';
455-
document.getElementById('numberOfResultsDisplay').textContent = data['numberOfResults']['value'] || 'No numberOfResults found in response.';
458+
if (previouslySubmitted()) {
459+
showResults();
460+
}
456461
})
457462
.catch(error => {
458463
document.getElementById('valueDisplay').textContent = 'Fehler: ' + error.message;
@@ -462,6 +467,39 @@
462467
}
463468
});
464469

470+
function getPollyEntity() {
471+
const urlParams = new URLSearchParams(window.location.search);
472+
return urlParams.get('url') || DEFAULT_POLLY_URL;
473+
}
474+
475+
function getVotedUrlArray() {
476+
const stringArray = localStorage.getItem('voteUrl')
477+
if (!stringArray) {
478+
return []
479+
}
480+
return JSON.parse(stringArray)
481+
}
482+
483+
function setVoteSubmitted() {
484+
const array = getVotedUrlArray();
485+
array.push(getPollyEntity());
486+
localStorage.setItem('voteUrl', JSON.stringify(array));
487+
}
488+
489+
function previouslySubmitted() {
490+
const array = getVotedUrlArray();
491+
return array.includes(getPollyEntity());
492+
}
493+
494+
function showResults() {
495+
hasSubmitted = true; // Mark as submitted
496+
document.getElementById('needle').setAttribute('style', 'display: none')
497+
document.getElementById('thumb').setAttribute('style', 'display: none')
498+
document.getElementById('arrows').setAttribute('style', 'display: none')
499+
drawCircles();
500+
calculatePercentages(entity);
501+
}
502+
465503
async function postDataToApptiveGrid(data) {
466504
const url = entity['flow_uri'];
467505

0 commit comments

Comments
 (0)