Skip to content

Commit

Permalink
Refactor Vote component to use useEffect for navigation logic and imp…
Browse files Browse the repository at this point in the history
…rove code readability
  • Loading branch information
JohanGrims committed Dec 10, 2024
1 parent 914008b commit d1cadf7
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions src/Vote.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,28 +53,30 @@ export default function Vote() {
const preview = urlParams.get("preview");


if (localStorage.getItem(id) && !urlParams.get("preview")) {
if (urlParams.get("allowResubmission")) {
navigate(`/x/${id}?allowResubmission=true`);
return;
React.useEffect(() => {
if (localStorage.getItem(id) && !urlParams.get("preview")) {
if (urlParams.get("allowResubmission")) {
navigate(`/x/${id}?allowResubmission=true`);
return;
}
navigate(`/x/${id}`);
}
navigate(`/x/${id}`);
}

if ((active === false || Date.now() > endTime.seconds * 1000) && !preview) {
snackbar({ message: "Die Wahl ist bereits beendet." });
navigate(`/r/${id}`);
}
if (Date.now() < startTime.seconds * 1000 && !preview) {
snackbar({
message:
"Die Wahl startet erst am " +
moment
.tz(startTime.seconds * 1000, "Europe/Berlin")
.format("dddd, D. MMMM YYYY, HH:mm"),
});
navigate("/");
}
if ((active === false || Date.now() > endTime.seconds * 1000) && !preview) {
snackbar({ message: "Die Wahl ist bereits beendet." });
navigate(`/r/${id}`);
}
if (Date.now() < startTime.seconds * 1000 && !preview) {
snackbar({
message:
"Die Wahl startet erst am " +
moment
.tz(startTime.seconds * 1000, "Europe/Berlin")
.format("dddd, D. MMMM YYYY, HH:mm"),
});
navigate("/");
}
}, [active, endTime, id, navigate, preview, startTime, urlParams]);


const submitDisabled = () => {
Expand Down

0 comments on commit d1cadf7

Please sign in to comment.