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

Function LearnProgress

src/components/LearnProgress.tsx:9–125  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

7import { useLanguageDirection } from "src/utils/useLanguageDirection";
8
9const LearnProgress = () => {
10 const [open, setOpen] = useState(false);
11 const learnProgressRef = useRef<HTMLDivElement>(null);
12 const { formatMessage } = useIntl();
13 const { lessonData, step, setStep, lastStep, updateStorage } = useContext(InteractiveAreaContext);
14
15 useEffect(() => {
16 const activeitem = [...document.querySelectorAll('.step-item')][step];
17 if (!activeitem) return;
18 const topPos = (activeitem as HTMLDivElement).offsetTop;
19 learnProgressRef.current.scrollTop = topPos - 153;
20 }, [step]);
21
22 const handleChangeStep = (step: number) => {
23 if (step > lastStep) return;
24
25 updateStorage(step);
26 setStep(step);
27 };
28
29 const toggleProgress = () => setOpen(!open);
30
31 const direction = useLanguageDirection();
32
33 // list lesson (ToggleProgress For RTL/LTR)
34 const listOpen = direction === 'rtl' ? 'left-0' : 'right-0';
35 const listClose = direction === 'rtl' ? '-left-[244px]' : '-right-[244px]';
36 const listOpenInner = direction === 'rtl' ? '-left-10' : '-right-10';
37 const listCloseInner = direction === 'rtl' ? 'left-[204px]' : 'right-[204px]';
38 const listIconName = direction === 'rtl' ? 'arrow-right' : 'arrow-left';
39
40 return (
41 <div
42 className={clsx(
43 'hidden lg:block text-xs top-[50%] -translate-y-[50%] absolute z-10 transition-all select-none',
44 open ? listOpen : listClose,
45 )}
46 >
47 <div
48 ref={learnProgressRef}
49 className="hidden-scrollbar scroll-smooth pl-5 bg-[#282c34] rounded-2xl shadow-2xl shadow-[#282c34] relative w-56 overflow-y-scroll overflow-x-hidden py-10 h-[320px]"
50 >
51 <div
52 onClick={toggleProgress}
53 className={clsx(
54 direction === 'rtl' ? 'translate-x-[50%]' : '-translate-x-[50%]',
55 `w-10 h-10 cursor-pointer rounded-full flex fixed top-[50%] transition-all duration-50`,
56 open ? `${listOpenInner} bg-neutral-600/40` : `${listCloseInner} bg-emerald-600`,
57 )}
58 >
59 <Icon
60 icon={listIconName}
61 size={15}
62 className={clsx(
63 direction === 'rtl' ? 'ml-auto mr-1' : 'mr-auto ml-1',
64 `my-auto text-neutral-100`,
65 open ? 'rotate-180' : 'rotate-0',
66 )}

Callers

nothing calls this directly

Calls 2

useLanguageDirectionFunction · 0.90
handleChangeStepFunction · 0.70

Tested by

no test coverage detected