From 5655df93917d59764e4809aca4b1fdbe1ffaeac0 Mon Sep 17 00:00:00 2001 From: Arjun Patel Date: Mon, 17 Jan 2022 15:46:28 -0800 Subject: [PATCH] updating to have statuses for rooms --- components/Dashboard/Rooms.tsx | 4 ++-- components/Modals/CreateRoom.tsx | 6 +++++- components/RoomCard.tsx | 5 ++++- components/RoomTypeTag.tsx | 23 ++++++++++++++++++++++- models/room.ts | 8 +++++++- services/roomService.tsx | 14 ++++++++++++-- 6 files changed, 52 insertions(+), 8 deletions(-) diff --git a/components/Dashboard/Rooms.tsx b/components/Dashboard/Rooms.tsx index 568c1d5..526dcf3 100644 --- a/components/Dashboard/Rooms.tsx +++ b/components/Dashboard/Rooms.tsx @@ -19,7 +19,7 @@ import { } from "firebase/firestore"; import { Collections } from "../../services/collections"; import { useTeamDashboardContext } from "../../contexts/teamDashboardContext"; -import Room, { RoomType } from "../../models/room"; +import Room, { RoomStatus, RoomType } from "../../models/room"; import { useAuth } from "../../contexts/authContext"; import { Radio } from "antd"; import RoomCard from "../RoomCard"; @@ -158,7 +158,7 @@ export default function DashboardRoom() { (room) => room.type == RoomType.recurring ); const archivedRooms = allRooms.filter( - (room) => room.type == RoomType.archived + (room) => room.status == RoomStatus.archived ); function getRoomContent() { diff --git a/components/Modals/CreateRoom.tsx b/components/Modals/CreateRoom.tsx index 718a65f..21d2329 100644 --- a/components/Modals/CreateRoom.tsx +++ b/components/Modals/CreateRoom.tsx @@ -7,7 +7,7 @@ import { useKeyboardContext, } from "../../contexts/keyboardContext"; import { useTeamDashboardContext } from "../../contexts/teamDashboardContext"; -import Room, { RoomType } from "../../models/room"; +import Room, { RoomStatus, RoomType } from "../../models/room"; import RoomService from "../../services/roomService"; const { Option } = Select; @@ -46,6 +46,10 @@ export default function CreateRoomModal() { newRoom.attachments = [roomAttachment]; } + if (roomType == RoomType.now) { + newRoom.status = RoomStatus.live; + } + newRoom.approximateDateTime = roomAppxDateTime; newRoom.link = roomLink; newRoom.members = [...membersSelected, currUser.uid]; // add currUser to the list of "people" diff --git a/components/RoomCard.tsx b/components/RoomCard.tsx index 1778da5..2ba056c 100644 --- a/components/RoomCard.tsx +++ b/components/RoomCard.tsx @@ -208,7 +208,10 @@ export default function RoomCard(props: IRoomCardProps) { {/* room status and link(s) */} - + + + live + + ); + } else if (props.roomStatus == RoomStatus.archived) { + return ( + + archived + + ); + } + + // if it's just empty and not empty, then go ahead and show the right type switch (props.roomType) { case RoomType.now: return ( diff --git a/models/room.ts b/models/room.ts index 035e043..a815db3 100644 --- a/models/room.ts +++ b/models/room.ts @@ -15,6 +15,7 @@ export default class Room { attachments: string[]; // the links themselves (NOT Ids)...there will be duplicate entries in the attachments table which will be created type: RoomType; + status: RoomStatus = RoomStatus.empty; approximateDateTime: string; // vaguely say when the meeting should be...give user pointers @@ -30,5 +31,10 @@ export enum RoomType { now = "now", scheduled = "scheduled", // one time sort of standard meeting recurring = "recurring", //daily standup - archived = "archived", // this room is dead or over +} + +export enum RoomStatus { + live = "live", + empty = "empty", + archived = "archived", // user marks it over } diff --git a/services/roomService.tsx b/services/roomService.tsx index f07e07a..f20ddaa 100644 --- a/services/roomService.tsx +++ b/services/roomService.tsx @@ -7,7 +7,7 @@ import { serverTimestamp, setDoc, } from "firebase/firestore"; -import Room from "../models/room"; +import Room, { RoomStatus } from "../models/room"; import { Collections } from "./collections"; export default class RoomService { @@ -21,10 +21,20 @@ export default class RoomService { } async updateMembersInRoom(roomId: string, newMembersInRoom: string[]) { + // if the room is going to be empty, then change status accordingly + var status: RoomStatus = RoomStatus.live; + if (newMembersInRoom.length == 0) { + status = RoomStatus.empty; + } + const docRef = doc(this.db, Collections.rooms, roomId); await setDoc( docRef, - { membersInRoom: newMembersInRoom, lastUpdatedDate: serverTimestamp() }, + { + status, + membersInRoom: newMembersInRoom, + lastUpdatedDate: serverTimestamp(), + }, { merge: true } ); }