Skip to content

Commit

Permalink
Ensure only submit once
Browse files Browse the repository at this point in the history
  • Loading branch information
gycgabriel committed Nov 3, 2023
1 parent a494776 commit 5821afc
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions frontend/src/components/room/code-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type CodeEditorProps = {
onChange: React.Dispatch<React.SetStateAction<string>>;
onCursorChange?: React.Dispatch<React.SetStateAction<number>>;
hasRoom?: boolean;
onSubmitClick?: () => void;
onSubmitClick?: (value: string) => void;
onLeaveRoomClick?: () => void;
};

Expand Down Expand Up @@ -68,7 +68,7 @@ export default function CodeEditor({
onChange,
onCursorChange,
hasRoom = true,
onSubmitClick = (value) => {},
onSubmitClick = () => {},
onLeaveRoomClick = () => {},
}: CodeEditorProps) {
const [open, setOpen] = React.useState(false);
Expand Down Expand Up @@ -121,12 +121,10 @@ export default function CodeEditor({
}
setIsSubmitting(true);
try {
onChange(value);
onSubmitClick(value);
await onChange(value);
await onSubmitClick(value);
} catch (error) {
console.log(error);
} finally {
setIsSubmitting(false);
}
};

Expand Down Expand Up @@ -209,7 +207,11 @@ export default function CodeEditor({
Leave Room
</Button>
) : (
<Button variant="default" onClick={handleOnSubmitClick}>
<Button
variant="default"
onClick={handleOnSubmitClick}
disabled={isSubmitting}
>
Submit
</Button>
)}
Expand Down

0 comments on commit 5821afc

Please sign in to comment.