|
1 | 1 | "use client";
|
2 |
| -import Image from "next/image"; |
3 | 2 | import Link from "next/link";
|
4 | 3 | import { useEffect, useState } from "react";
|
5 | 4 | import { getTimeAgo } from "~/lib/utils";
|
6 | 5 | import { createClient } from "~/utils/supabase/client";
|
| 6 | +import CardReview from "./_components/card-review"; |
7 | 7 |
|
8 | 8 | type Comment = {
|
9 | 9 | content: string;
|
10 | 10 | created_at: string;
|
11 | 11 | id: number;
|
12 | 12 | poll_id: number;
|
13 | 13 | user_id: string;
|
14 |
| - profiles: { |
| 14 | + users: { |
15 | 15 | id: string;
|
16 | 16 | username: string | null;
|
17 | 17 | avatar_url: string | null;
|
18 |
| - }[]; |
| 18 | + }; |
19 | 19 | }[];
|
20 | 20 |
|
21 | 21 | export function Comments({
|
@@ -60,42 +60,50 @@ export function Comments({
|
60 | 60 | },
|
61 | 61 | )
|
62 | 62 | .subscribe();
|
63 |
| - }, [supabase, comments, setComments]); |
| 63 | + }, [supabase, comments]); |
64 | 64 |
|
65 | 65 | return comments != null
|
66 | 66 | ? comments.map((comment) => {
|
67 |
| - // @ts-expect-error supabase thinks profiles is an array |
68 |
| - const { username } = comment.profiles; |
| 67 | + // <li key={comment.id} className="px-3 py-2 bg-gray-100 rounded-lg"> |
| 68 | + // <div className="w-full flex flex-col gap-2"> |
| 69 | + // <p>{comment.content}</p> |
| 70 | + // <div className="flex items-center gap-1 bg-gray-200 w-fit py-0.5 px-2 rounded-full"> |
| 71 | + // <Image |
| 72 | + // alt={`${username}'s Avatar`} |
| 73 | + // className="shrink-0 select-none rounded-full" |
| 74 | + // loading="eager" |
| 75 | + // src={`https://vercel.com/api/www/avatar/${username}?s=48`} |
| 76 | + // width={24} |
| 77 | + // height={24} |
| 78 | + // /> |
| 79 | + // <div className="flex items-center gap-1"> |
| 80 | + // <Link |
| 81 | + // href={`/${username}`} |
| 82 | + // className="font-medium hover:underline" |
| 83 | + // > |
| 84 | + // @{username} |
| 85 | + // </Link> |
69 | 86 |
|
| 87 | + // <span className="text-xs text-gray-600"> |
| 88 | + // {/* Date ago of the comment */} |
| 89 | + // {getTimeAgo(comment.created_at)} |
| 90 | + // </span> |
| 91 | + // </div> |
| 92 | + // </div> |
| 93 | + // </div> |
| 94 | + // </li> |
70 | 95 | return (
|
71 |
| - <li key={comment.id} className="px-3 py-2 bg-gray-100 rounded-lg"> |
72 |
| - <div className="w-full flex flex-col gap-2"> |
73 |
| - <p>{comment.content}</p> |
74 |
| - <div className="flex items-center gap-1 bg-gray-200 w-fit py-0.5 px-2 rounded-full"> |
75 |
| - <Image |
76 |
| - alt={`${username}'s Avatar`} |
77 |
| - className="shrink-0 select-none rounded-full" |
78 |
| - loading="eager" |
79 |
| - src={`https://vercel.com/api/www/avatar/${username}?s=48`} |
80 |
| - width={24} |
81 |
| - height={24} |
82 |
| - /> |
83 |
| - <div className="flex items-center gap-1"> |
84 |
| - <Link |
85 |
| - href={`/${username}`} |
86 |
| - className="font-medium hover:underline" |
87 |
| - > |
88 |
| - @{username} |
89 |
| - </Link> |
90 |
| - |
91 |
| - <span className="text-xs text-gray-600"> |
92 |
| - {/* Date ago of the comment */} |
93 |
| - {getTimeAgo(comment.created_at)} |
94 |
| - </span> |
95 |
| - </div> |
96 |
| - </div> |
97 |
| - </div> |
98 |
| - </li> |
| 96 | + <CardReview |
| 97 | + key={comment.id} |
| 98 | + content={comment.content} |
| 99 | + rating={3} |
| 100 | + title="Title" |
| 101 | + user={{ |
| 102 | + avatar: comment.users.avatar_url ?? "", |
| 103 | + name: comment.users.username ?? "", |
| 104 | + }} |
| 105 | + createdAt="2021-08-01T12:00:00.000Z" |
| 106 | + /> |
99 | 107 | );
|
100 | 108 | })
|
101 | 109 | : null;
|
|
0 commit comments