1- import { FC } from 'react' ;
1+ import { marked } from 'marked' ;
2+ import { FC , useMemo } from 'react' ;
23import { FaGithub } from 'react-icons/fa' ;
34import { IoMdLogOut } from 'react-icons/io' ;
45import { Link , useNavigate } from 'react-router-dom' ;
@@ -10,6 +11,38 @@ import { useGetActiveUsers, useGetServer } from '../core/api';
1011import { useAuth } from '../core/useAuth' ;
1112import { LoginParams } from '../types' ;
1213
14+ const MessageCard : FC < { content : string ; time ?: string } > = ( { content, time } ) => {
15+ const html = useMemo ( ( ) => {
16+ marked . setOptions ( { breaks : true } ) ;
17+ return marked . parse ( content ) as string ;
18+ } , [ content ] ) ;
19+
20+ return (
21+ < div
22+ style = { {
23+ background : '#f8f9fa' ,
24+ border : '1px solid #e9ecef' ,
25+ borderLeft : '4px solid #ff9a3c' ,
26+ borderRadius : '0.5rem' ,
27+ padding : '0.75rem 1rem' ,
28+ marginBottom : '0.75rem' ,
29+ textAlign : 'left' ,
30+ } }
31+ >
32+ < div
33+ className = "message-content"
34+ style = { { fontSize : '0.9rem' , color : '#333' , lineHeight : '1.5' } }
35+ dangerouslySetInnerHTML = { { __html : html } }
36+ />
37+ { time && (
38+ < div style = { { fontSize : '0.75rem' , color : '#999' , marginTop : '0.25rem' } } >
39+ { new Date ( time ) . toLocaleString ( ) }
40+ </ div >
41+ ) }
42+ </ div >
43+ ) ;
44+ } ;
45+
1346export const HomePage : FC = ( ) => {
1447 const { authenticatedUser, logout } = useAuth ( ) ;
1548 const { n_users } = useGetActiveUsers ( ) ;
@@ -127,24 +160,13 @@ export const HomePage: FC = () => {
127160 🐯 Go to your projects
128161 </ Link >
129162 </ div >
130- < div style = { { maxWidth : '600px' , margin : '1rem auto' } } >
131- { ( messages || [ ] ) . map ( ( msg ) => (
132- < div
133- key = { msg . id }
134- style = { {
135- fontSize : '0.9rem' ,
136- color : '#333' ,
137- } }
138- >
139- < div style = { { color : '#777' } } >
140- { msg . content } •{ ' ' }
141- < span style = { { fontSize : '0.5rem' } } >
142- { new Date ( msg . time || Date . now ( ) ) . toLocaleString ( ) }
143- </ span >
144- </ div >
145- </ div >
146- ) ) }
147- </ div >
163+ { ( messages || [ ] ) . length > 0 && (
164+ < div style = { { maxWidth : '600px' , margin : '1.5rem auto' } } >
165+ { ( messages || [ ] ) . map ( ( msg ) => (
166+ < MessageCard key = { msg . id } content = { msg . content } time = { msg . time } />
167+ ) ) }
168+ </ div >
169+ ) }
148170 </ div >
149171 </ div >
150172 ) }
0 commit comments