Skip to content

Commit

Permalink
added result screen and publishing, as well as the option to manually…
Browse files Browse the repository at this point in the history
… reassign students in the assign screen
  • Loading branch information
JohanGrims committed Sep 21, 2024
1 parent 78cd513 commit f04700a
Show file tree
Hide file tree
Showing 7 changed files with 400 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/Vote.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import React, { useRef } from "react";
import { useLoaderData, useNavigate, useParams } from "react-router-dom";
import { db } from "./firebase";

import { snackbar } from "mdui";
import { confirm, snackbar } from "mdui";
import "./vote.css";

export default function Vote() {
Expand Down
12 changes: 11 additions & 1 deletion src/admin/Settings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,17 @@ export default function Settings() {
<p />
<br />
<p>Bei Problemen mit der Anzeige kann es helfen, den Cache zu leeren.</p>
<mdui-button onClick={() => localStorage.clear()} variant="tonal">
<mdui-button
onClick={() => {
localStorage.clear();
snackbar({
message: "Cache geleert",
action: "Neu laden",
onActionClick: () => window.location.reload(),
});
}}
variant="tonal"
>
Cache leeren
</mdui-button>
<p />
Expand Down
38 changes: 38 additions & 0 deletions src/admin/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,41 @@ td,
th {
text-wrap: nowrap;
}

.print-table {
display: none;
}

@media print {
.print-table {
display: block;
margin: 40px;
}
table {
width: 100%;
border-collapse: collapse;
}

th,
td {
border: 1px solid #ddd;
padding: 8px;
}

th {
background-color: #f2f2f2;
text-align: left;
}

tr:nth-child(even) {
background-color: #f9f9f9;
}

tr:hover {
background-color: #ddd;
}
tfoot {
background-color: #f2f2f2;
font-weight: bold;
}
}
10 changes: 9 additions & 1 deletion src/admin/vote/Answers.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { collection, doc, getDoc, getDocs } from "firebase/firestore/lite";
import {
collection,
deleteDoc,
doc,
getDoc,
getDocs,
setDoc,
} from "firebase/firestore/lite";
import { confirm, prompt } from "mdui";
import React from "react";
import { useLoaderData } from "react-router-dom";
import { db } from "../../firebase";
Expand Down
158 changes: 149 additions & 9 deletions src/admin/vote/Assign.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ export default function Assign() {
console.log(data);

setResults(data);
if (window.location.hostname === "localhost") {
console.log("Running on localhost");
setLoading(false);
}
setTimeout(() => setLoading(false), 5000);
} catch (error) {
console.error("Error fetching optimization:", error);
Expand Down Expand Up @@ -299,7 +303,7 @@ export default function Assign() {
</ul>
<mdui-radio-group value={mode}>
<mdui-radio value="by-option" onClick={() => setMode("by-option")}>
Nach Erstwahl
Nach Projekt
</mdui-radio>
<mdui-radio value="by-grade" onClick={() => setMode("by-grade")}>
Nach Klasse
Expand All @@ -320,14 +324,12 @@ export default function Assign() {
key={i}
value={option.id}
>
{option.title}
<mdui-badge>
{
Object.values(results).filter(
(result) => result === option.id
).length
}
</mdui-badge>
{option.title} (
{
sortedResults.filter(([key, value]) => value === option.id)
.length
}
/{option.max})
</mdui-tab>
))}
{options.map((option, i) => (
Expand All @@ -344,6 +346,14 @@ export default function Assign() {
<th>
<b>Klasse</b>
</th>
{Array.from(
{ length: vote.selectCount },
(_, i) => i + 1
).map((i) => (
<th key={i}>
<b>Wahl {i}</b>
</th>
))}
</tr>
</thead>
<tbody>
Expand All @@ -360,6 +370,136 @@ export default function Assign() {
.grade
}
</td>
{choices
.find((choice) => choice.id === key)
.selected.map((selected, i) => (
<td
key={i}
style={{
cursor: selected !== value && "pointer",
textDecoration:
selected !== value && "underline",
color:
selected !== value && "rgb(27, 68, 133)",
}}
onClick={() => {
if (selected === value) return;
const newResults = { ...results };
newResults[key] = selected;
setResults(newResults);
const previousResults = { ...results };
snackbar({
message: "Änderung rückgängig machen",
action: "Rückgängig",
onActionClick: () =>
setResults(previousResults),
});
}}
>
{selected === value
? "✓"
: `${
options.find(
(option) => option.id === selected
).title
} (${
sortedResults.filter(
([key, value]) => value === selected
).length
}/${
options.find(
(option) => option.id === selected
).max
})`}
</td>
))}
</tr>
))}
</tbody>
</table>
</div>
<h2 style={{ color: "gray" }}>Alle Wähler</h2>
<div
className="mdui-table"
style={{ width: "100%", color: "gray" }}
>
<table>
<thead>
<tr>
<th>
<b>Name</b>
</th>
<th>
<b>Klasse</b>
</th>
<th>
<b>#</b>
</th>
{Array.from(
{ length: vote.selectCount },
(_, i) => i + 1
).map((i) => (
<th key={i}>
<b>Wahl {i}</b>
</th>
))}
</tr>
</thead>
<tbody>
{choices
.filter((choice) => choice.selected.includes(option.id))
.sort((a, b) => a.name.localeCompare(b.name))
.map((choice, i) => (
<tr key={i}>
<td>{choice.name}</td>
<td>{choice.grade}</td>
<td>{choice.listIndex}</td>
{choice.selected.map((selected, i) => (
<td
key={i}
style={{
cursor:
results[choice.id] !== selected &&
"pointer",
textDecoration:
results[choice.id] !== selected &&
"underline",
color:
results[choice.id] !== selected &&
"rgb(27, 68, 133)",
}}
onClick={() => {
if (results[choice.id] === selected) return;
const newResults = { ...results };
newResults[choice.id] = selected;
setResults(newResults);
const previousResults = { ...results };
snackbar({
message: "Änderung rückgängig machen",
action: "Rückgängig",
onActionClick: () =>
setResults(previousResults),
});
}}
>
{
options.find(
(option) => option.id === selected
).title
}

{results[choice.id] === selected &&
` (${
sortedResults.filter(
([key, value]) => value === selected
).length
}/${
options.find(
(option) => option.id === selected
).max
}) ✓`}
</td>
))}
</tr>
))}
</tbody>
Expand Down
Loading

0 comments on commit f04700a

Please sign in to comment.