@@ -2,9 +2,15 @@ import React from 'react';
22import { formatDistanceStrict } from 'date-fns' ;
33import { css } from '@styled-system/css' ;
44import { useOvermind } from 'app/overmind' ;
5- import { Text } from '@codesandbox/components' ;
5+ import { Text , Element } from '@codesandbox/components' ;
66
7- export const MultiComment = ( { x, y, ids } ) => {
7+ type MultiCommentProps = {
8+ x : number ;
9+ y : number ;
10+ ids : string [ ] ;
11+ } ;
12+
13+ export const MultiComment = ( { x, y, ids } : MultiCommentProps ) => {
814 const {
915 state : {
1016 comments : { currentComments } ,
@@ -70,38 +76,41 @@ export const MultiComment = ({ x, y, ids }) => {
7076 } ,
7177 } ) ;
7278
79+ const date = comment =>
80+ formatDistanceStrict ( new Date ( comment . insertedAt ) , new Date ( ) , {
81+ addSuffix : true ,
82+ } ) ;
83+
7384 return (
74- < ul css = { list } >
75- { ids . map ( id => (
76- < li key = { id } >
77- < button
78- type = "button"
79- // @ts -ignore
80- onClick = { ( ) => comments . selectComment ( id ) }
81- css = { item }
82- >
83- < Text
84- size = { 2 }
85- weight = "bold"
86- paddingRight = { 2 }
87- css = { css ( {
88- color : 'sideBar.foreground' ,
89- } ) }
85+ < Element as = "ul" css = { list } >
86+ { ids . map ( id => {
87+ const comment = currentComments . find ( c => c . id === id ) ;
88+ return (
89+ < Element as = "li" key = { id } >
90+ < Element
91+ as = "button"
92+ type = "button"
93+ // @ts -ignore
94+ onClick = { ( ) => comments . selectComment ( id ) }
95+ css = { item }
9096 >
91- { currentComments . find ( c => c . id === id ) . user . username }
92- </ Text >
93- < Text size = { 2 } variant = "muted" >
94- { formatDistanceStrict (
95- new Date ( currentComments . find ( c => c . id === id ) . insertedAt ) ,
96- new Date ( ) ,
97- {
98- addSuffix : true ,
99- }
100- ) }
101- </ Text >
102- </ button >
103- </ li >
104- ) ) }
105- </ ul >
97+ < Text
98+ size = { 2 }
99+ weight = "bold"
100+ paddingRight = { 2 }
101+ css = { css ( {
102+ color : 'sideBar.foreground' ,
103+ } ) }
104+ >
105+ { comment . user . username }
106+ </ Text >
107+ < Text size = { 2 } variant = "muted" >
108+ { date ( comment ) }
109+ </ Text >
110+ </ Element >
111+ </ Element >
112+ ) ;
113+ } ) }
114+ </ Element >
106115 ) ;
107116} ;
0 commit comments