diff --git a/frontend/src/components/pages/announcements/AnnouncementsGroups.tsx b/frontend/src/components/pages/announcements/AnnouncementsGroups.tsx index d1fc947..afad6ab 100644 --- a/frontend/src/components/pages/announcements/AnnouncementsGroups.tsx +++ b/frontend/src/components/pages/announcements/AnnouncementsGroups.tsx @@ -34,7 +34,12 @@ interface ProcessedGroupAnnouncements { export const formatRooms = (roomIDs: number[]) => { // Map each room ID to its formatted string - const formattedRooms = roomIDs.map((id) => `Room ${id}`); + const formattedRooms = roomIDs.map((id) => { + if (id === 0) { + return "New Announcement"; + } + return `Room ${id}`; + }); // Join the formatted room strings with commas return formattedRooms.join(", "); }; @@ -43,12 +48,17 @@ const GroupTab = ({ roomKey, firstAnnouncement, setSelectedGroup, + isDraft, + selectedRooms, }: { roomKey: string; - firstAnnouncement: Announcement; + firstAnnouncement: Announcement | null; setSelectedGroup: React.Dispatch>; + isDraft: boolean; + selectedRooms?: number[] | null; }) => { - const rooms = roomKey.split(",").map(Number); + const rooms = (selectedRooms && selectedRooms.length > 0)? selectedRooms: roomKey.split(",").map(Number); + return ( setSelectedGroup(roomKey)} @@ -58,7 +68,7 @@ const GroupTab = ({ borderBottomColor="gray.300" _hover={{ bg: "purple.100", cursor: "pointer" }} > - + - - - {formatRooms(rooms)} - - {moment(firstAnnouncement.createdAt).fromNow()} + + + {formatRooms(rooms)} + + {firstAnnouncement? moment(firstAnnouncement.createdAt).fromNow(): moment(Date.now()).fromNow()} - {truncateMessage(firstAnnouncement.message, 60)} + + {truncateMessage(firstAnnouncement? firstAnnouncement.message: "", 60)} + @@ -93,10 +105,12 @@ const GroupTab = ({ const GroupList: React.FC<{ announcements: GroupAnnouncements; setSelectedGroup: React.Dispatch>; -}> = ({ announcements, setSelectedGroup }) => { + addingNewRoom: boolean; + setAddingNewRoom: React.Dispatch>; + selectedRooms: number[]; +}> = ({ announcements, setSelectedGroup, addingNewRoom, setAddingNewRoom, selectedRooms}) => { const [processedAnnouncements, setProcessedAnnouncements] = useState(); - useEffect(() => { const processedData: ProcessedGroupAnnouncements = { all: {}, @@ -106,6 +120,7 @@ const GroupList: React.FC<{ Object.keys(announcements).forEach((key) => { const rooms = key.split(",").map((room) => parseInt(room.trim(), 10)); const announcementData = announcements[key]; + if (rooms.length === 1) { // Add announcement to 'all' and 'private' if there is only 1 room processedData.all[key] = announcementData; @@ -116,23 +131,38 @@ const GroupList: React.FC<{ processedData.groups[key] = announcementData; } }); + setProcessedAnnouncements(processedData); }, [announcements]); const renderGroupTabs = (announcementsGroup: GroupAnnouncements) => { return ( announcementsGroup && + [addingNewRoom? + : <>].concat( Object.keys(announcementsGroup).map((roomKey) => ( - )) + ))) ); }; + const addRoom = () => { + setAddingNewRoom(true); + } + return ( @@ -159,6 +189,7 @@ const GroupList: React.FC<{ border="solid" borderColor="gray.200" mr={5} + onClick={addRoom} /> diff --git a/frontend/src/components/pages/announcements/AnnouncementsPage.tsx b/frontend/src/components/pages/announcements/AnnouncementsPage.tsx index 4c5bb35..b3de832 100644 --- a/frontend/src/components/pages/announcements/AnnouncementsPage.tsx +++ b/frontend/src/components/pages/announcements/AnnouncementsPage.tsx @@ -9,6 +9,8 @@ import { announcementsMockData } from "../../../mocks/notifications"; const AnnouncementsPage = (): React.ReactElement => { const [announcements, setAnnouncements] = useState({}); const [selectedGroup, setSelectedGroup] = useState(""); + const [addingNewRoom, setAddingNewRoom] = useState(false); + const [selectedRooms, setSelectedRooms] = useState([]); useEffect(() => { // TODO: Fetch announcements from API @@ -21,10 +23,17 @@ const AnnouncementsPage = (): React.ReactElement => { diff --git a/frontend/src/components/pages/announcements/AnnouncementsView.tsx b/frontend/src/components/pages/announcements/AnnouncementsView.tsx index 87afd71..748813d 100644 --- a/frontend/src/components/pages/announcements/AnnouncementsView.tsx +++ b/frontend/src/components/pages/announcements/AnnouncementsView.tsx @@ -9,7 +9,16 @@ import { Avatar, Heading, Input, + Menu, + MenuButton, + MenuList, + MenuItem, + Tag, + HStack, + TagLabel, + TagCloseButton, } from "@chakra-ui/react"; +import AddCircleOutlineOutlinedIcon from '@mui/icons-material/AddCircleOutlineOutlined'; import InfoOutlinedIcon from "@mui/icons-material/InfoOutlined"; import { GroupAnnouncements } from "../../../types/NotificationTypes"; @@ -56,13 +65,22 @@ const MessageInput = ({ type Props = { announcements: GroupAnnouncements; selectedGroup: string; + addingNewRoom: boolean; + setAddingNewRoom: React.Dispatch>; + selectedRooms: number[]; + setSelectedRooms: React.Dispatch>; }; -const AnnouncementsList = ({ announcements, selectedGroup }: Props) => { +type PropsList = { + announcements: GroupAnnouncements; + selectedGroup: string; +}; + +const AnnouncementsList = ({ announcements, selectedGroup }: PropsList) => { if (selectedGroup.length === 0) { return null; } - + return ( {announcements[selectedGroup].map((announcement, index) => ( @@ -99,8 +117,59 @@ const AnnouncementsList = ({ announcements, selectedGroup }: Props) => { const AnnouncementsView = ({ announcements, selectedGroup, + addingNewRoom, + setAddingNewRoom, + selectedRooms, + setSelectedRooms }: Props): React.ReactElement => { const rooms = selectedGroup.split(",").map(Number); + const [allRooms, setAllRooms] = useState([1,2,3,4,5,6]); + + const addRoomToNewRoom = (roomId: number) => { + if(!selectedRooms.includes(roomId)) { + setSelectedRooms([...selectedRooms, roomId]); + } + } + + const deleteRoomSelected = (roomId: number) => { + if(selectedRooms.includes(roomId)) { + setSelectedRooms(selectedRooms.filter(room => room !== roomId)); + } + } + + const handlePost = (message: string) => { + if(addingNewRoom && selectedRooms.length > 0) { + setSelectedRooms([]); + setAddingNewRoom(false); + } + } + + const formatHeader = (roomIDs: number[]) => { + if(addingNewRoom && selectedGroup === "0"){ + return + + {selectedRooms.map((room) => ( + + Room {room} + deleteRoomSelected(room)} color='#57469D'/> + + ))} + + + + + + {allRooms.filter(room => !selectedRooms.includes(room)).map((room) => ( + addRoomToNewRoom(room)} key={room}>Room {room} + ))} + + + + + } + return "All Rooms"; + }; + return ( @@ -111,9 +180,10 @@ const AnnouncementsView = ({ display="flex" alignItems="center" justifyContent="space-between" + h="10vh" > -

- {selectedGroup === "" ? "All Rooms" : formatRooms(rooms)} +

+ {selectedGroup === "" || selectedGroup === "0" ? formatHeader(rooms) : formatRooms(rooms)}

- + />} - {}} /> +