import React from "react"
import Link from "next/link"
import { usePathname } from "next/navigation"
import { useAccount } from "@/lib/providers/jazz-provider"
import { cn } from "@/lib/utils"
import { PersonalLinkLists } from "@/lib/schema/personal-link"
import { useQueryState, parseAsStringLiteral } from "nuqs"
import { LEARNING_STATES } from "@/lib/constants"
export const LinkSection: React.FC<{ pathname: string }> = ({ pathname }) => {
const { me } = useAccount({
root: {
personalLinks: []
}
})
const linkCount = me?.root.personalLinks?.length || 0
const isActive = pathname === "/links"
if (!me) return null
return (
)
}
interface LinkSectionHeaderProps {
linkCount: number
isActive: boolean
}
const LinkSectionHeader: React.FC = ({ linkCount, isActive }) => (
Links
{linkCount > 0 && {linkCount}}
)
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 (
)
}
interface ListItemProps {
label: string
href: string
count: number
isActive: boolean
}
const ListItem: React.FC = ({ label, href, count, isActive }) => {
return (
{count > 0 && (
{count}
)}
)
}