import { FaAngleDown, FaCheck, FaMicrophoneAlt, FaPlay } from "react-icons/fa"; import { UserStatus } from "../../models/user"; import Image from "next/image"; import { useEffect, useState } from "react"; import { collection, getFirestore, onSnapshot, query, where, } from "firebase/firestore"; import { Collections } from "../../services/collections"; import { useTeamDashboardContext } from "../../contexts/teamDashboardContext"; import { useAuth } from "../../contexts/authContext"; import Announcement, { AnnouncementState } from "../../models/announcement"; import { getTime } from "../../helpers/dateTime"; import AnnouncementCard from "../AnnouncementCard"; import { Dropdown, Menu, Radio, Tooltip } from "antd"; import { useKeyboardContext } from "../../contexts/keyboardContext"; // for query const yesterday = new Date(); yesterday.setDate(yesterday.getDate() - 1); const db = getFirestore(); export default function Announcements() { const { currUser } = useAuth(); const { team } = useTeamDashboardContext(); const { isRecordingAnnouncement } = useKeyboardContext(); const [annMap, setAnnMap] = useState>( new Map() ); // SECTION: LISTENER for Announcements useEffect(() => { /** * QUERY: * all announcements for the team in the past 24 hours for now * order createdDate desc * */ const q = query( collection(db, Collections.announcements), where("teamId", "==", team.id), where("createdDate", ">", yesterday) ); // return unsubscribe return onSnapshot(q, (snapshot) => { snapshot.docChanges().forEach((change) => { let updatedOrNewAnn = change.doc.data() as Announcement; updatedOrNewAnn.id = change.doc.id; if (change.type === "added" || change.type === "modified") { // update rooms map setAnnMap((prevMap) => { return new Map(prevMap.set(updatedOrNewAnn.id, updatedOrNewAnn)); }); } if (change.type === "removed") { // going to more so be resolved or deleted console.log("Removed annoncement: ", updatedOrNewAnn); } }); }); }, []); const allAnn = Array.from(annMap.values()); // sort the announcements allAnn.sort(function (a, b) { return getTime(b.createdDate.toDate()) - getTime(a.createdDate.toDate()); }); const activeAnn = allAnn.filter( (ann) => ann.state == AnnouncementState.active ); const resolvedAnn = allAnn.filter( (ann) => ann.state == AnnouncementState.resolved ); const [selectedTabPane, setSelectedTabPane] = useState( AnnouncementState.active ); function getTabContent() { switch (selectedTabPane) { case AnnouncementState.active: return ( <> {activeAnn.map((ann) => { return ; })} ); case AnnouncementState.resolved: return ( <> {resolvedAnn.map((ann) => { return ; })} ); } } const TimePeriodFilterMenu = ( Past Week (Coming Soon) This Month (Coming Soon) ); return (
ANNOUNCEMENTS updates, pep talks, blockers, reminders {/* tab pane */} setSelectedTabPane(e.target.value)} > {AnnouncementState.active}{" "} {activeAnn.length > 0 ? activeAnn.length : ""} {AnnouncementState.resolved}{" "} {activeAnn.length > 0 ? activeAnn.length : ""} 24 HRS {/* */}
{getTabContent()}
); }