diff --git a/apps/web/src/components/likes/likes.tsx b/apps/web/src/components/likes/likes.tsx index 96af7108..1ce23998 100644 --- a/apps/web/src/components/likes/likes.tsx +++ b/apps/web/src/components/likes/likes.tsx @@ -12,6 +12,13 @@ import { DialogHeader, DialogTrigger, } from '@plotwist/ui/components/ui/dialog' +import { + Drawer, + DrawerContent, + DrawerHeader, + DrawerTitle, + DrawerTrigger, +} from '@plotwist/ui/components/ui/drawer' import { Skeleton } from '@plotwist/ui/components/ui/skeleton' import { DialogTitle } from '@radix-ui/react-dialog' import { Heart } from 'lucide-react' @@ -23,10 +30,13 @@ import { useLanguage } from '@/context/language' import { cn } from '@/lib/utils' import { ProBadge } from '../pro-badge' +type LikesMode = 'dialog' | 'drawer' + type LikesProps = { className?: string likeCount: number entityId: string + mode?: LikesMode } & PropsWithChildren export function Likes({ @@ -34,6 +44,7 @@ export function Likes({ likeCount, entityId, children, + mode, }: LikesProps) { const { dictionary, language } = useLanguage() const [open, setOpen] = useState(false) @@ -43,84 +54,100 @@ export function Likes({ if (likeCount === 0) return null - const Content = () => { - if (isLoading || !data) { - return ( - <> - {Array.from({ length: 5 }).map(_ => ( + const resolvedMode: LikesMode = + mode ?? + (typeof window !== 'undefined' && + window.matchMedia('(max-width: 768px)').matches + ? 'drawer' + : 'dialog') + + const Trigger = children || ( +
+ + +
+ ) + + const Content = ( + <> + {isLoading || !data + ? Array.from({ length: 5 }).map(() => (
- +
-
+ )) + : data.likes.map(({ user, id }) => ( +
+ + + {user.avatarUrl && ( + + )} + + {user.username[0].toUpperCase()} + + + + + {user.username} + + + + {user.subscriptionType === 'PRO' && } + + + {dictionary.review_likes.view_profile} + +
))} - - ) - } + + ) + if (resolvedMode === 'dialog') { return ( - <> - {data.likes.map(({ user, id }) => ( -
- - - {user.avatarUrl && ( - - )} - - - {user.username[0].toUpperCase()} - - - - - {user.username} - - - - {user.subscriptionType === 'PRO' && } - - - {dictionary.review_likes.view_profile} - -
- ))} - + + {Trigger} + + + + {dictionary.likes} + + + {Content} + + ) } return ( - - - {children || ( -
- - -
- )} -
- - - - {dictionary.likes} - - - - -
+ + {Trigger} + + + + {dictionary.likes} + + + {Content} + + ) }