diff --git a/apps/web/src/components/likes/likes.tsx b/apps/web/src/components/likes/likes.tsx index aaf7f14ba..b4133eb78 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,86 +54,106 @@ 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 = ( + <> + {/* + API response is wrapped as { data: { likes: [...] } } by Orval. + */} + {(() => { + const likes = data?.data.likes ?? [] + return isLoading || !data + ? Array.from({ length: 5 }).map(() => ( +
+
+ + +
+
+ )) + : likes.map(({ user, id }) => ( +
+ + + {user.avatarUrl && ( + + )} + + {user.username[0].toUpperCase()} + + + + + {user.username} + + - -
- ))} - - ) - } + {user.subscriptionType === 'PRO' && } - const likes = data.data && 'likes' in data.data ? data.data.likes : [] + + {dictionary.review_likes.view_profile} + +
+ )) + })()} + + ) + if (resolvedMode === 'dialog') { return ( - <> - {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} + + ) }