Skip to content

Commit 1b6ee4e

Browse files
committed
fix: on paste error validation
1 parent 9e3fb78 commit 1b6ee4e

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

ui/components/app/srp-input-import/srp-input-import.tsx

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,23 @@ export default function SrpInputImport({
6060

6161
const srpRefs = useRef<ListOfTextFieldRefs>({});
6262

63-
const checkForInvalidWords = useCallback(() => {
64-
draftSrp.forEach((word) => {
65-
const isInWordlist = wordlist.includes(word.word);
66-
const alreadyInMisspelled = misSpelledWords.some((w) => w.id === word.id);
67-
if (isInWordlist && alreadyInMisspelled) {
68-
setMisSpelledWords((prev) => prev.filter((w) => w.id !== word.id));
69-
} else if (!isInWordlist && !alreadyInMisspelled && word.word !== '') {
70-
setMisSpelledWords((prev) => [...prev, word]);
71-
}
72-
});
73-
}, [draftSrp, misSpelledWords]);
63+
const checkForInvalidWords = useCallback(
64+
(srp?: DraftSrp[]) => {
65+
const draftSrpToCheck = srp ?? draftSrp;
66+
draftSrpToCheck.forEach((word) => {
67+
const isInWordlist = wordlist.includes(word.word);
68+
const alreadyInMisspelled = misSpelledWords.some(
69+
(w) => w.id === word.id,
70+
);
71+
if (isInWordlist && alreadyInMisspelled) {
72+
setMisSpelledWords((prev) => prev.filter((w) => w.id !== word.id));
73+
} else if (!isInWordlist && !alreadyInMisspelled && word.word !== '') {
74+
setMisSpelledWords((prev) => [...prev, word]);
75+
}
76+
});
77+
},
78+
[draftSrp, misSpelledWords],
79+
);
7480

7581
const initializeSrp = () => {
7682
const firstWordId = uuidv4();
@@ -109,6 +115,7 @@ export default function SrpInputImport({
109115
});
110116
}
111117

118+
checkForInvalidWords(newDraftSrp);
112119
setDraftSrp(newDraftSrp);
113120
};
114121

0 commit comments

Comments
 (0)