Skip to content

Commit

Permalink
Refactored QueueFormField to make easier to read
Browse files Browse the repository at this point in the history
  • Loading branch information
ryantanen committed Feb 12, 2025
1 parent 7f9e637 commit 8d0659b
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions frontend/components/Course/InstructorQueuePage/QueueFormFields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,13 @@ const QueueFormFields = ({
setInput({ ...input });
};
/* PROPS UPDATE */
// Helper function to handle toggle changes
const handleToggleChange = (name: string) => {
setInput({
...input,
[name]: !input[name],
});
};

return (
<>
Expand Down Expand Up @@ -241,12 +248,7 @@ const QueueFormFields = ({
id="pin-toggle"
toggle
disabled={loading}
onClick={() =>
setInput({
...input,
pinEnabled: !input.pinEnabled,
})
}
onClick={() => handleToggleChange("pinEnabled")}
/>
</Form.Field>

Expand All @@ -263,12 +265,7 @@ const QueueFormFields = ({
toggle
checked={input.rateLimitEnabled}
label="Enable queue rate-limiting"
onClick={() =>
setInput({
...input,
rateLimitEnabled: !input.rateLimitEnabled,
})
}
onClick={() => handleToggleChange("rateLimitEnabled")}
/>

{input.rateLimitEnabled && (
Expand Down Expand Up @@ -382,11 +379,7 @@ const QueueFormFields = ({
toggle
label="Enable a countdown for questions"
onChange={() =>
setInput({
...input,
questionTimerEnabled:
!input.questionTimerEnabled,
})
handleToggleChange("questionTimerEnabled")
}
/>
</Form.Field>
Expand Down

0 comments on commit 8d0659b

Please sign in to comment.