Skip to content

Commit 87ee7df

Browse files
author
Roshan Jossy
committed
update user profile page
1 parent cc7afc2 commit 87ee7df

File tree

12 files changed

+1234
-56
lines changed

12 files changed

+1234
-56
lines changed

next.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const nextConfig = {
1111
async rewrites() {
1212
return [
1313
{
14-
source: '/@:handle([a-zA-Z0-9]+)/:id*',
14+
source: '/@:handle([a-zA-Z0-9/-_]+)/:id*',
1515
destination: '/users/:handle/:id*',
1616
},
1717
{

schema/schema.graphql

Lines changed: 58 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ schema {
44
mutation: Mutation
55
}
66
scalar Time
7+
8+
enum SortOrder {
9+
asc,
10+
desc,
11+
}
12+
713
type Query {
814
viewer: User
915

@@ -12,7 +18,8 @@ type Query {
1218
# The ID of an object
1319
id: ID!
1420
): Node
15-
feeds(first: Int, last: Int, after: String, before: String): StoriesConnection!
21+
feeds(first: Int, last: Int, after: String, before: String, sortBy: String, sortOrder: SortOrder): StoriesConnection!
22+
user(handle: String): User!
1623
}
1724

1825
interface Node {
@@ -39,19 +46,23 @@ type Badge implements Node {
3946
type BadgesConnection {
4047
edges: [BadgeEdge]!
4148
pageInfo: PageInfo!
49+
totalCount: Int!
4250
}
4351

4452
type BadgeEdge {
4553
node: Badge!
4654
cursor: String!
55+
}
56+
57+
enum BadgeSortBy {
58+
time_created,
4759
}
4860

4961
type Comment implements Node {
5062
abstractContent: String!
5163
contentJson: String!
5264
createdBy: User!
5365
id: ID!
54-
reactions(first: Int, last: Int, after: String, before: String): ReactionsConnection!
5566
timeCreated: Time!
5667
timeUpdated: Time!
5768
}
@@ -68,11 +79,17 @@ input UpdateCommentInput {
6879
type CommentsConnection {
6980
edges: [CommentEdge]!
7081
pageInfo: PageInfo!
82+
totalCount: Int!
83+
hasViewerAssociation: Boolean!
7184
}
7285

7386
type CommentEdge {
7487
node: Comment!
7588
cursor: String!
89+
}
90+
91+
enum CommentSortBy {
92+
time_created,
7693
}
7794

7895
type GitContributionStats {
@@ -101,11 +118,16 @@ type Issue implements Node {
101118
type IssuesConnection {
102119
edges: [IssueEdge]!
103120
pageInfo: PageInfo!
121+
totalCount: Int!
104122
}
105123

106124
type IssueEdge {
107125
node: Issue!
108126
cursor: String!
127+
}
128+
129+
enum IssueSortBy {
130+
time_created,
109131
}
110132

111133
type Reaction implements Node {
@@ -116,7 +138,6 @@ type Reaction implements Node {
116138
}
117139

118140
input ReactionInput {
119-
commentID: ID!
120141
storyID: ID!
121142
}
122143
input UpdateReactionInput {
@@ -126,11 +147,17 @@ input UpdateReactionInput {
126147
type ReactionsConnection {
127148
edges: [ReactionEdge]!
128149
pageInfo: PageInfo!
150+
totalCount: Int!
151+
hasViewerAssociation: Boolean!
129152
}
130153

131154
type ReactionEdge {
132155
node: Reaction!
133156
cursor: String!
157+
}
158+
159+
enum ReactionSortBy {
160+
time_created,
134161
}
135162

136163
type Reputation {
@@ -143,11 +170,11 @@ input ReputationInput {
143170

144171
type Story implements Node {
145172
abstractContent: String!
146-
comments(first: Int, last: Int, after: String, before: String): CommentsConnection!
173+
comments(first: Int, last: Int, after: String, before: String, sortBy: String, sortOrder: SortOrder): CommentsConnection!
147174
contentJson: String!
148175
createdBy: User!
149176
id: ID!
150-
reactions(first: Int, last: Int, after: String, before: String): ReactionsConnection!
177+
reactions(first: Int, last: Int, after: String, before: String, sortBy: String, sortOrder: SortOrder): ReactionsConnection!
151178
thumbnail: String!
152179
timeCreated: Time!
153180
timeUpdated: Time!
@@ -169,26 +196,32 @@ input UpdateStoryInput {
169196
type StoriesConnection {
170197
edges: [StoryEdge]!
171198
pageInfo: PageInfo!
199+
totalCount: Int!
200+
hasViewerAssociation: Boolean!
172201
}
173202

174203
type StoryEdge {
175204
node: Story!
176205
cursor: String!
206+
}
207+
208+
enum StorySortBy {
209+
time_created,
177210
}
178211

179212
type User implements Node {
180213
avatar: String!
181-
badges(first: Int, last: Int, after: String, before: String): BadgesConnection!
214+
badges(first: Int, last: Int, after: String, before: String, sortBy: String, sortOrder: SortOrder): BadgesConnection!
182215
bio: String!
183216
gitContributionStats: GitContributionStats!
184217
handle: String!
185218
id: ID!
186-
issuesFromLastRepo(first: Int, last: Int, after: String, before: String): IssuesConnection!
187-
issuesFromOtherRecentRepos(first: Int, last: Int, after: String, before: String): IssuesConnection!
219+
issuesFromLastRepo(first: Int, last: Int, after: String, before: String, sortBy: String, sortOrder: SortOrder): IssuesConnection!
220+
issuesFromOtherRecentRepos(first: Int, last: Int, after: String, before: String, sortBy: String, sortOrder: SortOrder): IssuesConnection!
188221
name: String!
189-
relevantIssues(first: Int, last: Int, after: String, before: String): IssuesConnection!
222+
relevantIssues(first: Int, last: Int, after: String, before: String, sortBy: String, sortOrder: SortOrder): IssuesConnection!
190223
reputation: Reputation!
191-
stories(first: Int, last: Int, after: String, before: String): StoriesConnection!
224+
stories(first: Int, last: Int, after: String, before: String, sortBy: String, sortOrder: SortOrder): StoriesConnection!
192225
timeCreated: Time!
193226
timeUpdated: Time!
194227
}
@@ -208,6 +241,21 @@ input UpdateUserInput {
208241
gitContributionStats: GitContributionStatsInput
209242
name: String
210243
reputation: ReputationInput
244+
}
245+
246+
type UsersConnection {
247+
edges: [UserEdge]!
248+
pageInfo: PageInfo!
249+
totalCount: Int!
250+
}
251+
252+
type UserEdge {
253+
node: User!
254+
cursor: String!
255+
}
256+
257+
enum UserSortBy {
258+
time_created,
211259
}
212260

213261
type Mutation {

src/components/UserDetails/Bio.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useState } from 'react'
2-
import { GoPencil, GrPencil } from '@react-icons/all-files/go/GoPencil'
2+
import { GoPencil } from '@react-icons/all-files/go/GoPencil'
33
import { GoCheck } from '@react-icons/all-files/go/GoCheck'
44
import { graphql, useFragment, useMutation } from 'react-relay'
55
import { Bio_user$key } from '../../queries/__generated__/Bio_user.graphql'

src/components/feed/MyStories.tsx

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { graphql, usePaginationFragment } from 'react-relay'
2+
import { MyStories__Query$key } from '../../queries/__generated__/MyStories__Query.graphql'
3+
import StoryPreview from './StoryPreview'
4+
5+
type MyStoriesProps = {
6+
user: MyStories__Query$key
7+
}
8+
9+
const MyStories = ({ user }: MyStoriesProps) => {
10+
const { data } = usePaginationFragment(
11+
graphql`
12+
fragment MyStories__Query on User
13+
@refetchable(queryName: "MyStoriesUser_Query")
14+
@argumentDefinitions(
15+
count: { type: "Int", defaultValue: 10 }
16+
cursor: { type: "String" }
17+
) {
18+
stories(first: $count, after: $cursor)
19+
@connection(key: "UserQuery__stories") {
20+
edges {
21+
node {
22+
id
23+
...StoryPreview_node
24+
}
25+
}
26+
}
27+
}
28+
`,
29+
user
30+
)
31+
32+
return (
33+
<>
34+
{data.stories.edges.map(
35+
(edge) => edge && <StoryPreview story={edge?.node} key={edge.node.id} />
36+
)}
37+
</>
38+
)
39+
}
40+
41+
export default MyStories

src/components/story/StoryEditor.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,28 @@ export default function Editor({ editable, body }: EditorProps) {
142142
--tw-prose-pre-code: none;
143143
--tw-prose-pre-bg: none;
144144
}
145+
146+
.dark .ce-inline-tool,
147+
.dark .ce-toolbar__plus,
148+
.dark .ce-toolbar__settings-btn {
149+
@apply text-gray-400;
150+
}
151+
152+
.dark .ce-inline-toolbar,
153+
.dark .ce-conversion-toolbar,
154+
.dark .ce-toolbox,
155+
.dark .ce-popover,
156+
.dark .ce-settings {
157+
@apply bg-dark-600 border-dark-500;
158+
}
159+
160+
.dark .ce-popover__item-icon {
161+
@apply bg-dark-500;
162+
}
163+
164+
.dark .ce-block--selected {
165+
@apply bg-dark-500 text-gray-800;
166+
}
145167
`}
146168
</style>
147169
{editable && <Button onClick={() => handleStorySubmit()}>Submit </Button>}

src/pages/story/[id].tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import dynamic from 'next/dynamic'
33
import { graphql, usePreloadedQuery } from 'react-relay'
44
import { RelayProps, withRelay } from 'relay-nextjs'
55
import Layout from '../../components/Layout'
6+
import UserDetails from '../../components/UserDetails/UserDetails'
67
import { getClientEnvironment } from '../../lib/client_environment'
78
import { Id_StoryQuery } from '../../queries/__generated__/Id_StoryQuery.graphql'
89

@@ -16,6 +17,9 @@ const StoryQuery = graphql`
1617
... on Story {
1718
id
1819
contentJson
20+
createdBy {
21+
...UserDetails_user
22+
}
1923
}
2024
}
2125
}
@@ -29,7 +33,13 @@ const Story = ({
2933
<div>
3034
<Layout
3135
sidebarContentRight={<div>Promoted</div>}
32-
sidebarContentLeft={<div>Reactions</div>}
36+
sidebarContentLeft={
37+
<div>
38+
{query.node?.createdBy && (
39+
<UserDetails user={query?.node?.createdBy} />
40+
)}
41+
</div>
42+
}
3343
>
3444
<Editor body={query?.node?.contentJson} editable={false} />
3545
</Layout>

src/pages/users/[handle].tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,23 @@ import Layout from '../../components/Layout'
66
import { getClientEnvironment } from '../../lib/client_environment'
77
import Card from '../../components/Card'
88
import UserDetails from '../../components/UserDetails/UserDetails'
9-
import { pages_UserQuery } from '../../queries/__generated__/pages_UserQuery.graphql'
109
import RelayModernEnvironment from 'relay-runtime/lib/store/RelayModernEnvironment'
11-
import { UserDetails_user$key } from '../../queries/__generated__/UserDetails_user.graphql'
10+
import MyStories from '../../components/feed/MyStories'
11+
import { Handle_UserQuery } from '../../queries/__generated__/Handle_UserQuery.graphql'
1212

1313
const UserQuery = graphql`
14-
query pages_UserQuery {
15-
viewer {
14+
query Handle_UserQuery($handle: String!) {
15+
user(handle: $handle) {
1616
handle
1717
...UserDetails_user
18+
...MyStories__Query
1819
}
1920
}
2021
`
2122

2223
const User = ({
2324
preloadedQuery,
24-
}: RelayProps<Record<string, never>, pages_UserQuery>) => {
25+
}: RelayProps<Record<string, never>, Handle_UserQuery>) => {
2526
const query = usePreloadedQuery(UserQuery, preloadedQuery)
2627
const router = useRouter()
2728
const { handle } = router.query
@@ -32,11 +33,11 @@ const User = ({
3233
sidebarContentRight={handle}
3334
sidebarContentLeft={
3435
<Card>
35-
<UserDetails user={query.viewer as UserDetails_user$key} />
36+
<UserDetails user={query.user} />
3637
</Card>
3738
}
3839
>
39-
{handle}
40+
<MyStories user={query.user} />
4041
</Layout>
4142
</div>
4243
)

0 commit comments

Comments
 (0)