-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Refactor code for event log, move out to own component - Split event log in seperat functions - Use HTML parser for Link preview
- Loading branch information
Showing
13 changed files
with
346 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { Box, IconButton, Paper, Tooltip } from '@mui/material'; | ||
|
||
|
||
import { RootState } from '../store/store'; | ||
import { useSelector } from 'react-redux'; | ||
import { useEffect, useMemo, useState } from 'react'; | ||
import AutoStoriesIcon from '@mui/icons-material/AutoStories'; | ||
import KeyboardDoubleArrowRightIcon from '@mui/icons-material/KeyboardDoubleArrowRight'; | ||
import React from 'react'; | ||
|
||
interface ChatInfoBarProps { | ||
onShowLog: (showLog: boolean) => void; | ||
} | ||
|
||
const ChatInfoBar: React.FC<ChatInfoBarProps> = React.memo(({ onShowLog }) => { | ||
const [showLog, setShowLog] = useState(false); | ||
|
||
const currentChannelId = useSelector((state: RootState) => state.reducer.userInfo.currentUser?.channel_id); | ||
const channelInfo = useSelector((state: RootState) => state.reducer.channel.find(e => e.channel_id === currentChannelId)); | ||
|
||
const eventLogIcon = useMemo(() => { | ||
if (!showLog) return (<AutoStoriesIcon sx={{ fontSize: 20 }} />); | ||
else return (<KeyboardDoubleArrowRightIcon sx={{ fontSize: 20 }} />); | ||
}, [showLog]); | ||
|
||
useEffect(() => { | ||
onShowLog(showLog); | ||
}, [showLog, onShowLog]); | ||
|
||
return ( | ||
<Box sx={{ flexShrink: 1 }}> | ||
<Paper elevation={0} sx={{ backgroundImage: `url(${channelInfo?.channelImage})`, backgroundSize: 'contain' }}> | ||
<Box sx={{ display: 'flex', flexDirection: 'row', alignItems: 'center', backdropFilter: 'blur(20px)', textShadow: '1px 1px #000' }}> | ||
<Box sx={{ flexGrow: 1, paddingLeft: 1 }}> | ||
{channelInfo?.name} | ||
</Box> | ||
<Box sx={{ flexGrow: 0 }}> | ||
<Box sx={{ display: 'flex', flexDirection: 'row', alignItems: 'center' }}> | ||
<Tooltip title={showLog ? 'Hide Log' : 'Show Log'}> | ||
<IconButton size="small" onClick={() => setShowLog(!showLog)}> | ||
{eventLogIcon} | ||
</IconButton> | ||
</Tooltip> | ||
</Box> | ||
</Box> | ||
</Box> | ||
</Paper> | ||
</Box> | ||
|
||
) | ||
}); | ||
|
||
export default ChatInfoBar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { Box, IconButton, Paper, Table, TableBody, TableCell, TableContainer, TableHead, TableRow, Tooltip } from '@mui/material'; | ||
|
||
|
||
import { RootState } from '../store/store'; | ||
import { useSelector } from 'react-redux'; | ||
import React, { useEffect, useRef } from 'react'; | ||
import dayjs from 'dayjs'; | ||
|
||
interface EventLogProps { | ||
showLog: boolean; | ||
} | ||
|
||
const EventLog: React.FC<EventLogProps> = React.memo(({ showLog }) => { | ||
const eventLog = useSelector((state: RootState) => state.eventLog); | ||
const eventLogRef = useRef<HTMLDivElement | null>(null); | ||
|
||
useEffect(() => { | ||
if (showLog && eventLogRef.current) { | ||
eventLogRef.current.scrollTo({ top: eventLogRef.current.scrollHeight, behavior: 'smooth' }); | ||
} | ||
}, [showLog, eventLog, eventLogRef]); | ||
|
||
if (!showLog) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Box sx={{ | ||
maxWidth: '300px', | ||
display: 'flex', | ||
flexDirection: 'column', | ||
flex: 1, | ||
overflowY: 'auto', | ||
}} > | ||
<Paper | ||
elevation={0} | ||
sx={{ flexGrow: 1, overflowX: 'hidden' }} | ||
ref={eventLogRef} | ||
> | ||
<Box sx={{ display: 'flex', flexDirection: 'row', alignItems: 'flex-start', height: '100%' }}> | ||
<Box sx={{ flexGrow: 1, paddingLeft: 0 }}> | ||
<TableContainer component={Paper}> | ||
<Table sx={{ minWidth: 300 }} aria-label="messaeg log" size="small" stickyHeader> | ||
<TableHead> | ||
<TableRow> | ||
<TableCell>Timestamp</TableCell> | ||
<TableCell align="left">Message</TableCell> | ||
</TableRow> | ||
</TableHead> | ||
<TableBody> | ||
{eventLog.map((row, i) => { | ||
const timestamp = dayjs(row.timestamp).format('HH:mm:ss'); | ||
|
||
return ( | ||
<TableRow key={'' + i + row.timestamp} sx={{ '&:last-child td, &:last-child th': { border: 0 } }}> | ||
<TableCell component="th" scope="row"> | ||
{timestamp} | ||
</TableCell> | ||
<TableCell align="left">{row.logMessage}</TableCell> | ||
</TableRow> | ||
) | ||
})} | ||
</TableBody> | ||
</Table> | ||
</TableContainer> | ||
</Box> | ||
</Box> | ||
</Paper> | ||
</Box> | ||
) | ||
}); | ||
|
||
export default EventLog; |
Oops, something went wrong.