Add index page and link to share more easily

This commit is contained in:
2025-01-20 10:13:59 +01:00
parent 5668b1cd6a
commit bddae031cc
5 changed files with 53 additions and 6 deletions

View File

@ -17,6 +17,17 @@ import (
"time"
)
func (app *application) indexPage(w http.ResponseWriter, r *http.Request) {
content, err := ui.Files.ReadFile("index.html")
if err != nil {
app.serverError(w, r, err)
return
}
w.Header().Set("Content-Type", "text/html")
w.Write(content)
}
func (app *application) createElectionPage(w http.ResponseWriter, r *http.Request) {
content, err := ui.Files.ReadFile("create-election.html")
if err != nil {

View File

@ -22,6 +22,7 @@ func (app *application) routes() http.Handler {
cached := alice.New(app.cacheStatic)
mux.Handle("GET /static/", cached.Then(http.FileServerFS(ui.Files)))
mux.HandleFunc("GET /", app.indexPage)
mux.HandleFunc("GET /election/create", app.createElectionPage)
mux.HandleFunc("GET /election/{id}", app.getElectionPage)

View File

@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Create New Election</title>
<title>Create New Election - qv</title>
<script src="/static/js/tailwind.min.js"></script>
<script src="/static/js/alpine.min.js" defer></script>
</head>
@ -90,10 +90,17 @@
</ul>
</div>
<template x-if="createdElectionId > 0">
<template x-if="createdElectionId != ''">
<div class="mt-6 bg-green-100 p-4 rounded-md">
<h2 class="text-green-700 font-bold">Election Created Successfully</h2>
<p class="mt-2">Election ID: <span class="font-mono" x-text="createdElectionId"></span></p> <!-- TODO: link to created election -->
<p class="mt-2">
<a
:href="`/election/${createdElectionId}`"
class="text-blue-600 underline hover:text-blue-800"
target="_blank">
View Election
</a>
</p>
</div>
</template>
@ -132,7 +139,7 @@
expiresAt: "",
choices: ["", ""]
},
createdElectionId: 0,
createdElectionId: "",
errorMessage: "",
errorDetails: {},
voterIdentities: [],
@ -148,7 +155,7 @@
async createElection() {
this.errorMessage = "";
this.errorDetails = {};
this.createdElectionId = 0;
this.createdElectionId = "";
this.voterIdentities = [];
const payload = {

View File

@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vote in Election</title>
<title>Vote in Election - qv</title>
<script src="/static/js/tailwind.min.js"></script>
<script src="/static/js/alpine.min.js" defer></script>
</head>

28
ui/index.html Normal file
View File

@ -0,0 +1,28 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>qv</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-gray-100 text-gray-900">
<div class="min-h-screen flex flex-col items-center justify-center">
<header class="text-center mb-8">
<h1 class="text-4xl font-bold mb-4">Quadratic Voting</h1>
<p class="text-lg text-gray-600">Start your journey by creating a new election.</p>
</header>
<main class="text-center">
<a href="/election/create"
class="bg-blue-600 text-white text-lg font-semibold px-6 py-3 rounded-lg hover:bg-blue-700">
Create Election
</a>
</main>
<footer class="mt-12 text-center text-gray-600">
<p>See the source code<a href="https://code.dlmw.ch/dlmw/qv"></a></p>
</footer>
</div>
</body>
</html>