File tree Expand file tree Collapse file tree 9 files changed +193
-74
lines changed
pages/Sandbox/Editor/Workspace/screens/Comments Expand file tree Collapse file tree 9 files changed +193
-74
lines changed Original file line number Diff line number Diff line change @@ -97,6 +97,8 @@ export const reply: Query<any, any> = gql`
97
97
) {
98
98
id
99
99
replies {
100
+ insertedAt
101
+ updatedAt
100
102
id
101
103
content
102
104
author {
@@ -117,6 +119,8 @@ export const deleteReply: Query<
117
119
deleteReply(replyId: $replyId, commentId: $commentId) {
118
120
id
119
121
replies {
122
+ insertedAt
123
+ updatedAt
120
124
id
121
125
content
122
126
author {
@@ -137,6 +141,8 @@ export const updateReply: Query<
137
141
updateReply(replyId: $replyId, commentId: $commentId, comment: $comment) {
138
142
id
139
143
replies {
144
+ insertedAt
145
+ updatedAt
140
146
id
141
147
content
142
148
author {
Original file line number Diff line number Diff line change @@ -23,9 +23,12 @@ export const allComments: Query<CommentsResponse, CommentsVariables> = gql`
23
23
}
24
24
}
25
25
replies {
26
+ insertedAt
27
+ updatedAt
26
28
id
27
29
content
28
30
author {
31
+ id
29
32
avatarUrl
30
33
username
31
34
}
@@ -54,9 +57,12 @@ export const comment: Query<CommentResponse, CommentVariables> = gql`
54
57
id
55
58
content
56
59
author {
60
+ id
57
61
avatarUrl
58
62
username
59
63
}
64
+ insertedAt
65
+ updatedAt
60
66
}
61
67
insertedAt
62
68
updatedAt
Original file line number Diff line number Diff line change @@ -4,6 +4,14 @@ export type Message = {
4
4
author ?: Author ;
5
5
} ;
6
6
7
+ export type Reply = {
8
+ id : string ;
9
+ content ?: string ;
10
+ author ?: Author ;
11
+ insertedAt ?: string ;
12
+ updatedAt ?: string ;
13
+ } ;
14
+
7
15
export type Author = {
8
16
id : string ;
9
17
avatarUrl : string ;
@@ -14,7 +22,7 @@ export type Comment = {
14
22
id : string ;
15
23
isResolved : boolean ;
16
24
originalMessage : Message ;
17
- replies : Message [ ] ;
25
+ replies : Reply [ ] ;
18
26
insertedAt : string ;
19
27
updatedAt ?: string ;
20
28
metadata ?: string ;
@@ -29,7 +37,7 @@ export type CommentsResponse = {
29
37
{
30
38
id : string ;
31
39
isResolved : boolean ;
32
- replies : Pick < Message , 'id' > [ ] ;
40
+ replies : Pick < Reply , 'id' > [ ] ;
33
41
originalMessage : Message ;
34
42
insertedAt : string ;
35
43
updatedAt : string ;
@@ -49,7 +57,7 @@ export type AddCommentResponse = {
49
57
addComment : {
50
58
id : string ;
51
59
isResolved : boolean ;
52
- replies : Pick < Message , 'id' > [ ] ;
60
+ replies : Pick < Reply , 'id' > [ ] ;
53
61
originalMessage : Message ;
54
62
insertedAt : string ;
55
63
updatedAt : string ;
@@ -98,7 +106,7 @@ export type CommentResponse = {
98
106
id : string ;
99
107
content : string ;
100
108
} ;
101
- replies : Message [ ] ;
109
+ replies : Reply [ ] ;
102
110
insertedAt : string ;
103
111
updatedAt : string ;
104
112
metadata : string ;
@@ -110,7 +118,7 @@ export type DeleteReplyVariables = { replyId: string; commentId: string };
110
118
export type DeleteReplyResponse = {
111
119
deleteReply : {
112
120
id : string ;
113
- replies : Message [ ] ;
121
+ replies : Reply [ ] ;
114
122
} ;
115
123
} ;
116
124
@@ -123,6 +131,6 @@ export type UpdateReplyVariables = {
123
131
export type UpdateReplyResponse = {
124
132
updateReply : {
125
133
id : string ;
126
- replies : Message [ ] ;
134
+ replies : Reply [ ] ;
127
135
} ;
128
136
} ;
Original file line number Diff line number Diff line change @@ -1488,13 +1488,22 @@ export const updateComment: AsyncAction<{
1488
1488
const sandboxId = state . editor . currentSandbox . id ;
1489
1489
const isResolved = state . editor . comments [ sandboxId ] [ id ] . isResolved ;
1490
1490
const comment = state . editor . comments [ sandboxId ] [ id ] . originalMessage . content ;
1491
+ const updateIsCurrent =
1492
+ state . editor . comments [ sandboxId ] [ id ] . id === state . editor . currentComment . id ;
1491
1493
1492
1494
if ( 'isResolved' in data ) {
1493
1495
state . editor . comments [ sandboxId ] [ id ] . isResolved = data . isResolved ;
1496
+ if ( updateIsCurrent ) {
1497
+ state . editor . currentComment . isResolved = data . isResolved ;
1498
+ }
1494
1499
}
1495
1500
1496
1501
if ( 'comment' in data ) {
1497
1502
state . editor . comments [ sandboxId ] [ id ] . originalMessage . content = data . comment ;
1503
+
1504
+ if ( updateIsCurrent ) {
1505
+ state . editor . currentComment . originalMessage . content = data . comment ;
1506
+ }
1498
1507
}
1499
1508
1500
1509
try {
@@ -1508,6 +1517,10 @@ export const updateComment: AsyncAction<{
1508
1517
) ;
1509
1518
state . editor . comments [ sandboxId ] [ id ] . isResolved = isResolved ;
1510
1519
state . editor . comments [ sandboxId ] [ id ] . originalMessage . content = comment ;
1520
+ if ( updateIsCurrent ) {
1521
+ state . editor . currentComment . id = id ;
1522
+ state . editor . currentComment . originalMessage . content = comment ;
1523
+ }
1511
1524
}
1512
1525
} ;
1513
1526
@@ -1635,6 +1648,7 @@ export const addReply: AsyncAction<string> = async (
1635
1648
// sorry
1636
1649
// @ts -ignore
1637
1650
replies : state . editor . currentComment . replies . concat ( {
1651
+ insertedAt : new Date ( ) ,
1638
1652
id : fakeId ,
1639
1653
content : comment ,
1640
1654
author : {
Original file line number Diff line number Diff line change @@ -31,7 +31,6 @@ export const Comment = React.memo(({ comment }: any) => {
31
31
32
32
return (
33
33
< ListAction
34
- onClick = { ( ) => actions . editor . selectComment ( comment . id ) }
35
34
key = { comment . id }
36
35
paddingTop = { 5 }
37
36
css = { css ( {
@@ -44,7 +43,11 @@ export const Comment = React.memo(({ comment }: any) => {
44
43
} ) }
45
44
>
46
45
< Stack align = "flex-start" justify = "space-between" marginBottom = { 4 } >
47
- < Stack gap = { 2 } align = "center" >
46
+ < Stack
47
+ gap = { 2 }
48
+ align = "center"
49
+ onClick = { ( ) => actions . editor . selectComment ( comment . id ) }
50
+ >
48
51
< Avatar user = { comment . originalMessage . author } />
49
52
< Stack direction = "vertical" justify = "center" >
50
53
< Link
@@ -93,6 +96,7 @@ export const Comment = React.memo(({ comment }: any) => {
93
96
</ Stack >
94
97
</ Stack >
95
98
< Element
99
+ onClick = { ( ) => actions . editor . selectComment ( comment . id ) }
96
100
as = "p"
97
101
marginY = { 0 }
98
102
marginRight = { 2 /** Adjust for the missing margin in ListAction */ }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -42,6 +42,9 @@ export const Comment = ({ source }) => {
42
42
color : 'mutedForeground' ,
43
43
content : "counter(counter) '. '" ,
44
44
} ,
45
+ p : {
46
+ margin : 0 ,
47
+ } ,
45
48
li : {
46
49
listStyle : 'none' ,
47
50
} ,
Original file line number Diff line number Diff line change
1
+ import React from 'react' ;
2
+ import { formatDistance } from 'date-fns' ;
3
+ import css from '@styled-system/css' ;
4
+ import {
5
+ Element ,
6
+ Stack ,
7
+ Avatar ,
8
+ Text ,
9
+ Link ,
10
+ Menu ,
11
+ } from '@codesandbox/components' ;
12
+ import { useOvermind } from 'app/overmind' ;
13
+ import { Comment } from './Comment' ;
14
+
15
+ type ReplyProps = {
16
+ id : string ;
17
+ author ?: any ;
18
+ insertedAt ?: string ;
19
+ commentId : string ;
20
+ content ?: string ;
21
+ } ;
22
+
23
+ export const Reply = ( {
24
+ id,
25
+ author,
26
+ insertedAt,
27
+ commentId,
28
+ content,
29
+ } : ReplyProps ) => {
30
+ const { state, actions } = useOvermind ( ) ;
31
+ return (
32
+ < >
33
+ < Element
34
+ key = { id }
35
+ paddingX = { 4 }
36
+ paddingTop = { 6 }
37
+ css = { css ( {
38
+ borderTop : '1px solid' ,
39
+ borderColor : 'sideBar.border' ,
40
+ } ) }
41
+ >
42
+ < Stack align = "flex-start" justify = "space-between" marginBottom = { 4 } >
43
+ < Stack gap = { 2 } align = "center" >
44
+ < Avatar user = { author } />
45
+ < Stack direction = "vertical" justify = "center" >
46
+ < Link
47
+ href = { `/u/${ author . username } ` }
48
+ variant = "body"
49
+ css = { { fontWeight : 'bold' , display : 'block' } }
50
+ >
51
+ { author . username }
52
+ </ Link >
53
+ < Text size = { 12 } variant = "muted" >
54
+ { formatDistance ( new Date ( insertedAt ) , new Date ( ) , {
55
+ addSuffix : true ,
56
+ } ) }
57
+ </ Text >
58
+ </ Stack >
59
+ </ Stack >
60
+ { state . user . id === author . id && (
61
+ < Stack align = "center" >
62
+ < Menu >
63
+ < Menu . IconButton name = "more" title = "Reply actions" size = { 3 } />
64
+ < Menu . List >
65
+ < Menu . Item
66
+ onSelect = { ( ) =>
67
+ actions . editor . deleteReply ( {
68
+ replyId : id ,
69
+ commentId,
70
+ } )
71
+ }
72
+ >
73
+ Delete
74
+ </ Menu . Item >
75
+ < Menu . Item > Edit</ Menu . Item >
76
+ </ Menu . List >
77
+ </ Menu >
78
+ </ Stack >
79
+ ) }
80
+ </ Stack >
81
+ </ Element >
82
+ < Comment source = { content } />
83
+ </ >
84
+ ) ;
85
+ } ;
You can’t perform that action at this time.
0 commit comments