MCPcopy
hub / github.com/aykutkardas/regexlearn.com / InteractiveArea

Function InteractiveArea

src/components/InteractiveArea.tsx:22–283  ·  view source on GitHub ↗
({ isShow, setIsOpenModal }: Props)

Source from the content-addressed store, hash-verified

20}
21
22const InteractiveArea = ({ isShow, setIsOpenModal }: Props) => {
23 const {
24 data,
25 lessonData,
26 step,
27 lastStep,
28 nextStep,
29 prevStep,
30 success,
31 setSuccess,
32 match,
33 setMatch,
34 error,
35 setError,
36 lockError,
37 } = useContext(InteractiveAreaContext);
38
39 const { formatMessage } = useIntl();
40 const regexInput = useRef<HTMLInputElement>(null);
41 const [regex, setRegex] = useState(data.initialValue || '');
42 const [flags, setFlags] = useState(data.initialFlags || '');
43 const [content, setContent] = useState('');
44 const [isChanged, setIsChanged] = useState(false);
45 const [skip, setSkip] = useState(false);
46
47 const skipStep = () => {
48 setRegex(data.regex[0]);
49 setFlags(data.flags);
50 setError(false);
51 setSuccess(true);
52 setMatch(true);
53 setSkip(true);
54 };
55
56 useEffect(() => {
57 setCaretPosition(regexInput.current, data.cursorPosition || 0);
58
59 if (lastStep > step) {
60 const newRegex = data.regex?.[0];
61 const newFlags = data.flags;
62
63 setRegex(newRegex);
64 setFlags(newFlags);
65 setSuccess(true);
66 applyRegex(newRegex, newFlags);
67
68 return;
69 }
70
71 if (step === lessonData.length - 1) {
72 confetti({
73 particleCount: 400,
74 startVelocity: 30,
75 gravity: 0.5,
76 spread: 350,
77 origin: {
78 x: 0.5,
79 y: 0.4,

Callers

nothing calls this directly

Calls 5

setCaretPositionFunction · 0.85
handleFocusFunction · 0.85
applyRegexFunction · 0.70
checkRegexFunction · 0.70
handleChangeStepFunction · 0.70

Tested by

no test coverage detected