mirror of
https://github.com/linsa-io/linsa.git
synced 2026-01-12 12:20:23 +01:00
fix: topic for guest auth (#149)
* wip * chore: redirect instead of toast * refactor: remove useRouter
This commit is contained in:
@@ -6,7 +6,6 @@ import { cn } from "@/lib/utils"
|
|||||||
import { PersonalLinkLists } from "@/lib/schema/personal-link"
|
import { PersonalLinkLists } from "@/lib/schema/personal-link"
|
||||||
import { useQueryState, parseAsStringLiteral } from "nuqs"
|
import { useQueryState, parseAsStringLiteral } from "nuqs"
|
||||||
import { LEARNING_STATES } from "@/lib/constants"
|
import { LEARNING_STATES } from "@/lib/constants"
|
||||||
import { useRouter } from "next/navigation"
|
|
||||||
|
|
||||||
export const LinkSection: React.FC<{ pathname: string }> = ({ pathname }) => {
|
export const LinkSection: React.FC<{ pathname: string }> = ({ pathname }) => {
|
||||||
const { me } = useAccount({
|
const { me } = useAccount({
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { useAccount } from "@/lib/providers/jazz-provider"
|
import { LaIcon } from "@/components/custom/la-icon"
|
||||||
import { LaIcon } from "../../la-icon"
|
|
||||||
import { useState } from "react"
|
import { useState } from "react"
|
||||||
import { useAuth } from "@clerk/nextjs"
|
import { SignInButton, useAuth, useUser } from "@clerk/nextjs"
|
||||||
import {
|
import {
|
||||||
DropdownMenu,
|
DropdownMenu,
|
||||||
DropdownMenuContent,
|
DropdownMenuContent,
|
||||||
@@ -11,97 +10,68 @@ import {
|
|||||||
} from "@/components/ui/dropdown-menu"
|
} from "@/components/ui/dropdown-menu"
|
||||||
import { Avatar, AvatarImage } from "@/components/ui/avatar"
|
import { Avatar, AvatarImage } from "@/components/ui/avatar"
|
||||||
import Link from "next/link"
|
import Link from "next/link"
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import { usePathname } from "next/navigation"
|
||||||
|
|
||||||
const MenuItem = ({
|
export const ProfileSection: React.FC = () => {
|
||||||
icon,
|
const { user, isSignedIn } = useUser()
|
||||||
text,
|
const { signOut } = useAuth()
|
||||||
href,
|
const [menuOpen, setMenuOpen] = useState(false)
|
||||||
onClick,
|
const pathname = usePathname()
|
||||||
onClose
|
|
||||||
}: {
|
if (!isSignedIn) {
|
||||||
icon: string
|
return (
|
||||||
text: string
|
<div className="flex flex-col gap-px border-t border-transparent px-3 py-2 pb-3 pt-1.5">
|
||||||
href?: string
|
<SignInButton mode="modal" forceRedirectUrl={pathname}>
|
||||||
onClick?: () => void
|
<Button variant="outline" className="flex w-full items-center gap-2">
|
||||||
onClose: () => void
|
<LaIcon name="LogIn" />
|
||||||
}) => {
|
Sign in
|
||||||
const handleClick = () => {
|
</Button>
|
||||||
onClose()
|
</SignInButton>
|
||||||
if (onClick) {
|
</div>
|
||||||
onClick()
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="relative flex flex-1 items-center gap-2">
|
<div className="flex flex-col gap-px border-t border-transparent px-3 py-2 pb-3 pt-1.5">
|
||||||
<LaIcon name={icon as any} />
|
|
||||||
{href ? (
|
|
||||||
<Link href={href} onClick={onClose}>
|
|
||||||
<span className="line-clamp-1 flex-1">{text}</span>
|
|
||||||
</Link>
|
|
||||||
) : (
|
|
||||||
<span className="line-clamp-1 flex-1" onClick={handleClick}>
|
|
||||||
{text}
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
export const ProfileSection: React.FC = () => {
|
|
||||||
const { me } = useAccount({
|
|
||||||
profile: true
|
|
||||||
})
|
|
||||||
const { signOut, isSignedIn } = useAuth()
|
|
||||||
const [menuOpen, setMenuOpen] = useState(false)
|
|
||||||
|
|
||||||
const closeMenu = () => setMenuOpen(false)
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="visible absolute inset-x-0 bottom-0 z-10 flex gap-8 p-2.5">
|
|
||||||
<div className="flex h-10 min-w-full items-center">
|
<div className="flex h-10 min-w-full items-center">
|
||||||
<div className="flex min-w-0">
|
<div className="flex min-w-0">
|
||||||
<DropdownMenu open={menuOpen} onOpenChange={setMenuOpen}>
|
<DropdownMenu open={menuOpen} onOpenChange={setMenuOpen}>
|
||||||
<DropdownMenuTrigger asChild>
|
<DropdownMenuTrigger asChild>
|
||||||
<button
|
<Button
|
||||||
|
variant="ghost"
|
||||||
aria-label="Profile"
|
aria-label="Profile"
|
||||||
className="hover:bg-accent focus-visible:ring-ring hover:text-accent-foreground flex items-center gap-1.5 truncate rounded pl-1 pr-1.5 focus-visible:outline-none focus-visible:ring-1"
|
className="hover:bg-accent focus-visible:ring-ring hover:text-accent-foreground flex h-auto items-center gap-1.5 truncate rounded py-1 pl-1 pr-1.5 focus-visible:outline-none focus-visible:ring-1"
|
||||||
>
|
>
|
||||||
{isSignedIn ? (
|
<Avatar className="size-6">
|
||||||
<Avatar className="size-6">
|
<AvatarImage src={user.imageUrl} alt={user.fullName || ""} />
|
||||||
<AvatarImage src="https://github.com/shadcn.png" alt="@shadcn" />
|
</Avatar>
|
||||||
</Avatar>
|
<span className="truncate text-left text-sm font-medium -tracking-wider">{user.fullName}</span>
|
||||||
) : (
|
|
||||||
<LaIcon name="User" />
|
|
||||||
)}
|
|
||||||
<span className="truncate text-left text-sm font-medium -tracking-wider">
|
|
||||||
{isSignedIn ? me?.profile?.name : "guest"}
|
|
||||||
</span>
|
|
||||||
<LaIcon
|
<LaIcon
|
||||||
name="ChevronDown"
|
name="ChevronDown"
|
||||||
className={`size-4 shrink-0 transition-transform duration-300 ${menuOpen ? "rotate-180" : ""}`}
|
className={cn("size-4 shrink-0 transition-transform duration-300", {
|
||||||
|
"rotate-180": menuOpen
|
||||||
|
})}
|
||||||
/>
|
/>
|
||||||
</button>
|
</Button>
|
||||||
</DropdownMenuTrigger>
|
</DropdownMenuTrigger>
|
||||||
<DropdownMenuContent className="w-56" align="start" side="top">
|
<DropdownMenuContent className="w-56" align="start" side="top">
|
||||||
{isSignedIn ? (
|
<DropdownMenuItem asChild>
|
||||||
<>
|
<Link href="/profile">
|
||||||
<DropdownMenuItem>
|
<div className="relative flex flex-1 items-center gap-2">
|
||||||
<MenuItem icon="CircleUser" text="My profile" href="/profile" onClose={closeMenu} />
|
<LaIcon name="CircleUser" />
|
||||||
</DropdownMenuItem>
|
<span className="line-clamp-1 flex-1">My profile</span>
|
||||||
<DropdownMenuSeparator />
|
</div>
|
||||||
<DropdownMenuItem>
|
</Link>
|
||||||
<MenuItem icon="LogOut" text="Log out" onClick={signOut} onClose={closeMenu} />
|
</DropdownMenuItem>
|
||||||
</DropdownMenuItem>
|
<DropdownMenuSeparator />
|
||||||
<DropdownMenuSeparator />
|
<DropdownMenuItem onClick={() => signOut()}>
|
||||||
<DropdownMenuItem>
|
<div className="relative flex flex-1 items-center gap-2">
|
||||||
<MenuItem icon="CircleUser" text="Tauri" href="/tauri" onClose={closeMenu} />
|
<LaIcon name="LogOut" />
|
||||||
</DropdownMenuItem>
|
<span className="line-clamp-1 flex-1">Log out</span>
|
||||||
</>
|
</div>
|
||||||
) : (
|
</DropdownMenuItem>
|
||||||
<DropdownMenuItem>
|
|
||||||
<MenuItem icon="LogIn" text="Sign in" href="/sign-in" onClose={closeMenu} />
|
|
||||||
</DropdownMenuItem>
|
|
||||||
)}
|
|
||||||
</DropdownMenuContent>
|
</DropdownMenuContent>
|
||||||
</DropdownMenu>
|
</DropdownMenu>
|
||||||
</div>
|
</div>
|
||||||
@@ -109,7 +79,3 @@ export const ProfileSection: React.FC = () => {
|
|||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* <DropdownMenuItem>
|
|
||||||
<MenuItem icon="Settings" text="Settings" href="/settings" onClose={closeMenu} />
|
|
||||||
</DropdownMenuItem> */
|
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import { PageSection } from "./partial/page-section"
|
|||||||
import { TopicSection } from "./partial/topic-section"
|
import { TopicSection } from "./partial/topic-section"
|
||||||
import { ProfileSection } from "./partial/profile-section"
|
import { ProfileSection } from "./partial/profile-section"
|
||||||
import { useAccountOrGuest } from "@/lib/providers/jazz-provider"
|
import { useAccountOrGuest } from "@/lib/providers/jazz-provider"
|
||||||
import { SignInButton } from "@clerk/nextjs"
|
|
||||||
|
|
||||||
interface SidebarContextType {
|
interface SidebarContextType {
|
||||||
isCollapsed: boolean
|
isCollapsed: boolean
|
||||||
@@ -126,15 +125,9 @@ const SidebarContent: React.FC = React.memo(() => {
|
|||||||
{me._type === "Account" && <PageSection pathname={pathname} />}
|
{me._type === "Account" && <PageSection pathname={pathname} />}
|
||||||
{me._type === "Account" && <TopicSection pathname={pathname} />}
|
{me._type === "Account" && <TopicSection pathname={pathname} />}
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
|
||||||
|
|
||||||
{me._type === "Account" ? (
|
|
||||||
<ProfileSection />
|
<ProfileSection />
|
||||||
) : (
|
</nav>
|
||||||
<div className="visible absolute inset-x-0 bottom-0 z-10 flex gap-8 p-2.5">
|
|
||||||
<SignInButton>Fake profile section</SignInButton>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -6,13 +6,16 @@ import { ListOfTopics, Topic } from "@/lib/schema"
|
|||||||
import { LearningStateSelector } from "@/components/custom/learning-state-selector"
|
import { LearningStateSelector } from "@/components/custom/learning-state-selector"
|
||||||
import { useAccountOrGuest } from "@/lib/providers/jazz-provider"
|
import { useAccountOrGuest } from "@/lib/providers/jazz-provider"
|
||||||
import { LearningStateValue } from "@/lib/constants"
|
import { LearningStateValue } from "@/lib/constants"
|
||||||
import { toast } from "sonner"
|
import { useClerk } from "@clerk/nextjs"
|
||||||
|
import { usePathname } from "next/navigation"
|
||||||
|
|
||||||
interface TopicDetailHeaderProps {
|
interface TopicDetailHeaderProps {
|
||||||
topic: Topic
|
topic: Topic
|
||||||
}
|
}
|
||||||
|
|
||||||
export const TopicDetailHeader = React.memo(function TopicDetailHeader({ topic }: TopicDetailHeaderProps) {
|
export const TopicDetailHeader = React.memo(function TopicDetailHeader({ topic }: TopicDetailHeaderProps) {
|
||||||
|
const clerk = useClerk()
|
||||||
|
const pathname = usePathname()
|
||||||
const { me } = useAccountOrGuest({
|
const { me } = useAccountOrGuest({
|
||||||
root: {
|
root: {
|
||||||
topicsWantToLearn: [],
|
topicsWantToLearn: [],
|
||||||
@@ -32,7 +35,6 @@ export const TopicDetailHeader = React.memo(function TopicDetailHeader({ topic }
|
|||||||
if (wantToLearnIndex !== -1) {
|
if (wantToLearnIndex !== -1) {
|
||||||
p = {
|
p = {
|
||||||
index: wantToLearnIndex,
|
index: wantToLearnIndex,
|
||||||
// TODO: fix this type error by doing better conditionals on both index and p
|
|
||||||
topic: me && me._type !== "Anonymous" ? me.root.topicsWantToLearn[wantToLearnIndex] : undefined,
|
topic: me && me._type !== "Anonymous" ? me.root.topicsWantToLearn[wantToLearnIndex] : undefined,
|
||||||
learningState: "wantToLearn"
|
learningState: "wantToLearn"
|
||||||
}
|
}
|
||||||
@@ -60,9 +62,9 @@ export const TopicDetailHeader = React.memo(function TopicDetailHeader({ topic }
|
|||||||
|
|
||||||
const handleAddToProfile = (learningState: LearningStateValue) => {
|
const handleAddToProfile = (learningState: LearningStateValue) => {
|
||||||
if (me?._type === "Anonymous") {
|
if (me?._type === "Anonymous") {
|
||||||
// TODO: handle better
|
return clerk.redirectToSignIn({
|
||||||
toast.error("You need to sign in to add links to your personal list.")
|
redirectUrl: pathname
|
||||||
return
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const topicLists: Record<LearningStateValue, (ListOfTopics | null) | undefined> = {
|
const topicLists: Record<LearningStateValue, (ListOfTopics | null) | undefined> = {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import React, { useCallback, useMemo, useState } from "react"
|
import React, { useCallback, useMemo, useState } from "react"
|
||||||
import Link from "next/link"
|
import Link from "next/link"
|
||||||
import { useRouter } from "next/navigation"
|
import { usePathname, useRouter } from "next/navigation"
|
||||||
import { useAtom } from "jotai"
|
import { useAtom } from "jotai"
|
||||||
import { toast } from "sonner"
|
import { toast } from "sonner"
|
||||||
|
|
||||||
@@ -10,10 +10,11 @@ import { Button } from "@/components/ui/button"
|
|||||||
import { LearningStateSelectorContent } from "@/components/custom/learning-state-selector"
|
import { LearningStateSelectorContent } from "@/components/custom/learning-state-selector"
|
||||||
|
|
||||||
import { cn, ensureUrlProtocol, generateUniqueSlug } from "@/lib/utils"
|
import { cn, ensureUrlProtocol, generateUniqueSlug } from "@/lib/utils"
|
||||||
import { LaAccount, Link as LinkSchema, PersonalLink, PersonalLinkLists, Topic, UserRoot } from "@/lib/schema"
|
import { Link as LinkSchema, PersonalLink, Topic } from "@/lib/schema"
|
||||||
import { openPopoverForIdAtom } from "../TopicDetailRoute"
|
import { openPopoverForIdAtom } from "../TopicDetailRoute"
|
||||||
import { LEARNING_STATES, LearningStateValue } from "@/lib/constants"
|
import { LEARNING_STATES, LearningStateValue } from "@/lib/constants"
|
||||||
import { useAccountOrGuest } from "@/lib/providers/jazz-provider"
|
import { useAccountOrGuest } from "@/lib/providers/jazz-provider"
|
||||||
|
import { useClerk } from "@clerk/nextjs"
|
||||||
|
|
||||||
interface LinkItemProps {
|
interface LinkItemProps {
|
||||||
topic: Topic
|
topic: Topic
|
||||||
@@ -24,185 +25,183 @@ interface LinkItemProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const LinkItem = React.memo(
|
export const LinkItem = React.memo(
|
||||||
React.forwardRef<HTMLLIElement, LinkItemProps>(
|
React.forwardRef<HTMLLIElement, LinkItemProps>(({ topic, link, isActive, index, setActiveIndex }, ref) => {
|
||||||
({ topic, link, isActive, index, setActiveIndex }, ref) => {
|
const clerk = useClerk()
|
||||||
const router = useRouter()
|
const pathname = usePathname()
|
||||||
const [, setOpenPopoverForId] = useAtom(openPopoverForIdAtom)
|
const router = useRouter()
|
||||||
const [isPopoverOpen, setIsPopoverOpen] = useState(false)
|
const [, setOpenPopoverForId] = useAtom(openPopoverForIdAtom)
|
||||||
|
const [isPopoverOpen, setIsPopoverOpen] = useState(false)
|
||||||
|
|
||||||
const { me } = useAccountOrGuest({ root: { personalLinks: [] } });
|
const { me } = useAccountOrGuest({ root: { personalLinks: [] } })
|
||||||
|
|
||||||
const personalLinks = useMemo(() => {
|
const personalLinks = useMemo(() => {
|
||||||
if (!me || me._type === "Anonymous") return undefined;
|
if (!me || me._type === "Anonymous") return undefined
|
||||||
return me?.root?.personalLinks || []
|
return me?.root?.personalLinks || []
|
||||||
}, [me])
|
}, [me])
|
||||||
|
|
||||||
const personalLink = useMemo(() => {
|
const personalLink = useMemo(() => {
|
||||||
return personalLinks?.find(pl => pl?.link?.id === link.id)
|
return personalLinks?.find(pl => pl?.link?.id === link.id)
|
||||||
}, [personalLinks, link.id])
|
}, [personalLinks, link.id])
|
||||||
|
|
||||||
const selectedLearningState = useMemo(() => {
|
const selectedLearningState = useMemo(() => {
|
||||||
return LEARNING_STATES.find(ls => ls.value === personalLink?.learningState)
|
return LEARNING_STATES.find(ls => ls.value === personalLink?.learningState)
|
||||||
}, [personalLink?.learningState])
|
}, [personalLink?.learningState])
|
||||||
|
|
||||||
const handleClick = useCallback(
|
const handleClick = useCallback(
|
||||||
(e: React.MouseEvent) => {
|
(e: React.MouseEvent) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
setActiveIndex(index)
|
setActiveIndex(index)
|
||||||
},
|
},
|
||||||
[index, setActiveIndex]
|
[index, setActiveIndex]
|
||||||
)
|
)
|
||||||
|
|
||||||
const handleSelectLearningState = useCallback(
|
const handleSelectLearningState = useCallback(
|
||||||
(learningState: LearningStateValue) => {
|
(learningState: LearningStateValue) => {
|
||||||
if (!personalLinks || !me || me?._type === "Anonymous") {
|
if (!personalLinks || !me || me?._type === "Anonymous") {
|
||||||
if (me?._type === "Anonymous") {
|
return clerk.redirectToSignIn({
|
||||||
// TODO: handle better
|
redirectUrl: pathname
|
||||||
toast.error("You need to sign in to add links to your personal list.")
|
})
|
||||||
}
|
}
|
||||||
return
|
|
||||||
};
|
|
||||||
|
|
||||||
const defaultToast = {
|
const defaultToast = {
|
||||||
duration: 5000,
|
duration: 5000,
|
||||||
position: "bottom-right" as const,
|
position: "bottom-right" as const,
|
||||||
closeButton: true,
|
closeButton: true,
|
||||||
action: {
|
action: {
|
||||||
label: "Go to list",
|
label: "Go to list",
|
||||||
onClick: () => router.push("/")
|
onClick: () => router.push("/")
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (personalLink) {
|
if (personalLink) {
|
||||||
if (personalLink.learningState === learningState) {
|
if (personalLink.learningState === learningState) {
|
||||||
personalLink.learningState = undefined
|
personalLink.learningState = undefined
|
||||||
toast.error("Link learning state removed", defaultToast)
|
toast.error("Link learning state removed", defaultToast)
|
||||||
} else {
|
|
||||||
personalLink.learningState = learningState
|
|
||||||
toast.success("Link learning state updated", defaultToast)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
const slug = generateUniqueSlug(personalLinks.toJSON(), link.title)
|
personalLink.learningState = learningState
|
||||||
const newPersonalLink = PersonalLink.create(
|
toast.success("Link learning state updated", defaultToast)
|
||||||
{
|
|
||||||
url: link.url,
|
|
||||||
title: link.title,
|
|
||||||
slug,
|
|
||||||
link,
|
|
||||||
learningState,
|
|
||||||
sequence: personalLinks.length + 1,
|
|
||||||
completed: false,
|
|
||||||
topic,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date()
|
|
||||||
},
|
|
||||||
{ owner: me }
|
|
||||||
)
|
|
||||||
|
|
||||||
personalLinks.push(newPersonalLink)
|
|
||||||
|
|
||||||
toast.success("Link added.", {
|
|
||||||
...defaultToast,
|
|
||||||
description: `${link.title} has been added to your personal link.`
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
const slug = generateUniqueSlug(personalLinks.toJSON(), link.title)
|
||||||
|
const newPersonalLink = PersonalLink.create(
|
||||||
|
{
|
||||||
|
url: link.url,
|
||||||
|
title: link.title,
|
||||||
|
slug,
|
||||||
|
link,
|
||||||
|
learningState,
|
||||||
|
sequence: personalLinks.length + 1,
|
||||||
|
completed: false,
|
||||||
|
topic,
|
||||||
|
createdAt: new Date(),
|
||||||
|
updatedAt: new Date()
|
||||||
|
},
|
||||||
|
{ owner: me }
|
||||||
|
)
|
||||||
|
|
||||||
setOpenPopoverForId(null)
|
personalLinks.push(newPersonalLink)
|
||||||
setIsPopoverOpen(false)
|
|
||||||
},
|
|
||||||
[personalLink, personalLinks, me, link, router, setOpenPopoverForId, topic]
|
|
||||||
)
|
|
||||||
|
|
||||||
const handlePopoverOpenChange = useCallback(
|
toast.success("Link added.", {
|
||||||
(open: boolean) => {
|
...defaultToast,
|
||||||
setIsPopoverOpen(open)
|
description: `${link.title} has been added to your personal link.`
|
||||||
setOpenPopoverForId(open ? link.id : null)
|
})
|
||||||
},
|
}
|
||||||
[link.id, setOpenPopoverForId]
|
|
||||||
)
|
|
||||||
|
|
||||||
return (
|
setOpenPopoverForId(null)
|
||||||
<li
|
setIsPopoverOpen(false)
|
||||||
ref={ref}
|
},
|
||||||
tabIndex={0}
|
[personalLink, personalLinks, me, link, router, setOpenPopoverForId, topic]
|
||||||
onClick={handleClick}
|
)
|
||||||
className={cn("relative flex h-14 cursor-pointer items-center outline-none xl:h-11", {
|
|
||||||
"bg-muted-foreground/10": isActive,
|
const handlePopoverOpenChange = useCallback(
|
||||||
"hover:bg-muted/50": !isActive
|
(open: boolean) => {
|
||||||
})}
|
setIsPopoverOpen(open)
|
||||||
>
|
setOpenPopoverForId(open ? link.id : null)
|
||||||
<div className="flex grow justify-between gap-x-6 px-6 max-lg:px-4">
|
},
|
||||||
<div className="flex min-w-0 items-center gap-x-4">
|
[link.id, setOpenPopoverForId]
|
||||||
<Popover open={isPopoverOpen} onOpenChange={handlePopoverOpenChange}>
|
)
|
||||||
<PopoverTrigger asChild>
|
|
||||||
<Button
|
return (
|
||||||
size="sm"
|
<li
|
||||||
type="button"
|
ref={ref}
|
||||||
role="combobox"
|
tabIndex={0}
|
||||||
variant="secondary"
|
onClick={handleClick}
|
||||||
className={cn("size-7 shrink-0 p-0", "hover:bg-accent-foreground/10")}
|
className={cn("relative flex h-14 cursor-pointer items-center outline-none xl:h-11", {
|
||||||
onClick={e => e.stopPropagation()}
|
"bg-muted-foreground/10": isActive,
|
||||||
>
|
"hover:bg-muted/50": !isActive
|
||||||
{selectedLearningState?.icon ? (
|
})}
|
||||||
<LaIcon name={selectedLearningState.icon} className={selectedLearningState.className} />
|
>
|
||||||
) : (
|
<div className="flex grow justify-between gap-x-6 px-6 max-lg:px-4">
|
||||||
<LaIcon name="Circle" />
|
<div className="flex min-w-0 items-center gap-x-4">
|
||||||
)}
|
<Popover open={isPopoverOpen} onOpenChange={handlePopoverOpenChange}>
|
||||||
</Button>
|
<PopoverTrigger asChild>
|
||||||
</PopoverTrigger>
|
<Button
|
||||||
<PopoverContent
|
size="sm"
|
||||||
className="w-52 rounded-lg p-0"
|
type="button"
|
||||||
side="bottom"
|
role="combobox"
|
||||||
align="start"
|
variant="secondary"
|
||||||
onCloseAutoFocus={e => e.preventDefault()}
|
className={cn("size-7 shrink-0 p-0", "hover:bg-accent-foreground/10")}
|
||||||
|
onClick={e => e.stopPropagation()}
|
||||||
>
|
>
|
||||||
<LearningStateSelectorContent
|
{selectedLearningState?.icon ? (
|
||||||
showSearch={false}
|
<LaIcon name={selectedLearningState.icon} className={selectedLearningState.className} />
|
||||||
searchPlaceholder="Search state..."
|
) : (
|
||||||
value={personalLink?.learningState}
|
<LaIcon name="Circle" />
|
||||||
onSelect={(value: string) => handleSelectLearningState(value as LearningStateValue)}
|
)}
|
||||||
|
</Button>
|
||||||
|
</PopoverTrigger>
|
||||||
|
<PopoverContent
|
||||||
|
className="w-52 rounded-lg p-0"
|
||||||
|
side="bottom"
|
||||||
|
align="start"
|
||||||
|
onCloseAutoFocus={e => e.preventDefault()}
|
||||||
|
>
|
||||||
|
<LearningStateSelectorContent
|
||||||
|
showSearch={false}
|
||||||
|
searchPlaceholder="Search state..."
|
||||||
|
value={personalLink?.learningState}
|
||||||
|
onSelect={(value: string) => handleSelectLearningState(value as LearningStateValue)}
|
||||||
|
/>
|
||||||
|
</PopoverContent>
|
||||||
|
</Popover>
|
||||||
|
|
||||||
|
<div className="w-full min-w-0 flex-auto">
|
||||||
|
<div className="gap-x-2 space-y-0.5 xl:flex xl:flex-row">
|
||||||
|
<p
|
||||||
|
className={cn(
|
||||||
|
"text-primary hover:text-primary line-clamp-1 text-sm font-medium xl:truncate",
|
||||||
|
isActive && "font-bold"
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{link.title}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div className="group flex items-center gap-x-1">
|
||||||
|
<LaIcon
|
||||||
|
name="Link"
|
||||||
|
aria-hidden="true"
|
||||||
|
className="text-muted-foreground group-hover:text-primary flex-none"
|
||||||
/>
|
/>
|
||||||
</PopoverContent>
|
|
||||||
</Popover>
|
|
||||||
|
|
||||||
<div className="w-full min-w-0 flex-auto">
|
<Link
|
||||||
<div className="gap-x-2 space-y-0.5 xl:flex xl:flex-row">
|
href={ensureUrlProtocol(link.url)}
|
||||||
<p
|
passHref
|
||||||
className={cn(
|
prefetch={false}
|
||||||
"text-primary hover:text-primary line-clamp-1 text-sm font-medium xl:truncate",
|
target="_blank"
|
||||||
isActive && "font-bold"
|
onClick={e => e.stopPropagation()}
|
||||||
)}
|
className="text-muted-foreground hover:text-primary text-xs"
|
||||||
>
|
>
|
||||||
{link.title}
|
<span className="xl:truncate">{link.url}</span>
|
||||||
</p>
|
</Link>
|
||||||
|
|
||||||
<div className="group flex items-center gap-x-1">
|
|
||||||
<LaIcon
|
|
||||||
name="Link"
|
|
||||||
aria-hidden="true"
|
|
||||||
className="text-muted-foreground group-hover:text-primary flex-none"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<Link
|
|
||||||
href={ensureUrlProtocol(link.url)}
|
|
||||||
passHref
|
|
||||||
prefetch={false}
|
|
||||||
target="_blank"
|
|
||||||
onClick={e => e.stopPropagation()}
|
|
||||||
className="text-muted-foreground hover:text-primary text-xs"
|
|
||||||
>
|
|
||||||
<span className="xl:truncate">{link.url}</span>
|
|
||||||
</Link>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex shrink-0 items-center gap-x-4"></div>
|
|
||||||
</div>
|
</div>
|
||||||
</li>
|
<div className="flex shrink-0 items-center gap-x-4"></div>
|
||||||
)
|
</div>
|
||||||
}
|
</li>
|
||||||
)
|
)
|
||||||
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
LinkItem.displayName = "LinkItem"
|
LinkItem.displayName = "LinkItem"
|
||||||
|
|||||||
Reference in New Issue
Block a user