Skip to content

Commit

Permalink
sending state
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanGrims authored Oct 24, 2024
1 parent 26e1012 commit 19bde71
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Vote.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ export default function Vote() {

const [confirmDialog, setConfirmDialog] = React.useState(false);


const [sending, setSending] = React.useState(false)

React.useEffect(() => {
document.title = title;

Expand Down Expand Up @@ -84,6 +87,7 @@ export default function Vote() {
}

function submit() {
setSending(true)
addDoc(collection(db, `/votes/${id}/choices`), {
name: `${firstName} ${lastName.charAt(0)}.`,
grade,
Expand All @@ -94,6 +98,7 @@ export default function Vote() {
timestamp: serverTimestamp(),
})
.then((e) => {
setSending(false)
localStorage.setItem(
id,
JSON.stringify({ choiceId: e.id, timestamp: Date.now() })
Expand All @@ -105,6 +110,7 @@ export default function Vote() {
navigate(`/x/${id}`);
})
.catch((error) => {
setSending(false)
console.log(JSON.stringify(error));
if (error.code === "permission-denied") {
alert(
Expand Down Expand Up @@ -190,6 +196,11 @@ export default function Vote() {
)
.join(", ")}
<p />
{
sending?(
<div/>
):(<div/>)
}
<div className="button-container">
<mdui-button onClick={() => setConfirmDialog(false)} variant="text">
Abbrechen
Expand Down

0 comments on commit 19bde71

Please sign in to comment.