From 6ebc2f300eadc85ff05d9a12817265e5d8acdeb4 Mon Sep 17 00:00:00 2001 From: Ashhhleyyy Date: Tue, 26 Jul 2022 22:03:00 +0100 Subject: [PATCH] fix: lock transcribe fields when submitting --- pages/comic/[comic]/transcribe/[page].tsx | 26 ++++++++++++++--------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/pages/comic/[comic]/transcribe/[page].tsx b/pages/comic/[comic]/transcribe/[page].tsx index 75ee567..3467687 100644 --- a/pages/comic/[comic]/transcribe/[page].tsx +++ b/pages/comic/[comic]/transcribe/[page].tsx @@ -65,6 +65,7 @@ export default function TranscribePage(props: Props) { const [indicateNumbers, setIndicateNumbers] = useState(false); const [lockAreas, setLockAreas] = useState(false); const [selectedBubble, setSelectedBubble] = useState(-1); + const [saving, setSaving] = useState(false); const extractText = useCallback(() => { if (image && regions.length > 0) { @@ -94,6 +95,7 @@ export default function TranscribePage(props: Props) { }, [props.characters]); async function submitBubbles() { + setSaving(true); const res = await fetch('/api/submit-page-bubbles', { method: 'PUT', headers: { @@ -139,11 +141,10 @@ export default function TranscribePage(props: Props) { pageId: props.page.id, }), }); - if (res.ok) { - console.log('submitted!'); - } else { - console.log('failed to submit:', res.status, res.statusText); + if (!res.ok) { + alert(`failed to submit: ${res.status}, ${res.statusText}`); } + setSaving(false); } return ( @@ -218,7 +219,7 @@ export default function TranscribePage(props: Props) { r.area)} onChange={(areas) => - !lockAreas && + !lockAreas && !saving && setRegions( areas.map((area, i) => { if (i < regions.length) { @@ -239,13 +240,13 @@ export default function TranscribePage(props: Props) { } globalAreaStyle={{ border: `1.5px dashed ${randomColour( - props.page.comic.id, + props.page.id, 0.3, 0.49, 0.5 )}`, backgroundColor: randomColour( - props.page.comic.id, + props.page.id, undefined, undefined, 0.5 @@ -268,12 +269,13 @@ export default function TranscribePage(props: Props) {
- +