Skip to content

Commit

Permalink
adding functionality for websocket on doc view
Browse files Browse the repository at this point in the history
  • Loading branch information
mbogo-mit committed Dec 29, 2023
1 parent 10ef992 commit fea4713
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/components/AnnotationCard/AnnotationCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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,
},
Expand All @@ -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)
}
}

Expand Down
15 changes: 13 additions & 2 deletions src/pages/documents/[slug]/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand Down Expand Up @@ -940,6 +943,7 @@ const DocumentPage = ({
const {
annotation,
new_annotation,
side,
user,
withGroupId,
} = data;
Expand All @@ -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 = {
Expand Down

0 comments on commit fea4713

Please sign in to comment.