import { BsThreeDots } from "react-icons/bs"; import { FaAngleDown, FaCode, FaFileImage, FaPlus } from "react-icons/fa"; import Image from "next/image"; import { Dropdown, Menu, Radio, Tooltip } from "antd"; import { ShowModalType, useKeyboardContext, } from "../../contexts/keyboardContext"; import CreateOrUpdateLink from "../Modals/CreateOrUpdateLink"; import { useEffect, useState } from "react"; import LinkCard from "../LinkCard"; import { Collections } from "../../services/collections"; import { collection, getFirestore, onSnapshot, orderBy, query, where, } from "firebase/firestore"; import { useTeamDashboardContext } from "../../contexts/teamDashboardContext"; import Link, { LinkState } from "../../models/link"; import { useAuth } from "../../contexts/authContext"; const lastWeek = new Date(); lastWeek.setDate(lastWeek.getDate() - 7); const db = getFirestore(); export default function Links() { const { currUser } = useAuth(); const { handleModalType } = useKeyboardContext(); const { team } = useTeamDashboardContext(); const [linksMap, setLinksMap] = useState>( new Map() ); // SECTION: LISTENER for LINKS useEffect(() => { /** * QUERY: * all links for the team in the past 7 days * order createdDate desc * */ const q = query( collection(db, Collections.links), where("teamId", "==", team.id), where("createdDate", ">", lastWeek), orderBy("createdDate", "desc") ); // return unsubscribe return onSnapshot(q, (snapshot) => { snapshot.docChanges().forEach((change) => { let updatedOrNewLink = change.doc.data() as Link; updatedOrNewLink.id = change.doc.id; if (change.type === "added" || change.type === "modified") { setLinksMap((prevMap) => { return new Map(prevMap.set(updatedOrNewLink.id, updatedOrNewLink)); }); } if (change.type === "removed") { console.log("Removed link: ", updatedOrNewLink); } }); }); }, []); const TimePeriodFilterMenu = ( Past 24 Hours (Coming Soon) This Month (Coming Soon) ); const [selectedTabPane, setSelectedTabPane] = useState( LinkTypeFilter.me ); const allLinks = Array.from(linksMap.values()); const meLinks = allLinks.filter((link) => { // if archived or deleted, don't show if (link.state != LinkState.active) { return false; } // if I am the sender, then also show, but only if it's me sending to a specific person if (link.createdByUserId == currUser.uid && link.recipients?.length > 0) { return true; } // if I am a receiver if (link.recipients?.includes(currUser.uid)) { return true; } return false; }); const teamLinks = allLinks.filter((link) => { // not archived and does not have a recipients list if (link.state == LinkState.active && !link.recipients) { return true; } return false; }); const archivedLinks = allLinks.filter( (link) => link.state == LinkState.archived ); function getFilteredContent() { switch (selectedTabPane) { case LinkTypeFilter.me: return meLinks; case LinkTypeFilter.team: return teamLinks; case LinkTypeFilter.archived: return archivedLinks; default: return allLinks; } } return (
{/* header row */} {/* modal */} DRAWER links: jira tickets, drive files/folders, powerpoints... {meLinks.length > 6 || teamLinks.length > 6 ? ( Make sure to{" "} {"clear out your drawer and your team's"} {" "} so that you are focused on this week. ) : ( <> )}
setSelectedTabPane(e.target.value)} > {LinkTypeFilter.me}{" "} {meLinks.length > 0 ? meLinks.length : ""} {LinkTypeFilter.team}{" "} {teamLinks.length} {LinkTypeFilter.favorites}{" "} {/* {liveRooms.length > 0 ? fa.length : ""} */} {LinkTypeFilter.archived}{" "} {archivedLinks.length > 0 ? archivedLinks.length : ""}
Week
{/* table of links */}
{getFilteredContent().map((link) => ( ))}
); } enum LinkTypeFilter { team = "team", me = "me", favorites = "favorites", archived = "archived", }