-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(web): extract sidebar as component
- Loading branch information
Showing
4 changed files
with
157 additions
and
132 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import styles from "./index.module.css"; | ||
|
||
import { useContext } from "react"; | ||
import { Link, NavLink } from "react-router-dom"; | ||
import PropTypes from "prop-types"; | ||
|
||
import AddOutlinedIcon from "@mui/icons-material/AddOutlined"; | ||
import GitHubIcon from "@mui/icons-material/GitHub"; | ||
import InfoOutlinedIcon from "@mui/icons-material/InfoOutlined"; | ||
import MailOutlineIcon from "@mui/icons-material/MailOutline"; | ||
|
||
import { ConversationContext } from "@/contexts/conversation"; | ||
|
||
import ChatTab from "../ChatTab"; | ||
|
||
|
||
const Sidebar = ({onShareClick, onDeleteClick}) => { | ||
const { groupedConvs } = useContext(ConversationContext); | ||
|
||
return ( | ||
<aside className={styles.sidebar}> | ||
<Link className={styles.sidebarButton} to="/"> | ||
<AddOutlinedIcon /> | ||
New Chat | ||
</Link> | ||
<nav className={styles.convList}> | ||
{groupedConvs && Object.entries(groupedConvs) | ||
.filter(([, convs]) => convs && convs.length > 0) // Filter out empty lists | ||
.flatMap(([grp, convs]) => ( | ||
[ | ||
<div key={grp}> | ||
<div className={styles.sidebarDateGroup}>{grp}</div> | ||
<ul> | ||
{convs.map((conv) => ( | ||
<li key={conv.id}> | ||
<NavLink | ||
to={`conversations/${conv.id}`} | ||
className={`${styles.sidebarButton} ${({ isActive, isPending }) => isActive ? "active" : isPending ? "pending" : ""}`} | ||
> | ||
{({ isActive }) => ( | ||
<ChatTab chat={conv} isActive={isActive} onShareClick={onShareClick} onDeleteClick={onDeleteClick} /> | ||
)} | ||
</NavLink> | ||
</li> | ||
))} | ||
</ul> | ||
</div> | ||
] | ||
))} | ||
</nav> | ||
<hr className={styles.sidebarBottom} /> | ||
<div className={styles.sidebarBottomGroup}> | ||
<div className={styles.sidebarBottomGroupItem}> | ||
<InfoOutlinedIcon /> | ||
</div> | ||
<div className={styles.sidebarBottomGroupItem}> | ||
<a href="https://github.com/edwardzjl/chatbot" target="_blank" rel="noreferrer"> <GitHubIcon /> </a> | ||
</div> | ||
<div className={styles.sidebarBottomGroupItem}> | ||
<a href="mailto:jameszhou2108@hotmail.com"> | ||
<MailOutlineIcon /> | ||
</a> | ||
</div> | ||
</div> | ||
</aside> | ||
); | ||
}; | ||
|
||
Sidebar.propTypes = { | ||
onShareClick: PropTypes.func.isRequired, | ||
onDeleteClick: PropTypes.func.isRequired, | ||
}; | ||
|
||
|
||
export default Sidebar; |
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,77 @@ | ||
.sidebar { | ||
width: 260px; | ||
padding: 10px; | ||
border: 1px solid rgba(255, 255, 255, .2); | ||
background-color: var(--bg-primary); | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
|
||
.sidebar ul { | ||
list-style-type: none; | ||
margin: 0; | ||
padding: 0; | ||
} | ||
|
||
.sidebar li { | ||
list-style: none; | ||
width: 100%; | ||
} | ||
|
||
.sidebar a { | ||
color: unset; | ||
text-decoration: none; | ||
} | ||
|
||
.convList { | ||
display: flex; | ||
height: 100%; | ||
flex-direction: column; | ||
overflow: auto; | ||
scrollbar-color: var(--border-color) transparent; | ||
scrollbar-width: thin; | ||
} | ||
|
||
.sidebarDateGroup { | ||
color: var(--text-3); | ||
text-align: start; | ||
margin: 10px; | ||
margin-top: 20px; | ||
} | ||
|
||
.sidebarButton { | ||
height: 2rem; | ||
margin: 2px; | ||
padding: 3px; | ||
background-color: var(--bg-primary); | ||
color: var(--text-primary); | ||
border: none; | ||
border-radius: 5px; | ||
transition: ease 0.25s all; | ||
display: flex; | ||
flex-direction: row; | ||
align-items: center; | ||
} | ||
|
||
.sidemenu-button:hover { | ||
background-color: var(--bg-secondary); | ||
} | ||
|
||
.sidemenu-button.active { | ||
background-color: var(--bg-secondary); | ||
} | ||
|
||
.sidebarBottom { | ||
margin-top: auto; | ||
width: 90%; | ||
border: 1px solid var(--border-color); | ||
} | ||
|
||
.sidebarBottomGroup { | ||
margin: 1rem; | ||
display: flex; | ||
} | ||
|
||
.sidebarBottomGroupItem { | ||
margin: 0.5rem; | ||
} |
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