Skip to content

Commit

Permalink
Fix onSubscriptionData naming confusion
Browse files Browse the repository at this point in the history
  • Loading branch information
KhaledEmaraDev committed Jan 16, 2021
1 parent 94c92a4 commit 349ea69
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 31 deletions.
48 changes: 22 additions & 26 deletions frontend/src/components/Chat.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -235,32 +235,28 @@ const Chat = (props) => {
defaultMatches: true,
});

const { data: subData, error: subError } = useSubscription(
MESSAGE_SUBSCRIPTION,
{
onSubscriptionData({ subscriptionData }) {
if (
subscriptionData &&
(messageArray.length == 0 ||
subscriptionData.newMessage.id !=
messageArray[messageArray.length - 1].id) &&
currentReceiver != "#" &&
subscriptionData.newMessage.from.id === currentReceiver
) {
play();
setMessageArray((messageArray) => [
...messageArray,
{
id: subData.newMessage.id,
createdAt: subData.newMessage.createdAt,
body: subData.newMessage.body,
sender: false,
},
]);
}
},
}
);
const { error: subError } = useSubscription(MESSAGE_SUBSCRIPTION, {
onSubscriptionData({ subscriptionData: { data: subData } }) {
if (
subData &&
(messageArray.length == 0 ||
subData.newMessage.id != messageArray[messageArray.length - 1].id) &&
currentReceiver != "#" &&
subData.newMessage.from.id === currentReceiver
) {
play();
setMessageArray((messageArray) => [
...messageArray,
{
id: subData.newMessage.id,
createdAt: subData.newMessage.createdAt,
body: subData.newMessage.body,
sender: false,
},
]);
}
},
});

if (subError) console.error(subError);

Expand Down
10 changes: 5 additions & 5 deletions frontend/src/components/NotificationsMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,18 @@ function NotificationsMenu(props) {
},
});
useSubscription(NOTIFICATION_SUBSCRIPTION, {
onSubscriptionData({ subscriptionData }) {
onSubscriptionData({ subscriptionData: { data } }) {
if (
subscriptionData &&
subscriptionData.newNotification &&
data &&
data.newNotification &&
(notifications.length === 0 ||
subscriptionData.newNotification.id !== notifications[0].id)
data.newNotification.id !== notifications[0].id)
) {
play();

setNotifications((notifications) => [
...notifications,
subscriptionData.newNotification,
data.newNotification,
]);
showSnackbar("info", "New Notification");
}
Expand Down

0 comments on commit 349ea69

Please sign in to comment.