11import { Element , Text } from '@codesandbox/components' ;
2+ import OutsideClickHandler from 'react-outside-click-handler' ;
23import { css } from '@styled-system/css' ;
34import { useOvermind } from 'app/overmind' ;
45import { formatDistanceStrict } from 'date-fns' ;
@@ -69,6 +70,7 @@ export const MultiComment = ({ x, y, ids }: MultiCommentProps) => {
6970 width : 200 ,
7071 cursor : 'pointer' ,
7172 position : 'relative' ,
73+ textAlign : 'left' ,
7274 '&:hover' : {
7375 color : 'list.hoverForeground' ,
7476 backgroundColor : 'list.hoverBackground' ,
@@ -85,57 +87,63 @@ export const MultiComment = ({ x, y, ids }: MultiCommentProps) => {
8587 ) ;
8688
8789 return (
88- < Element as = "ul" css = { list } >
89- { ids
90- . map ( id => comments . comments [ editor . currentSandbox . id ] [ id ] )
91- . sort ( ( commentA , commentB ) => {
92- const dateA = new Date ( commentA . insertedAt ) ;
93- const dateB = new Date ( commentB . insertedAt ) ;
94- if ( dateA < dateB ) {
95- return 1 ;
96- }
90+ < Element css = { css ( { position : 'absolute' } ) } >
91+ < OutsideClickHandler
92+ onOutsideClick = { ( ) => actions . comments . closeMultiCommentsSelector ( ) }
93+ >
94+ < Element as = "ul" css = { list } >
95+ { ids
96+ . map ( id => comments . comments [ editor . currentSandbox . id ] [ id ] )
97+ . sort ( ( commentA , commentB ) => {
98+ const dateA = new Date ( commentA . insertedAt ) ;
99+ const dateB = new Date ( commentB . insertedAt ) ;
100+ if ( dateA < dateB ) {
101+ return 1 ;
102+ }
97103
98- if ( dateA > dateB ) {
99- return - 1 ;
100- }
104+ if ( dateA > dateB ) {
105+ return - 1 ;
106+ }
101107
102- return 0 ;
103- } )
104- . map ( comment => (
105- < Element as = "li" key = { comment . id } >
106- < Element
107- as = "button"
108- type = "button"
109- onClick = { event => {
110- const bounds = event . currentTarget . getBoundingClientRect ( ) ;
111- actions . comments . selectComment ( {
112- commentId : comment . id ,
113- bounds : {
114- left : bounds . left ,
115- right : bounds . right ,
116- top : bounds . top ,
117- bottom : bounds . bottom ,
118- } ,
119- } ) ;
120- } }
121- css = { item }
122- >
123- < Text
124- size = { 2 }
125- weight = "bold"
126- paddingRight = { 2 }
127- css = { css ( {
128- color : 'sideBar.foreground' ,
129- } ) }
130- >
131- { comment . user . username }
132- </ Text >
133- < Text size = { 2 } variant = "muted" >
134- { date ( comment ) }
135- </ Text >
136- </ Element >
137- </ Element >
138- ) ) }
108+ return 0 ;
109+ } )
110+ . map ( comment => (
111+ < Element as = "li" key = { comment . id } >
112+ < Element
113+ as = "button"
114+ type = "button"
115+ onClick = { event => {
116+ const bounds = event . currentTarget . getBoundingClientRect ( ) ;
117+ actions . comments . selectComment ( {
118+ commentId : comment . id ,
119+ bounds : {
120+ left : bounds . left ,
121+ right : bounds . right ,
122+ top : bounds . top ,
123+ bottom : bounds . bottom ,
124+ } ,
125+ } ) ;
126+ } }
127+ css = { item }
128+ >
129+ < Text
130+ size = { 2 }
131+ weight = "bold"
132+ paddingRight = { 2 }
133+ css = { css ( {
134+ color : 'sideBar.foreground' ,
135+ } ) }
136+ >
137+ { comment . user . username }
138+ </ Text >
139+ < Text size = { 2 } variant = "muted" >
140+ { date ( comment ) }
141+ </ Text >
142+ </ Element >
143+ </ Element >
144+ ) ) }
145+ </ Element >
146+ </ OutsideClickHandler >
139147 </ Element >
140148 ) ;
141149} ;
0 commit comments