Skip to content

Commit

Permalink
Merge pull request #1124 from ericzhy0815/fixFriendsDarkMode
Browse files Browse the repository at this point in the history
Fixed issues in friends modal
  • Loading branch information
JiaqiWang18 authored May 16, 2024
2 parents 88b52e6 + e9983f6 commit 77cc9b9
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 49 deletions.
111 changes: 68 additions & 43 deletions static/js/redux/ui/modals/PeerModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { useActions, useAppDispatch, useAppSelector } from "../../hooks";
import { signupModalActions } from "../../state/slices/signupModalSlice";
import { userInfoActions } from "../../state/slices";
import { peerModalActions } from "../../state/slices/peerModalSlice";
import { selectSlotColorData } from "../../state/slices/themeSlice";
import { selectSlotColorData, selectTheme } from "../../state/slices/themeSlice";
import { parseInstructors } from "../CourseModalSection";
import { Box, Tab, Tabs } from "@mui/material";
import RequestsReceived from "./PeerModalComponents/RequestsReceived";
Expand Down Expand Up @@ -49,6 +49,10 @@ const emptyState = (
</div>
);

/**
* Why is this called ghost card
*/

const ghostCard = (
<div className="ghost peer-card">
<div className="peer-card-wrapper">
Expand Down Expand Up @@ -113,6 +117,9 @@ const PeerModal = () => {
const slotColorData = useAppSelector(selectSlotColorData);
const [tab, setTab] = useState(0);

const theme = useAppSelector(selectTheme);
const isDarkMode = theme && theme.name && theme.name === "dark"; // whether dark mode is toggled

const handleChange = (event: React.SyntheticEvent, newValue: number) => {
setTab(newValue);
};
Expand Down Expand Up @@ -315,52 +322,70 @@ const PeerModal = () => {
}

const sideBar = (
<div>
<Box
<Box
sx={{
flexGrow: 1,
bgcolor: isDarkMode ? "#2d2e32" : "background.paper",
display: "flex",
height: "100%",
}}
>
<Tabs
orientation="vertical"
variant="fullWidth"
value={tab || false}
onChange={handleChange}
aria-label="Vertical tabs example"
sx={{
flexGrow: 1,
bgcolor: "background.paper",
display: "flex",
height: "100%",
borderRight: 1,
borderColor: isDarkMode ? "#A9A9A9" : "divider",
minWidth: "100px",
}}
>
<Tabs
orientation="vertical"
variant="fullWidth"
value={tab || false}
onChange={handleChange}
aria-label="Vertical tabs example"
sx={{
borderRight: 1,
borderColor: "divider",
minWidth: "100px",
}}
>
<Tab label="Classmates" {...a11yProps(0)} />
<Tab label="Find New Friends" {...a11yProps(1)} />
<Tab label="Current Friends" {...a11yProps(2)} />
<Tab label="Requests Received" {...a11yProps(3)} />
<Tab label="Requests Sent" {...a11yProps(4)} />
</Tabs>
<Box sx={{ flexGrow: 1 }}>
<TabPanel value={tab} index={0}>
{display}
</TabPanel>
<TabPanel value={tab} index={1}>
<FindNewFriends />
</TabPanel>
<TabPanel value={tab} index={2}>
<CurrentFriends />
</TabPanel>
<TabPanel value={tab} index={3}>
<RequestsReceived />
</TabPanel>
<TabPanel value={tab} index={4}>
<RequestsSent />
</TabPanel>
</Box>
<Tab
label="Classmates"
{...a11yProps(0)}
sx={isDarkMode ? { color: "#ceddeb" } : undefined} // dark mode font color
/>
<Tab
label="Find New Friends"
{...a11yProps(1)}
sx={isDarkMode ? { color: "#ceddeb" } : undefined}
/>
<Tab
label="Current Friends"
{...a11yProps(2)}
sx={isDarkMode ? { color: "#ceddeb" } : undefined}
/>
<Tab
label="Requests Received"
{...a11yProps(3)}
sx={isDarkMode ? { color: "#ceddeb" } : undefined}
/>
<Tab
label="Requests Sent"
{...a11yProps(4)}
sx={isDarkMode ? { color: "#ceddeb" } : undefined}
/>
</Tabs>
<Box sx={{ flexGrow: 1, overflowY: "auto" }}>
<TabPanel value={tab} index={0}>
{display}
</TabPanel>
<TabPanel value={tab} index={1}>
<FindNewFriends />
</TabPanel>
<TabPanel value={tab} index={2}>
<CurrentFriends />
</TabPanel>
<TabPanel value={tab} index={3}>
<RequestsReceived />
</TabPanel>
<TabPanel value={tab} index={4}>
<RequestsSent />
</TabPanel>
</Box>
</div>
</Box>
);

return (
Expand Down
28 changes: 22 additions & 6 deletions static/js/redux/ui/modals/PeerModalComponents/FindNewFriends.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useState, useEffect } from "react";
import { selectTheme } from "../../../state/slices/themeSlice";
import {
List,
ListItem,
Expand All @@ -19,12 +20,15 @@ import {
} from "../../../constants/endpoints";
import Cookie from "js-cookie";
import { User } from "./Types";
import { useAppSelector } from "../../../hooks";

const FindNewFriends = () => {
const [searchResults, setSearchResults] = useState<User[]>([]);
const [searchTerm, setSearchTerm] = useState("");
const [isSearching, setIsSearching] = useState(false);
const [requestSent, setRequestSent] = useState<{ [key: string]: boolean }>({});
const theme = useAppSelector(selectTheme);
const isDarkMode = theme && theme.name && theme.name === "dark";

useEffect(() => {
const fetchFriendRequestsSent = async () => {
Expand All @@ -42,11 +46,6 @@ const FindNewFriends = () => {

useEffect(() => {
const fetchSearchResults = async () => {
if (searchTerm === "") {
setSearchResults([]);
setIsSearching(false);
return;
}
setIsSearching(true);
const response = await fetch(getSearchFriendsEndpoint(searchTerm));
const responseJson = await response.json();
Expand Down Expand Up @@ -86,9 +85,26 @@ const FindNewFriends = () => {
onChange={handleSearchChange}
margin="normal"
fullWidth
// darkmode pallete for fonts and border
{...(isDarkMode && {
InputLabelProps: { style: { color: "white" } },
sx: {
"& .MuiOutlinedInput-root": {
"& fieldset": {
borderColor: "darkgrey",
},
"&:hover fieldset": {
borderColor: "darkgrey",
},
"&.Mui-focused fieldset": {
borderColor: "darkgrey",
},
},
},
})}
/>
</Box>
{isSearching && <CircularProgress />}
{isSearching && searchTerm.length > 0 && <CircularProgress />}
{!isSearching && searchTerm && searchResults.length > 0 && (
<List
sx={{ width: "100%", maxWidth: 600, maxHeight: "60%", overflowY: "auto" }}
Expand Down

0 comments on commit 77cc9b9

Please sign in to comment.