-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0a44707
commit 3eb26a1
Showing
8 changed files
with
232 additions
and
180 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import React from "react"; | ||
import { AppBar, Toolbar, Typography, Box, IconButton, Button, Menu, MenuItem, Avatar } from "@mui/material"; | ||
import MenuIcon from "@mui/icons-material/Menu"; | ||
import AccountCircleIcon from "@mui/icons-material/AccountCircle"; | ||
import md5 from "md5"; | ||
|
||
const AppHeader = ({ isAuthenticated, userEmail, onSignOut, onOpenAuthModal, onToggle }) => { | ||
const [anchorEl, setAnchorEl] = React.useState(null); | ||
|
||
const handleProfileMenuOpen = (event) => { | ||
setAnchorEl(event.currentTarget); | ||
}; | ||
|
||
const handleProfileMenuClose = () => { | ||
setAnchorEl(null); | ||
}; | ||
|
||
return ( | ||
<AppBar position="static"> | ||
<Toolbar> | ||
<IconButton color="inherit" aria-label="open drawer" edge="start" onClick={onToggle}> | ||
<MenuIcon /> | ||
</IconButton> | ||
<Typography sx={{ ml: 2 }} variant="h6" noWrap> | ||
AllChat | ||
</Typography> | ||
<Box sx={{ ml: "auto" }}> | ||
{isAuthenticated ? ( | ||
<div> | ||
<IconButton color="inherit" onClick={handleProfileMenuOpen}> | ||
{userEmail ? ( | ||
<Avatar | ||
src={`https://www.gravatar.com/avatar/${md5( | ||
userEmail.trim().toLowerCase() | ||
)}?d=retro`} | ||
alt="User Avatar" | ||
/> | ||
) : ( | ||
<AccountCircleIcon /> | ||
)} | ||
</IconButton> | ||
<Menu | ||
anchorEl={anchorEl} | ||
open={Boolean(anchorEl)} | ||
onClose={handleProfileMenuClose} | ||
anchorOrigin={{ | ||
vertical: "bottom", | ||
horizontal: "right", | ||
}} | ||
transformOrigin={{ | ||
vertical: "top", | ||
horizontal: "right", | ||
}} | ||
> | ||
<MenuItem onClick={onSignOut}>Sign Out</MenuItem> | ||
</Menu> | ||
</div> | ||
) : ( | ||
<Button color="inherit" onClick={onOpenAuthModal}> | ||
Sign In | ||
</Button> | ||
)} | ||
</Box> | ||
</Toolbar> | ||
</AppBar> | ||
); | ||
}; | ||
|
||
export default AppHeader; |
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,56 @@ | ||
import React from "react"; | ||
import { Box, CircularProgress } from "@mui/material"; | ||
import ReactMarkdown from "react-markdown"; | ||
|
||
const ChatHistory = ({ chatHistory, isModelResponding, chatContainerRef, getFileTypeIcon }) => { | ||
return ( | ||
<Box flex={1} overflow="auto" padding={2} display="flex" flexDirection="column" ref={chatContainerRef}> | ||
{chatHistory.map((chat, index) => ( | ||
<Box | ||
style={{ fontFamily: "PT Sans" }} | ||
key={index} | ||
display="flex" | ||
flexDirection="column" | ||
marginBottom={2} | ||
> | ||
<Box alignSelf="flex-end" bgcolor="#d4edda" color="#155724" padding={1} borderRadius={2}> | ||
{chat.user} | ||
{chat.fileType && getFileTypeIcon(chat.fileType) !== null && ( | ||
<span style={{ fontSize: "3rem" }}>{getFileTypeIcon(chat.fileType)}</span> | ||
)} | ||
{!getFileTypeIcon(chat.fileType) && chat.userImageData && ( | ||
<img | ||
src={`data:image/${chat.fileType.split("/")[1]};base64,${chat.userImageData}`} | ||
alt="User input" | ||
style={{ maxWidth: "100%" }} | ||
/> | ||
)} | ||
</Box> | ||
<Box | ||
alignSelf="flex-start" | ||
bgcolor={chat.error ? "#f8d7da" : "#cff4fc"} | ||
color={chat.error ? "#721c24" : "#0c5460"} | ||
padding={1} | ||
marginTop={1} | ||
borderRadius={2} | ||
> | ||
{isModelResponding && | ||
chat.assistant === null && | ||
chatHistory[chatHistory.length - 1] === chat && <CircularProgress size={20} />} | ||
{chat.assistant !== null && <ReactMarkdown>{chat.assistant}</ReactMarkdown>} | ||
{chat.error && chat.error} | ||
{chat.image && ( | ||
<img | ||
src={`data:image/png;base64,${chat.image.toString("base64")}`} | ||
alt="Model output" | ||
style={{ maxWidth: "100%" }} | ||
/> | ||
)} | ||
</Box> | ||
</Box> | ||
))} | ||
</Box> | ||
); | ||
}; | ||
|
||
export default ChatHistory; |
Oops, something went wrong.