From 3014116b5644af3e9724ad2f0f1a4cf1d68e6b46 Mon Sep 17 00:00:00 2001 From: marshennikovaolga Date: Fri, 6 Sep 2024 13:07:41 +0300 Subject: [PATCH] active path sidebar --- .../custom/sidebar/partial/link-section.tsx | 17 +++++++------ .../custom/sidebar/partial/page-section.tsx | 24 +++++++++++++++---- .../custom/sidebar/partial/topic-section.tsx | 16 +++++++++---- web/components/custom/sidebar/sidebar.tsx | 7 +++--- 4 files changed, 44 insertions(+), 20 deletions(-) diff --git a/web/components/custom/sidebar/partial/link-section.tsx b/web/components/custom/sidebar/partial/link-section.tsx index a3da175a..72eeb615 100644 --- a/web/components/custom/sidebar/partial/link-section.tsx +++ b/web/components/custom/sidebar/partial/link-section.tsx @@ -3,11 +3,10 @@ import Link from "next/link" import { usePathname } from "next/navigation" import { useAccount } from "@/lib/providers/jazz-provider" import { cn } from "@/lib/utils" -import { Button } from "@/components/ui/button" import { LaIcon } from "@/components/custom/la-icon" import { PersonalLinkLists } from "@/lib/schema/personal-link" -export const LinkSection: React.FC = () => { +export const LinkSection: React.FC<{ pathname: string }> = ({ pathname }) => { const { me } = useAccount({ root: { personalLinks: [] @@ -15,12 +14,13 @@ export const LinkSection: React.FC = () => { }) const linkCount = me?.root.personalLinks?.length || 0 + const isActive = pathname === "/" if (!me) return null return (
- +
) @@ -28,18 +28,22 @@ export const LinkSection: React.FC = () => { interface LinkSectionHeaderProps { linkCount: number + isActive: boolean } -const LinkSectionHeader: React.FC = ({ linkCount }) => ( +const LinkSectionHeader: React.FC = ({ linkCount, isActive }) => (

@@ -83,7 +87,6 @@ const ListItem: React.FC = ({ label, href, count, isActive }) => )} >

-

{label}

diff --git a/web/components/custom/sidebar/partial/page-section.tsx b/web/components/custom/sidebar/partial/page-section.tsx index b5064c0f..d8213c05 100644 --- a/web/components/custom/sidebar/partial/page-section.tsx +++ b/web/components/custom/sidebar/partial/page-section.tsx @@ -46,20 +46,32 @@ const SHOWS: Option[] = [ const pageSortAtom = atomWithStorage("pageSort", "title") const pageShowAtom = atomWithStorage("pageShow", 5) -export const PageSection: React.FC = () => { - const { me } = useAccount({ root: { personalPages: [] } }) +export const PageSection: React.FC<{ pathname?: string }> = ({ pathname }) => { + const { me } = useAccount({ + root: { + personalPages: [] + } + }) + + const [sort, setSort] = useAtom(pageSortAtom) + const [show, setShow] = useAtom(pageShowAtom) + const pageCount = me?.root.personalPages?.length || 0 + const isActive = pathname ? pathname.startsWith("/pages") : false + + if (!me) return null return (
- - {me?.root.personalPages && } + +
) } interface PageSectionHeaderProps { pageCount: number + isActive: boolean } const PageSectionHeader: React.FC = ({ pageCount }) => ( @@ -121,6 +133,8 @@ const NewPageButton: React.FC = () => { interface PageListProps { personalPages: PersonalPageLists + sort: SortOption + show: ShowOption } const PageList: React.FC = ({ personalPages }) => { @@ -250,4 +264,4 @@ const ShowAllForm: React.FC = () => { ) -} \ No newline at end of file +} diff --git a/web/components/custom/sidebar/partial/topic-section.tsx b/web/components/custom/sidebar/partial/topic-section.tsx index e1aaeb9b..0a2300b8 100644 --- a/web/components/custom/sidebar/partial/topic-section.tsx +++ b/web/components/custom/sidebar/partial/topic-section.tsx @@ -8,7 +8,7 @@ import { LaIcon } from "@/components/custom/la-icon" import { ListOfTopics } from "@/lib/schema" import { LEARNING_STATES, LearningStateValue } from "@/lib/constants" -export const TopicSection: React.FC = () => { +export const TopicSection: React.FC<{ pathname: string }> = ({ pathname }) => { const { me } = useAccount({ root: { topicsWantToLearn: [], @@ -22,11 +22,13 @@ export const TopicSection: React.FC = () => { (me?.root.topicsLearning?.length || 0) + (me?.root.topicsLearned?.length || 0) + const isActive = pathname.startsWith("/topics") + if (!me) return null return (
- + { interface TopicSectionHeaderProps { topicCount: number + isActive: boolean } -const TopicSectionHeader: React.FC = ({ topicCount }) => ( +const TopicSectionHeader: React.FC = ({ topicCount, isActive }) => (
) -} \ No newline at end of file +} diff --git a/web/components/custom/sidebar/sidebar.tsx b/web/components/custom/sidebar/sidebar.tsx index 893dcebb..f05afe08 100644 --- a/web/components/custom/sidebar/sidebar.tsx +++ b/web/components/custom/sidebar/sidebar.tsx @@ -109,6 +109,7 @@ const LogoAndSearch: React.FC = React.memo(() => { LogoAndSearch.displayName = "LogoAndSearch" const SidebarContent: React.FC = React.memo(() => { + const pathname = usePathname() return ( <>
- - - + + +