Skip to content

Commit

Permalink
fix: cleanup comments etc
Browse files Browse the repository at this point in the history
  • Loading branch information
gwynndp committed Mar 12, 2022
1 parent 0d8b419 commit 5747048
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 87 deletions.
18 changes: 0 additions & 18 deletions src/components/Messaging/AnnounceMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ const AnnounceMessageForm = ({ setToggleAnnounceMessage }) => {
user,
regions,
postBulkMessageSend,
threads,
setThreads,
} = useContext(MessagingContext);
const { form, sendButton } = useStyles();
Expand Down Expand Up @@ -117,26 +116,10 @@ const AnnounceMessageForm = ({ setToggleAnnounceMessage }) => {
(payload.body && payload.region_id)
) {
const res = await postBulkMessageSend(payload);
log.debug('Announce submit', threads, res);

if (res.error) {
setErrorMessage(res.message);
// handleModalOpen();
} else {
// id: null;
// type: 'announce';
// parent_message_id: null;
// from: 'admin';
// to: null;
// recipient_organization_id: '8b2628b3-733b-4962-943d-95ebea918c9d';
// recipient_region_id: null;
// subject: 'asdf2';
// body: 'asdf';
// composed_at: '2022-03-11T21:55:37.782Z';
// video_link: null;
// survey_response: null;
// survey: null;

const newAnnouncement = {
id: null,
type: 'announce',
Expand Down Expand Up @@ -164,7 +147,6 @@ const AnnounceMessageForm = ({ setToggleAnnounceMessage }) => {
},
...prev,
];
log.debug('updated threads', updated);
return updated;
});
}
Expand Down
2 changes: 0 additions & 2 deletions src/components/Messaging/MessageBody.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,6 @@ const MessageBody = ({ messages, messageRecipient, avatar }) => {
const res = await postMessageSend(messagePayload);
if (res.error) {
setErrorMessage(res.message);
// handleModalOpen();
} else {
const newMessage = {
parent_message_id: lastMessage.id ? lastMessage.id : null,
Expand Down Expand Up @@ -531,7 +530,6 @@ const MessageBody = ({ messages, messageRecipient, avatar }) => {
new Date(b?.messages?.at(-1).composed_at) -
new Date(a?.messages?.at(-1).composed_at)
);
// log.debug('updated threads', updated);
return updated;
});
}
Expand Down
80 changes: 38 additions & 42 deletions src/components/Messaging/NewMessage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useState, useContext, useEffect } from 'react';
import uuid from 'uuid/v4';
import { MessagingContext } from 'context/MessagingContext';
import {
FormControl,
Expand All @@ -13,6 +14,7 @@ import { makeStyles } from '@material-ui/styles';

import GSInputLabel from 'components/common/InputLabel';
const log = require('loglevel');

const useStyles = makeStyles((theme) => ({
box: {
position: 'absolute',
Expand Down Expand Up @@ -63,8 +65,9 @@ const NewMessage = ({ openModal, handleClose }) => {
setErrorMessage,
user,
authors,
postMessageSend,
threads,
setThreads,
postMessageSend,
} = useContext(MessagingContext);
const [messageContent, setMessageContent] = useState('');
const [recipient, setRecipient] = useState('');
Expand Down Expand Up @@ -104,48 +107,41 @@ const NewMessage = ({ openModal, handleClose }) => {

if (res.error) {
setErrorMessage(res.message);
// handleModalOpen();
} else {
// author_handle: 'admin';
// body: 'Do your thang\nDo what you gotta do...';
// organization_id: '8b2628b3-733b-4962-943d-95ebea918c9d';
// subject: 'I have something to say';
// type: 'announce';
// const newAnnouncement = {
// parent_message_id: lastMessage.id ? lastMessage.id : null,
// body: messageContent,
// composed_at: new Date().toISOString(),
// from: user.userName,
// id: uuid(),
// recipient_organization_id: null,
// recipient_region_id: null,
// subject: 'Message',
// survey: null,
// to: messageRecipient,
// type: 'message',
// video_link: null,
// };
// log.debug('...update threads w/ new announcement');
// // update the full set of threads
// setThreads((prev) => {
// const updated = prev
// .reduce(
// (threads, thread) => {
// if (thread.userName === messageRecipient) {
// thread.messages.push(newMessage);
// }
// return threads;
// },
// [...prev]
// )
// .sort(
// (a, b) =>
// new Date(b?.messages?.at(-1).composed_at) -
// new Date(a?.messages?.at(-1).composed_at)
// );
// // log.debug('updated threads', updated);
// return updated;
// });
const newMessage = {
parent_message_id: null,
body: messageContent,
composed_at: new Date().toISOString(),
from: user.userName,
id: uuid(),
recipient_organization_id: null,
recipient_region_id: null,
survey: null,
to: recipient,
type: 'message',
video_link: null,
};

log.debug('...update threads after postMessageSend');
// update the full set of threads
setThreads((prev) => {
const updated = prev
.reduce(
(threads, thread) => {
if (thread.userName === recipient) {
thread.messages.push(newMessage);
}
return threads;
},
[...prev]
)
.sort(
(a, b) =>
new Date(b?.messages?.at(-1).composed_at) -
new Date(a?.messages?.at(-1).composed_at)
);
return updated;
});
}
}
handleClose();
Expand Down
21 changes: 0 additions & 21 deletions src/components/Messaging/Survey.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,27 +172,7 @@ const SurveyForm = ({ setToggleSurvey }) => {

if (res.error) {
setErrorMessage(res.message);
// handleModalOpen();
} else {
// id: null;
// type: 'survey';
// parent_message_id: null;
// from: 'admin';
// to: null;
// recipient_organization_id: null;
// recipient_region_id: null;
// subject: 'Number of trees planted today';
// body: null;
// composed_at: '2022-01-22T00:00:00.000Z';
// video_link: null;
// survey_response: null;

// survey
// id:"99e61995-666c-48c8-9d4e-ca3cff1bfbeb"
// title:"Number of trees planted today"
// questions: [{…}]
// response: false

const newSurvey = {
id: uuid(),
type: 'survey',
Expand All @@ -219,7 +199,6 @@ const SurveyForm = ({ setToggleSurvey }) => {
},
...prev,
];
log.debug('updated threads', updated);
return updated;
});
}
Expand Down
3 changes: 0 additions & 3 deletions src/context/AppContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import CreditCardIcon from '@material-ui/icons/CreditCard';
import InboxRounded from '@material-ui/icons/InboxRounded';
import { session, hasPermission, POLICIES } from '../models/auth';
import api from '../api/treeTrackerApi';
import log from 'loglevel';

// no initial context here because we want login values to be 'undefined' until they are confirmed
export const AppContext = createContext({});
Expand Down Expand Up @@ -196,8 +195,6 @@ export const AppProvider = (props) => {
const [userHasOrg, setUserHasOrg] = useState(false);
const [orgList, setOrgList] = useState([]);

log.debug('AppProvider', !!user, !!token, !!routes, !!userHasOrg, !!orgList);

// TODO: The below `selectedFilters` state would be better placed under a
// separate FilterContext in the future iterations when the need to share
// filter state across components increases. For now this is used only in
Expand Down
2 changes: 1 addition & 1 deletion src/context/MessagingContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export const MessagingProvider = (props) => {
};

const loadAuthors = async () => {
log.debug('...load authors', user);
log.debug('...load authors');
const res = await api.getAuthors();

if (res.authors) {
Expand Down

0 comments on commit 5747048

Please sign in to comment.