|
| 1 | +import type { NextPage } from "next"; |
| 2 | +import Head from "next/head"; |
| 3 | +import { useRouter } from "next/router"; |
| 4 | +import { useQuery } from "urql"; |
| 5 | +import { gql } from "../../gql"; |
| 6 | +import { CommentItem } from "../../lib/comment-item"; |
| 7 | +import { Container } from "../../lib/container"; |
| 8 | +import { FeedItem } from "../../lib/feed-item"; |
| 9 | +import { MainSection } from "../../lib/main-section"; |
| 10 | + |
| 11 | +const ProfileRouteQuery = gql(/* GraphQL */ ` |
| 12 | + query ProfileRouteQuery($profileId: UUID!) { |
| 13 | + profileCollection(filter: { id: { eq: $profileId } }) { |
| 14 | + edges { |
| 15 | + node { |
| 16 | + id |
| 17 | + username |
| 18 | + bio |
| 19 | + website |
| 20 | + latestPosts: postCollection( |
| 21 | + orderBy: [{ createdAt: DescNullsFirst }] |
| 22 | + first: 15 |
| 23 | + ) { |
| 24 | + pageInfo { |
| 25 | + hasNextPage |
| 26 | + } |
| 27 | + edges { |
| 28 | + cursor |
| 29 | + node { |
| 30 | + id |
| 31 | + ...FeedItem_PostFragment |
| 32 | + } |
| 33 | + } |
| 34 | + } |
| 35 | + latestComments: commentCollection( |
| 36 | + orderBy: [{ createdAt: DescNullsFirst }] |
| 37 | + first: 15 |
| 38 | + ) { |
| 39 | + pageInfo { |
| 40 | + hasNextPage |
| 41 | + } |
| 42 | + edges { |
| 43 | + cursor |
| 44 | + node { |
| 45 | + id |
| 46 | + ...CommentItem_CommentFragment |
| 47 | + } |
| 48 | + } |
| 49 | + } |
| 50 | + } |
| 51 | + } |
| 52 | + } |
| 53 | + } |
| 54 | +`); |
| 55 | + |
| 56 | +const Profile: NextPage = () => { |
| 57 | + const router = useRouter(); |
| 58 | + const { profileId } = router.query; |
| 59 | + const [profileQuery] = useQuery({ |
| 60 | + query: ProfileRouteQuery, |
| 61 | + variables: { |
| 62 | + profileId, |
| 63 | + }, |
| 64 | + }); |
| 65 | + |
| 66 | + const profile = profileQuery.data?.profileCollection?.edges?.[0].node; |
| 67 | + |
| 68 | + return ( |
| 69 | + <Container> |
| 70 | + <Head> |
| 71 | + <title>supanews | {profile?.username}</title> |
| 72 | + <meta name="description" content="What is hot?" /> |
| 73 | + <link rel="icon" href="/favicon.ico" /> |
| 74 | + </Head> |
| 75 | + |
| 76 | + <MainSection> |
| 77 | + {profile == null ? null : ( |
| 78 | + <section className="text-gray-600 body-font overflow-hidden"> |
| 79 | + <div className="container px-5 py-24 pt-10 mx-auto"> |
| 80 | + <div> |
| 81 | + <span className="inline-block font-bold pr-2 w-20">User</span>{" "} |
| 82 | + {profile.username} |
| 83 | + </div> |
| 84 | + <div> |
| 85 | + <span className="inline-block font-bold pr-2 w-20"> |
| 86 | + Website |
| 87 | + </span>{" "} |
| 88 | + {profile.website} |
| 89 | + </div> |
| 90 | + <div className="mb-10"> |
| 91 | + <span className="inline-block font-bold pr-2 w-20">Bio</span>{" "} |
| 92 | + {profile.bio} |
| 93 | + </div> |
| 94 | + <h1 className="font-semibold text-xl tracking-tight mb-5"> |
| 95 | + Latest Posts |
| 96 | + </h1> |
| 97 | + <div> |
| 98 | + {profile.latestPosts?.edges.map((edge) => ( |
| 99 | + <FeedItem post={edge.node!} key={edge.cursor} /> |
| 100 | + ))} |
| 101 | + </div> |
| 102 | + |
| 103 | + <h1 className="font-semibold text-xl tracking-tight mb-5"> |
| 104 | + Latest Comments |
| 105 | + </h1> |
| 106 | + |
| 107 | + {profile.latestComments?.edges.map((edge) => ( |
| 108 | + <CommentItem comment={edge.node!} key={edge.cursor} /> |
| 109 | + ))} |
| 110 | + </div> |
| 111 | + </section> |
| 112 | + )} |
| 113 | + </MainSection> |
| 114 | + </Container> |
| 115 | + ); |
| 116 | +}; |
| 117 | + |
| 118 | +export default Profile; |
0 commit comments