From 6f77158aacb56b3e4e48447b2d836c1c851355c2 Mon Sep 17 00:00:00 2001 From: marshennikovaolga Date: Mon, 9 Sep 2024 20:48:29 +0300 Subject: [PATCH] link isActive sidebar --- .../custom/sidebar/partial/link-section.tsx | 77 ++++++++++--------- 1 file changed, 39 insertions(+), 38 deletions(-) diff --git a/web/components/custom/sidebar/partial/link-section.tsx b/web/components/custom/sidebar/partial/link-section.tsx index 46a6e359..0ac854aa 100644 --- a/web/components/custom/sidebar/partial/link-section.tsx +++ b/web/components/custom/sidebar/partial/link-section.tsx @@ -1,6 +1,6 @@ import React from "react" import Link from "next/link" -import { usePathname } from "next/navigation" +import { usePathname, useRouter } from "next/navigation" import { useAccount } from "@/lib/providers/jazz-provider" import { cn } from "@/lib/utils" import { PersonalLinkLists } from "@/lib/schema/personal-link" @@ -32,28 +32,31 @@ interface LinkSectionHeaderProps { isActive: boolean } -const LinkSectionHeader: React.FC = ({ linkCount, isActive }) => ( -
- -

- Links - {linkCount > 0 && {linkCount}} -

- -
-) +const LinkSectionHeader: React.FC = ({ linkCount, isActive }) => { + const pathname = usePathname() + const [state] = useQueryState("state", parseAsStringLiteral(LEARNING_STATES.map(ls => ls.value))) + const isLinksActive = pathname.startsWith("/links") && !state + + return ( +
+ +

+ Links + {linkCount > 0 && {linkCount}} +

+ +
+ ) +} const ALL_STATES = ["all", ...LEARNING_STATES.map(ls => ls.value)] interface ListProps { @@ -62,31 +65,26 @@ interface ListProps { const List: React.FC = ({ personalLinks }) => { const pathname = usePathname() - const [activeState] = useQueryState("state", parseAsStringLiteral(ALL_STATES)) + const [state] = useQueryState("state", parseAsStringLiteral(LEARNING_STATES.map(ls => ls.value))) + const toLearnCount = personalLinks.filter(link => link?.learningState === "wantToLearn").length const learningCount = personalLinks.filter(link => link?.learningState === "learning").length const learnedCount = personalLinks.filter(link => link?.learningState === "learned").length + const isActive = (checkState: string) => { + return pathname === "/links" && state === checkState + } + return (
- - + +
) } @@ -104,7 +102,10 @@ const ListItem: React.FC = ({ label, href, count, isActive }) =>

{label}