MCPcopy Create free account
hub / github.com/code100x/daily-code / ProfileOptions

Function ProfileOptions

apps/web/components/profile/ProfileOptions.tsx:6–51  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4import { useEffect, useState } from "react";
5
6const ProfileOptions = () => {
7 const optionsData = [
8 {
9 name: "Profile",
10 icon: <UserRound color="#3b82f6" size={18} />,
11 href: "/profile",
12 },
13 {
14 name: "Submissions",
15 icon: <Braces color="#3b82f6" size={18} />,
16 href: "/profile/submissions",
17 },
18 ];
19 const router = useRouter();
20 const pathname = usePathname();
21 const [activeOption, setActiveOption] = useState<Number | null>(() => {
22 return pathname === "/profile" ? 0 : null;
23 });
24
25 useEffect(() => {
26 const currentPath = pathname;
27 const activeIndex = optionsData.findIndex((option) => option.href === currentPath);
28 setActiveOption(activeIndex);
29 }, [pathname, optionsData]);
30
31 const handleOptionClick = (index: number, href: string) => {
32 setActiveOption(index);
33 router.push(href);
34 };
35 return (
36 <div className="flex gap-2 flex-col px-2 !max-h-[80%] overflow-y-auto w-full">
37 {optionsData.map((x, i) => {
38 return (
39 <div
40 onClick={() => handleOptionClick(i, x.href)}
41 className={` ${activeOption === i ? "border-r-8 border-blue-500 dark:bg-[#ffffff1d] bg-[#2020204d]" : ""} cursor-pointer hover:bg-[#ffffff1f] flex items-center gap-2 rounded-md p-2 `}
42 key={i}
43 >
44 <span>{x.icon}</span>
45 <span>{x.name}</span>
46 </div>
47 );
48 })}
49 </div>
50 );
51};
52
53export default ProfileOptions;

Callers

nothing calls this directly

Calls 1

handleOptionClickFunction · 0.85

Tested by

no test coverage detected