1- import React from 'react' ;
2- import { formatDistanceStrict } from 'date-fns' ;
1+ import { Element , Text } from '@codesandbox/components' ;
32import { css } from '@styled-system/css' ;
43import { useOvermind } from 'app/overmind' ;
5- import { Text , Element } from '@codesandbox/components' ;
4+ import { formatDistanceStrict } from 'date-fns' ;
5+ import { zonedTimeToUtc } from 'date-fns-tz' ;
6+ import React from 'react' ;
67
78type MultiCommentProps = {
89 x : number ;
@@ -12,10 +13,7 @@ type MultiCommentProps = {
1213
1314export const MultiComment = ( { x, y, ids } : MultiCommentProps ) => {
1415 const {
15- state : {
16- editor,
17- comments,
18- } ,
16+ state : { editor, comments } ,
1917 actions,
2018 } = useOvermind ( ) ;
2119
@@ -78,21 +76,48 @@ export const MultiComment = ({ x, y, ids }: MultiCommentProps) => {
7876 } ) ;
7977
8078 const date = comment =>
81- formatDistanceStrict ( new Date ( comment . insertedAt ) , new Date ( ) , {
82- addSuffix : true ,
83- } ) ;
79+ formatDistanceStrict (
80+ zonedTimeToUtc ( comment . insertedAt , 'Etc/UTC' ) ,
81+ new Date ( ) ,
82+ {
83+ addSuffix : true ,
84+ }
85+ ) ;
8486
8587 return (
8688 < Element as = "ul" css = { list } >
87- { ids . map ( id => {
88- const comment = comments . comments [ editor . currentSandbox . id ] [ id ] ;
89- return (
90- < Element as = "li" key = { id } >
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+ }
97+
98+ if ( dateA > dateB ) {
99+ return - 1 ;
100+ }
101+
102+ return 0 ;
103+ } )
104+ . map ( comment => (
105+ < Element as = "li" key = { comment . id } >
91106 < Element
92107 as = "button"
93108 type = "button"
94- // @ts -ignore
95- onClick = { ( ) => actions . comments . selectComment ( id ) }
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+ } }
96121 css = { item }
97122 >
98123 < Text
@@ -110,8 +135,7 @@ export const MultiComment = ({ x, y, ids }: MultiCommentProps) => {
110135 </ Text >
111136 </ Element >
112137 </ Element >
113- ) ;
114- } ) }
138+ ) ) }
115139 </ Element >
116140 ) ;
117141} ;
0 commit comments