From fea4713862210b931c01174efbeb63f5871d4b91 Mon Sep 17 00:00:00 2001 From: Joshua Mbogo <55801923+mbogo-mit@users.noreply.github.com> Date: Fri, 29 Dec 2023 12:13:51 -0500 Subject: [PATCH] adding functionality for websocket on doc view --- src/components/AnnotationCard/AnnotationCard.js | 5 +++-- src/pages/documents/[slug]/index.jsx | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/components/AnnotationCard/AnnotationCard.js b/src/components/AnnotationCard/AnnotationCard.js index fbcf34c..fd45cf6 100644 --- a/src/components/AnnotationCard/AnnotationCard.js +++ b/src/components/AnnotationCard/AnnotationCard.js @@ -196,7 +196,7 @@ function AnnotationCard({ $(`.annotation-highlighted-text[annotation-id='${id}']`).removeClass('active'); } - function SendNewAnnotationWebsocketNotification(anno, new_anno) { + function SendNewAnnotationWebsocketNotification(anno, new_anno, side) { const { permissions: { private: priv, sharedTo } } = anno; @@ -212,6 +212,7 @@ function AnnotationCard({ "_notification": { "annotation": anno, "new_annotation": new_anno, + "side": side, "user": { "id": `${anno.creator.id}`, "name": `${anno.creator.name}`, "email": `${anno.creator.email}`, "websocket_id": `${websocketID}`, date: new Date(), }, "withGroupId": anno.creator.withGroupId, }, @@ -233,7 +234,7 @@ function AnnotationCard({ // send websocket notification that user made an annotation if (sendNotification) { - SendNewAnnotationWebsocketNotification(anno, new_anno) + SendNewAnnotationWebsocketNotification(anno, new_anno, side) } } diff --git a/src/pages/documents/[slug]/index.jsx b/src/pages/documents/[slug]/index.jsx index 13bed08..f565726 100644 --- a/src/pages/documents/[slug]/index.jsx +++ b/src/pages/documents/[slug]/index.jsx @@ -288,11 +288,14 @@ const DocumentPage = ({ return tags.filter((value, index, self) => self.indexOf(value) === index).sort(); } - const saveAnnotationChanges = (anno, side) => { + const saveAnnotationChanges = (anno, side, dontSetAnnotationIdBeingEdited) => { const index = channelAnnotations[side].findIndex((a) => a._id === anno._id); channelAnnotations[side][index] = DeepCopyObj(anno); setChannelAnnotations(DeepCopyObj(channelAnnotations)); - setAnnotationIdBeingEdited(anno.editing ? anno._id : undefined); + if (!dontSetAnnotationIdBeingEdited) { + setAnnotationIdBeingEdited(anno.editing ? anno._id : undefined); + } + return index; }; const scrollToAnnotation = () => { @@ -940,6 +943,7 @@ const DocumentPage = ({ const { annotation, new_annotation, + side, user, withGroupId, } = data; @@ -948,6 +952,13 @@ const DocumentPage = ({ if (annotation) { description = `${FirstNameLastInitial(annotation.creator.name)} ${new_annotation ? 'made' : 'edited'} an annotation`; + + if (new_annotation) { + + } else { + // edit exisiting annotation data + // console.log('index: ', saveAnnotationChanges(annotation, side, true)) + } } const msg = {