fix captchamodal loading of captcha img

This commit is contained in:
plebeius.eth
2023-08-14 16:58:50 +02:00
parent 8f2b80e1e8
commit f4d2366b4a
2 changed files with 11 additions and 3 deletions
+10 -3
View File
@@ -20,6 +20,7 @@ const CaptchaModal = () => {
} = useGeneralStore(state => state);
const [imageSources, setImageSources] = useState([]);
const [isLoading, setIsLoading] = useState(true);
const [currentChallengeIndex, setCurrentChallengeIndex] = useState(0);
const [totalChallenges, setTotalChallenges] = useState(0);
const [isMobile, setIsMobile] = useState(window.innerWidth <= 480);
@@ -49,7 +50,8 @@ const CaptchaModal = () => {
useEffect(() => {
if (challengesArray) {
if (isCaptchaOpen && challengesArray) {
setIsLoading(true);
const challenges = challengesArray.challenges;
const decryptedChallenges = [];
@@ -61,8 +63,9 @@ const CaptchaModal = () => {
setImageSources(decryptedChallenges);
setTotalChallenges(decryptedChallenges.length);
setIsLoading(false);
}
}, [challengesArray]);
}, [challengesArray, isCaptchaOpen]);
const handleKeyDown = (event) => {
@@ -157,7 +160,11 @@ const CaptchaModal = () => {
ref={responseRef}
onKeyDown={handleKeyDown}
autoFocus />
<img src={imageSources[currentChallengeIndex]} alt="captcha" />
{isLoading ? (
<img src="" alt="loading..." style={{ visibility: "hidden" }} />
) : (
imageSources[currentChallengeIndex] && <img src={imageSources[currentChallengeIndex]} alt="captcha" />
)}
</div>
<div>
<span style={{lineHeight: '1.7'}}>
@@ -58,6 +58,7 @@ export const StyledModal = styled(Modal)`
position: relative;
clear: both;
width: 302px;
height: 100px;
overflow: hidden;
margin-bottom: 3px;
}