Files
archived-linsa/web/components/custom/GuideCommunityToggle.tsx
Nikita 3e7c8cf38a Q & A + journal (#174)
* tasks

* task input

* community route

* added thread and list for community QA

* answers thread

* journal sidebar section

* journal calendar

* fix: stuff

* fix: stuff

* fix: stuff

* chore: disable comunitty toggle

* fix: typo import header

---------

Co-authored-by: marshennikovaolga <marshennikova@gmail.com>
Co-authored-by: Aslam H <iupin5212@gmail.com>
2024-09-28 19:47:10 +07:00

51 lines
1.5 KiB
TypeScript

import { useState, useEffect } from "react"
import { useRouter, usePathname } from "next/navigation"
import { cn } from "@/lib/utils"
interface GuideCommunityToggleProps {
topicName: string
}
export const GuideCommunityToggle: React.FC<GuideCommunityToggleProps> = ({ topicName }) => {
const router = useRouter()
const pathname = usePathname()
const [view, setView] = useState<"guide" | "community">("guide")
useEffect(() => {
setView(pathname.includes("/community/") ? "community" : "guide")
}, [pathname])
const handleToggle = (newView: "guide" | "community") => {
setView(newView)
router.push(newView === "community" ? `/community/${topicName}` : `/${topicName}`)
}
return (
<div className="bg-accent/70 relative flex h-8 w-48 items-center rounded-md">
<div
className="absolute h-8 w-[calc(50%-4px)] rounded-md transition-all duration-300 ease-in-out"
style={{ left: view === "guide" ? "2px" : "calc(50% + 2px)" }}
/>
<button
className={cn(
"relative z-10 h-full flex-1 rounded-md text-sm font-medium transition-colors",
view === "guide" ? "text-primary bg-accent" : "text-primary/50"
)}
onClick={() => handleToggle("guide")}
>
Guide
</button>
<button
className={cn(
"relative z-10 h-full flex-1 rounded-md text-sm font-medium transition-colors",
view === "community" ? "text-primary bg-accent" : "text-primary/50"
)}
onClick={() => handleToggle("community")}
>
Community
</button>
</div>
)
}