ars/templates/play.stpl

65 lines
2.9 KiB
Text
Raw Normal View History

2023-11-01 21:12:18 +01:00
<% if !htmx {%>
<!DOCTYPE html>
<html>
<head>
<title>zettoIT ARS</title>
<meta charset="UTF-8">
<link rel="stylesheet" href="/static/pico.min.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<main class="container" hx-sse="connect:/<%= id %>/events?player=<%=player_id%> swap:message">
<% } %>
<% if let PlayerState::NotStarted = state { %>
<article>
<center>The Quiz hasn't started yet. Please wait for the first question.</center>
</article>
<% } else if let PlayerState::Answering((field_id, field)) = state { %>
<article>
<h1><%= field.name %></h1>
<% for (index, answer) in field.answers.iter().enumerate() { %>
<form method="POST" hx-post="" hx-target="closest main">
<input type="hidden" name="player_id" value="<%= player_id %>"></input>
<input type="hidden" name="selected" value="<%= index %>"></input>
<button type="submit"><%= answer %></button>
</form>
<% } %>
</article>
<% } else if let PlayerState::Waiting(_) = state{ %>
<article aria-busy="true">
You answered the current question. Please wait for the results.
</article>
<% } else if let PlayerState::Result((field, selected)) = state{ %>
<% if Some(field.correct) == selected { %>
<article>
<center><img src="./static/check.svg" width="50%"/></center>
<center><h1>Correct</h1></center>
<center><p>Your answer is correct. The correct answer is <b><%= field.answers[field.correct as usize] %></b>.</p></center>
</article>
<% } else { %>
<article>
<center><img src="./static/xmark.svg" width="50%"/></center>
<center><h1>Wrong</h1></center>
<center><p>
Your answer is incorrect. The correct answer is <b><%= field.answers[field.correct as usize] %></b>.
<% if let Some(s) = selected { %>
You answered <b><%=field.answers[s as usize]%></b>.
<% } else { %>
You didn't answer the question.
<% } %>
</p></center>
</article>
<% } %>
<% } else if let PlayerState::Completed(correct) = state { %>
<article>
The Quiz finished. You can close this tab now. You answered <b><%= correct*100.0 %>%</b> correctly.
</article>
<% } %>
<% if !htmx { %>
</main>
<script src="/static/htmx.min.js"></script>
</body>
</html>
<% } %>