Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Search Bar in Announcements Page #89

Merged
merged 3 commits into from
Sep 21, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 92 additions & 16 deletions frontend/src/components/pages/announcements/AnnouncementsGroups.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
import {
Box,
Flex,
InputGroup,
InputLeftElement,
Input,
Icon,
Tabs,
TabList,
Expand All @@ -14,6 +11,14 @@
TabPanel,
IconButton,
Text,
Menu,
MenuButton,
MenuList,
MenuItem,
Tag,
TagLabel,
TagCloseButton,
HStack,
} from "@chakra-ui/react";
import { Search } from "@mui/icons-material";
import EditNoteIcon from "@mui/icons-material/EditNote";
Expand Down Expand Up @@ -97,6 +102,8 @@
const [processedAnnouncements, setProcessedAnnouncements] =
useState<ProcessedGroupAnnouncements>();

const [searchRooms, setSearchRooms] = useState<number[]>([]);
const [allRooms, setAllRooms] = useState([1, 2, 3, 4, 5, 6]);

Check warning on line 106 in frontend/src/components/pages/announcements/AnnouncementsGroups.tsx

View workflow job for this annotation

GitHub Actions / run-lint

'setAllRooms' is assigned a value but never used
useEffect(() => {
const processedData: ProcessedGroupAnnouncements = {
all: {},
Expand All @@ -122,17 +129,41 @@
const renderGroupTabs = (announcementsGroup: GroupAnnouncements) => {
return (
announcementsGroup &&
Object.keys(announcementsGroup).map((roomKey) => (
<GroupTab
key={roomKey}
roomKey={roomKey}
firstAnnouncement={announcementsGroup[roomKey][0]}
setSelectedGroup={setSelectedGroup}
/>
))
Object.keys(announcementsGroup)
.filter(
(roomKey) =>
!searchRooms ||
searchRooms.length === 0 ||
searchRooms.some((room) =>
roomKey.split(",").map(Number).includes(room),
),
)
.map((roomKey) => (
<GroupTab
key={roomKey}
roomKey={roomKey}
firstAnnouncement={announcementsGroup[roomKey][0]}
setSelectedGroup={setSelectedGroup}
/>
))
);
};

const deleteSearchRoom = (
e: React.MouseEvent<HTMLButtonElement, MouseEvent>,
roomId: number,
) => {
if (searchRooms.includes(roomId)) {
setSearchRooms(searchRooms.filter((room) => room !== roomId));
}
};

const addRoomToSearch = (roomId: number) => {
if (!searchRooms.includes(roomId)) {
setSearchRooms([...searchRooms, roomId]);
}
};

return (
<Box h="100vh" w="100%" borderRight="solid" borderRightColor="gray.300">
<Flex flexDir="column" bg="purple.50" w="100%">
Expand All @@ -144,12 +175,57 @@
mb={4}
bg="purple.50"
>
<InputGroup w="80%" bg="white" ml={5}>
<InputLeftElement pointerEvents="none">
<Box
width="100%"
marginRight="1.25rem"
marginLeft="1.25rem"
position="relative"
w="100%"
bg="white"
h="2.5rem"
borderRadius="0.375rem"
border="1px solid"
borderColor="inherit"
_hover={{ borderColor: "#C5C8D8" }}
_focusVisible={{
borderColor: "477FC8",
boxShadow: "0 0 0 1px #3182ce",
}}
>
<Menu>
<MenuButton width="100%" position="absolute" height="100%" />
<MenuList maxH="40vh" overflow="auto" position="absolute">
{allRooms
.filter((room) => !searchRooms.includes(room))
.map((room) => (
<MenuItem onClick={() => addRoomToSearch(room)} key={room}>
Room {room}
</MenuItem>
))}
</MenuList>
</Menu>

<HStack spacing={2} height="100%" paddingLeft="8px">
<Icon as={Search} color="gray.300" />
</InputLeftElement>
<Input placeholder="Search" />
</InputGroup>
{searchRooms.map((room) => (
<Tag
key={room}
variant="solid"
height="30px"
color="#57469D"
border="1px solid #57469D"
backgroundColor="#F9F7FF"
>
<TagLabel textAlign="center"> Room {room} </TagLabel>
<TagCloseButton
onClick={(e) => deleteSearchRoom(e, room)}
color="#57469D"
/>
</Tag>
))}
</HStack>
</Box>

<IconButton
icon={<EditNoteIcon />}
aria-label="Edit"
Expand Down
Loading