Skip to content

Commit

Permalink
Merge pull request #3 from sora32127/fix_continuos_posting_error
Browse files Browse the repository at this point in the history
Fix Continuous Posting Error
  • Loading branch information
sora32127 authored Mar 8, 2024
2 parents d4c292e + 6780749 commit 62a51f7
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/SubmitContentBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const SubmitContentBox: React.FC<SubmitContentBoxProps> = ({
}) => {
const [showModal, setShowModal] = useState(false);
const [isValidUser, setIsValidUser] = useState(false);
const [isSubmitting, setIsSubmitting] = useState(false);

const handleTurnstileValidation = (isValid: boolean) => {
setIsValidUser(isValid);
Expand All @@ -40,6 +41,7 @@ const SubmitContentBox: React.FC<SubmitContentBoxProps> = ({


const handleSubmit = async () => {
setIsSubmitting(true);
try {
const response = await fetch("/maketext", {
method: 'POST',
Expand Down Expand Up @@ -71,6 +73,9 @@ const SubmitContentBox: React.FC<SubmitContentBoxProps> = ({
} catch (error) {
console.error('投稿エラー:', error);
alert('投稿中にエラーが発生しました。');
} finally {
setIsSubmitting(false);
setShowModal(false);
}
};

Expand All @@ -79,7 +84,7 @@ const SubmitContentBox: React.FC<SubmitContentBoxProps> = ({
<div className="checkbox mb-3">
<Turnstile siteKey={VITE_CF_TURNSTILE_SITEKEY} onSuccess={() => handleTurnstileValidation(true)} />
</div>
<Button className='submitButton' disabled = {!isValidUser || !isValid} variant="primary" onClick={() => setShowModal(true)}>
<Button className='submitButton' disabled={!isValidUser || !isValid || isSubmitting} variant="primary" onClick={() => setShowModal(true)}>
投稿する
</Button>
<Modal show={showModal} onHide={() => setShowModal(false)}>
Expand All @@ -88,16 +93,15 @@ const SubmitContentBox: React.FC<SubmitContentBoxProps> = ({
</Modal.Header>
<Modal.Body>本当に投稿しますか?</Modal.Body>
<Modal.Footer>
<Button variant="secondary" onClick={() => setShowModal(false)}>
<Button variant="secondary" onClick={() => setShowModal(false)} disabled={isSubmitting}>
戻る
</Button>
<Button variant="primary" onClick={handleSubmit}>
投稿する
<Button variant="primary" onClick={handleSubmit} disabled={isSubmitting}>
{isSubmitting ? '投稿中...' : '投稿する'}
</Button>
</Modal.Footer>
</Modal>
</div>
);
};

export default SubmitContentBox;

0 comments on commit 62a51f7

Please sign in to comment.