({ extensionId }: CommentSectionProps)
| 17 | } |
| 18 | |
| 19 | export function CommentSection({ extensionId }: CommentSectionProps) { |
| 20 | const [sortBy, setSortBy] = useState<SortOption>("newest") |
| 21 | |
| 22 | const comments = useQuery(api.comments.listByExtension, { extensionId, sortBy }) |
| 23 | const userLikes = useQuery(api.comments.getUserLikes, { extensionId }) |
| 24 | const isAdmin = useQuery(api.admin.isAdmin) |
| 25 | |
| 26 | // Get current user ID from the first comment's context or from likes query |
| 27 | // We need to get identity info another way - through Clerk |
| 28 | const identity = useQuery(api.admin.debugIdentity) |
| 29 | const currentUserId = identity?.subject |
| 30 | |
| 31 | const likedCommentIds = new Set(userLikes ?? []) |
| 32 | |
| 33 | const sortOptions: { value: SortOption; label: string }[] = [ |
| 34 | { value: "newest", label: "Newest" }, |
| 35 | { value: "oldest", label: "Oldest" }, |
| 36 | { value: "popular", label: "Popular" }, |
| 37 | ] |
| 38 | |
| 39 | return ( |
| 40 | <div className="flex flex-col gap-6"> |
| 41 | {/* Comment Form - Only for authenticated users */} |
| 42 | <Authenticated> |
| 43 | <CommentForm extensionId={extensionId} /> |
| 44 | </Authenticated> |
| 45 | |
| 46 | <Unauthenticated> |
| 47 | <div className="rounded border border-[var(--color-border-weak)] bg-[var(--color-bg-weak)] p-4 text-center"> |
| 48 | <p className="mb-3 text-sm text-[var(--color-text)]"> |
| 49 | Sign in to join the discussion |
| 50 | </p> |
| 51 | <Link href="/sign-in"> |
| 52 | <Button size="sm">Sign In</Button> |
| 53 | </Link> |
| 54 | </div> |
| 55 | </Unauthenticated> |
| 56 | |
| 57 | {/* Sort Filter */} |
| 58 | {comments && comments.length > 0 && ( |
| 59 | <div className="flex items-center gap-2"> |
| 60 | <span className="text-xs text-[var(--color-text-weak)]">Sort by:</span> |
| 61 | <div className="flex gap-1"> |
| 62 | {sortOptions.map((option) => ( |
| 63 | <button |
| 64 | key={option.value} |
| 65 | onClick={() => setSortBy(option.value)} |
| 66 | className={`rounded px-2 py-1 text-xs transition-colors ${ |
| 67 | sortBy === option.value |
| 68 | ? "bg-[var(--color-bg-strong)] text-[var(--color-text-inverted)]" |
| 69 | : "text-[var(--color-text-weak)] hover:bg-[var(--color-bg-weak)] hover:text-[var(--color-text)]" |
| 70 | }`} |
| 71 | > |
| 72 | {option.label} |
| 73 | </button> |
| 74 | ))} |
| 75 | </div> |
| 76 | </div> |
nothing calls this directly
no outgoing calls
no test coverage detected