From 2282ec27cdc78abd815780a292428ad692b9e741 Mon Sep 17 00:00:00 2001 From: Arjun Patel Date: Sun, 6 Feb 2022 17:24:14 -0800 Subject: [PATCH] up0dating tldr very simple without a whole modal --- packages/common/models/conversation.ts | 2 + .../common/services/conversationService.ts | 16 +++ .../components/MainTabsOrPages/ViewConvo.tsx | 111 +++++++++++++++++- 3 files changed, 125 insertions(+), 4 deletions(-) diff --git a/packages/common/models/conversation.ts b/packages/common/models/conversation.ts index 8f703ea..3106294 100644 --- a/packages/common/models/conversation.ts +++ b/packages/common/models/conversation.ts @@ -19,6 +19,8 @@ export default class Conversation { createdDate: Timestamp = Timestamp.now(); createdByUserId: string; + lastUpdatedBy?: string; // some sort of security data collection whenever updating convo + constructor( _createdByUserId: string, _name: string, diff --git a/packages/common/services/conversationService.ts b/packages/common/services/conversationService.ts index 9426bc4..20e08d6 100644 --- a/packages/common/services/conversationService.ts +++ b/packages/common/services/conversationService.ts @@ -166,4 +166,20 @@ export default class ConversationService { ); }); } + + async updateTldr(convoId: string, newTldr: string, updateUserId: string) { + // todo make sure that this user is allowed to update it + const docRef = doc(this.db, Collections.conversations, convoId); + await setDoc( + docRef, + { + tldr: newTldr, + lastActivityDate: serverTimestamp(), + lastUpdatedBy: updateUserId, + }, + { merge: true } + ); + + return false; + } } diff --git a/packages/web/components/MainTabsOrPages/ViewConvo.tsx b/packages/web/components/MainTabsOrPages/ViewConvo.tsx index 56ab2a0..327d78b 100644 --- a/packages/web/components/MainTabsOrPages/ViewConvo.tsx +++ b/packages/web/components/MainTabsOrPages/ViewConvo.tsx @@ -46,6 +46,7 @@ import { import { firestoreDb as db } from "../../services/firebaseService"; import Collections from "@nirvana/common/services/collections"; import TimelineAudioClip from "../Conversations/TimelineAudioClip"; +import Modal from "antd/lib/modal/Modal"; const testDrawerItems: { linkType: LinkType; @@ -76,6 +77,12 @@ const testDrawerItems: { const AUDIO_CLIP_FETCH_LIMIT = 50; +enum ConvoModal { + na = "na", + editTldr = "editTldr", + adminEdit = "adminEdit", +} + export default function ViewConvo(props: { conversationId: string }) { const { currUser } = useAuth(); @@ -83,6 +90,10 @@ export default function ViewConvo(props: { conversationId: string }) { const endOfTimeline = useRef(); + const [currentConvoModal, setCurrConvoModal] = useState( + ConvoModal.na + ); + const router = useRouter(); // auth if do not have this conversation in react cache, then we are not authorized @@ -170,8 +181,57 @@ export default function ViewConvo(props: { conversationId: string }) { } }; + const handleCloseModal = () => { + setCurrConvoModal(ConvoModal.na); + }; + + const handleEditTldr = () => { + console.log("updating tldr with modal"); + }; + + const [editTldrMode, setEditTldrMode] = useState(false); + const [newTldr, setNewTldr] = useState(""); + const [isSubmitting, setIsSubmitting] = useState(false); + + const saveNewTldr = async (e) => { + if (!newTldr) { + toast.error("can't have a blank tldr!"); + return; + } + + setIsSubmitting(true); + + try { + await conversationService.updateTldr( + props.conversationId, + newTldr, + currUser!.uid + ); + + toast.success("Updated TLDR;"); + + setEditTldrMode(false); + } catch (error) { + toast.error("problem in updating tldr"); + console.error(error); + } + + setIsSubmitting(false); + }; + return ( <> + {/* +

Some contents...

+

Some contents...

+

Some contents...

+
*/} +
{/* convo name and action buttons on top */}
@@ -268,9 +328,52 @@ export default function ViewConvo(props: { conversationId: string }) { - {convo?.tldr && ( - - tldr: {convo?.tldr} + {convo?.tldr && !editTldrMode ? ( + <> + + setEditTldrMode(true)} + className="flex flex-row group items-center" + > + + tldr; + + + + + + + + + {convo?.tldr} + + + ) : ( + +