diff --git a/web/components/custom/sidebar/partial/link-section.tsx b/web/components/custom/sidebar/partial/link-section.tsx index 1d143b82..e4639ccc 100644 --- a/web/components/custom/sidebar/partial/link-section.tsx +++ b/web/components/custom/sidebar/partial/link-section.tsx @@ -3,8 +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 { LaIcon } from "@/components/custom/la-icon" import { PersonalLinkLists } from "@/lib/schema/personal-link" +import { useQueryState, parseAsStringLiteral } from "nuqs" +import { LEARNING_STATES } from "@/lib/constants" +import { useRouter } from "next/navigation" export const LinkSection: React.FC<{ pathname: string }> = ({ pathname }) => { const { me } = useAccount({ @@ -54,16 +56,38 @@ const LinkSectionHeader: React.FC = ({ linkCount, isActi ) +const ALL_STATES = ["all", ...LEARNING_STATES.map(ls => ls.value)] interface ListProps { personalLinks: PersonalLinkLists } const List: React.FC = ({ personalLinks }) => { const pathname = usePathname() + const [activeState] = useQueryState("state", parseAsStringLiteral(ALL_STATES)) + 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 return (
- + + +
) } @@ -78,13 +102,10 @@ interface ListItemProps { const ListItem: React.FC = ({ label, href, count, isActive }) => { return (
- {/*
+

{label}

@@ -94,7 +115,7 @@ const ListItem: React.FC = ({ label, href, count, isActive }) => {count > 0 && ( {count} )} -
*/} +
) } diff --git a/web/components/routes/link/header.tsx b/web/components/routes/link/header.tsx index 2c7c07f0..527894db 100644 --- a/web/components/routes/link/header.tsx +++ b/web/components/routes/link/header.tsx @@ -24,6 +24,11 @@ export const learningStateAtom = atom("all") export const LinkHeader = React.memo(() => { const isTablet = useMedia("(max-width: 1024px)") + const [activeState, setActiveState] = useQueryState( + "state", + parseAsStringLiteral(["all", "ToLearn", "learning", "learned"]).withDefault("all") + ) + return ( <> @@ -52,6 +57,42 @@ export const LinkHeader = React.memo(() => { LinkHeader.displayName = "LinkHeader" +// const LearningTab = React.memo(() => { +// const [activeTab, setActiveTab] = useAtom(learningStateAtom) +// const [activeState, setActiveState] = useQueryState( +// "state", +// parseAsStringLiteral(Object.values(ALL_STATES_STRING)).withDefault(ALL_STATES_STRING[0]) +// ) + +// const handleTabChange = React.useCallback( +// (value: string) => { +// setActiveTab(value) +// setActiveState(value) +// }, +// [setActiveTab, setActiveState] +// ) + +// React.useEffect(() => { +// setActiveTab(activeState) +// }, [activeState, setActiveTab]) + +// return ( +// { +// handleTabChange(value as string) +// }} +// options={ALL_STATES} +// className="bg-secondary flex rounded-lg" +// highlighterClassName="bg-secondary-foreground/10 rounded-lg" +// radioClassName={cn( +// "relative mx-2 flex h-8 cursor-pointer items-center justify-center rounded-full px-1 text-sm text-secondary-foreground/60 data-[checked]:text-secondary-foreground font-medium transition-colors focus:outline-none" +// )} +// highlighterIncludeMargin={true} +// /> +// ) +// }) + const LearningTab = React.memo(() => { const [activeTab, setActiveTab] = useAtom(learningStateAtom) const [activeState, setActiveState] = useQueryState( @@ -61,15 +102,19 @@ const LearningTab = React.memo(() => { const handleTabChange = React.useCallback( (value: string) => { - setActiveTab(value) - setActiveState(value) + if (value !== activeTab) { + setActiveTab(value) + setActiveState(value) + } }, - [setActiveTab, setActiveState] + [activeTab, setActiveTab, setActiveState] ) React.useEffect(() => { - setActiveTab(activeState) - }, [activeState, setActiveTab]) + if (activeState !== activeTab) { + setActiveTab(activeState) + } + }, [activeState, activeTab, setActiveTab]) return (