Skip to content

Commit

Permalink
fix loading state
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanGrims authored Oct 24, 2024
1 parent 19bde71 commit e5f8cb7
Showing 1 changed file with 30 additions and 18 deletions.
48 changes: 30 additions & 18 deletions src/Vote.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ export default function Vote() {

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


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

React.useEffect(() => {
document.title = title;
Expand Down Expand Up @@ -87,7 +86,7 @@ export default function Vote() {
}

function submit() {
setSending(true)
setSending(true);
addDoc(collection(db, `/votes/${id}/choices`), {
name: `${firstName} ${lastName.charAt(0)}.`,
grade,
Expand All @@ -98,7 +97,7 @@ export default function Vote() {
timestamp: serverTimestamp(),
})
.then((e) => {
setSending(false)
setSending(false);
localStorage.setItem(
id,
JSON.stringify({ choiceId: e.id, timestamp: Date.now() })
Expand All @@ -110,7 +109,7 @@ export default function Vote() {
navigate(`/x/${id}`);
})
.catch((error) => {
setSending(false)
setSending(false);
console.log(JSON.stringify(error));
if (error.code === "permission-denied") {
alert(
Expand Down Expand Up @@ -196,19 +195,32 @@ export default function Vote() {
)
.join(", ")}
<p />
{
sending?(
<div/>
):(<div/>)
}
<div className="button-container">
<mdui-button onClick={() => setConfirmDialog(false)} variant="text">
Abbrechen
</mdui-button>
<mdui-button onClick={submit} end-icon="send">
Absenden
</mdui-button>
</div>
{!sending ? (
<div className="button-container">
<mdui-button
onClick={() => setConfirmDialog(false)}
variant="text"
>
Abbrechen
</mdui-button>
<mdui-button onClick={submit} end-icon="send">
Absenden
</mdui-button>
</div>
) : (
<div className="button-container">
<mdui-button
onClick={() => setConfirmDialog(false)}
variant="text"
disabled
>
Abbrechen
</mdui-button>
<mdui-button onClick={submit} end-icon="send" disabled loading>
Absenden
</mdui-button>
</div>
)}
</div>
</mdui-dialog>
<mdui-card variant="outlined" class="card">
Expand Down

0 comments on commit e5f8cb7

Please sign in to comment.