Skip to content

Commit 93c0aa4

Browse files
authored
Create vote.html
1 parent fb451b0 commit 93c0aa4

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed

ui/templates/vote.html

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}">
7+
<title>Vote on Proposals - Stable Pi Core</title>
8+
</head>
9+
<body>
10+
<div class="container">
11+
<header>
12+
<h1>Vote on Proposals</h1>
13+
<p>Participate in the decision-making process by voting on proposals.</p>
14+
</header>
15+
16+
<main>
17+
<section id="vote-section" aria-labelledby="vote-section-header">
18+
<h2 id="vote-section-header">Vote on a Proposal</h2>
19+
<div class="input-group">
20+
<input type="number" id="proposal-id" placeholder="Enter proposal ID" aria-label="Proposal ID">
21+
<button onclick="vote()" aria-label="Vote on proposal">Vote</button>
22+
</div>
23+
<div id="vote-result" class="result-box" aria-live="polite"></div>
24+
</section>
25+
26+
<section id="existing-proposals" aria-labelledby="existing-proposals-header">
27+
<h2 id="existing-proposals-header">Current Proposals</h2>
28+
<ul id="proposals-list"></ul>
29+
</section>
30+
</main>
31+
32+
<footer>
33+
<p>&copy; 2023 Stable Pi Core. All rights reserved.</p>
34+
</footer>
35+
</div>
36+
37+
<script src="{{ url_for('static', filename='script.js') }}"></script>
38+
<script>
39+
// Function to load existing proposals
40+
function loadProposals() {
41+
fetch('/dao/proposals')
42+
.then(response => response.json())
43+
.then(data => {
44+
const proposalsList = document.getElementById('proposals-list');
45+
proposalsList.innerHTML = ''; // Clear existing list
46+
data.forEach(proposal => {
47+
const listItem = document.createElement('li');
48+
listItem.innerText = `ID: ${proposal.id}, Description: ${proposal.description}, Votes: ${proposal.voteCount}, Executed: ${proposal.executed}`;
49+
proposalsList.appendChild(listItem);
50+
});
51+
})
52+
.catch(error => {
53+
console.error('Error loading proposals:', error);
54+
});
55+
}
56+
57+
// Function to vote on a proposal
58+
function vote() {
59+
const proposalId = document.getElementById('proposal-id').value;
60+
fetch('/dao/vote', {
61+
method: 'POST',
62+
headers: {
63+
'Content-Type': 'application/json'
64+
},
65+
body: JSON.stringify({ proposal_id: proposalId })
66+
})
67+
.then(response => {
68+
if (!response.ok) {
69+
throw new Error('Network response was not ok');
70+
}
71+
return response.json();
72+
})
73+
.then(data => {
74+
document.getElementById('vote-result').innerText = 'Vote recorded successfully!';
75+
document.getElementById('proposal-id').value = ''; // Clear input
76+
loadProposals(); // Refresh the proposals list
77+
})
78+
.catch(error => {
79+
document.getElementById('vote-result').innerText = 'Error voting: ' + error.message;
80+
});
81+
}
82+
83+
// Load proposals on page load
84+
window.onload = loadProposals;
85+
</script>
86+
</body>
87+
</html>

0 commit comments

Comments
 (0)