From 4e7e6b3e92bb87c1ffb9b0be260f5f5245cd7dba Mon Sep 17 00:00:00 2001 From: Taso Date: Mon, 22 Mar 2021 14:44:13 -0400 Subject: [PATCH 1/5] fix(client/marketplace): Fixed typo preventing listings from being sent --- resources/client/cl_sellout.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/resources/client/cl_sellout.ts b/resources/client/cl_sellout.ts index 8622562..1699827 100644 --- a/resources/client/cl_sellout.ts +++ b/resources/client/cl_sellout.ts @@ -2,12 +2,11 @@ import { MarketplaceEvents, MarketplaceListing } from '../../typings/marketplace import { IAlertProps } from '../../typings/alerts'; import { sendMarketplaceEvent } from '../utils/messages'; -RegisterNuiCallbackType(MarketplaceEvents.ADD_LISTING); - -onNet(MarketplaceEvents.SEND_LISTING, (listing: MarketplaceListing) => { - sendMarketplaceEvent('setListing', listing); +onNet(MarketplaceEvents.SEND_LISTING, (listings: MarketplaceListing[]) => { + sendMarketplaceEvent('setListings', listings); }); +RegisterNuiCallbackType(MarketplaceEvents.ADD_LISTING); on(`__cfx_nui:${MarketplaceEvents.ADD_LISTING}`, (data: MarketplaceListing, cb: Function) => { emitNet(MarketplaceEvents.ADD_LISTING, data); cb(); From b42ee97450be770847ff511ebeea5444d65672bc Mon Sep 17 00:00:00 2001 From: Christopher Date: Mon, 22 Mar 2021 22:45:47 +0100 Subject: [PATCH 2/5] feat(resources/cl_utils): NuiCallback --- resources/client/cl_utils.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/resources/client/cl_utils.ts b/resources/client/cl_utils.ts index 304f25f..6db155c 100644 --- a/resources/client/cl_utils.ts +++ b/resources/client/cl_utils.ts @@ -52,3 +52,10 @@ export default class ClientUtils { }); } } + +export const NuiCallback = (event: string, callback: Function) => { + RegisterRawNuiCallback(event, (data: any) => { + const parsed = JSON.parse(data?.body); + callback(parsed); + }); +}; From a3d7c19f44759a7a13c2592b002b42aa2e9d5633 Mon Sep 17 00:00:00 2001 From: J Francisco Rader Date: Mon, 22 Mar 2021 18:57:20 -0300 Subject: [PATCH 3/5] Tweaks / Message notifications (#174) * Remove msg notifications when opening one | Dont alert notifications when inside that conversation * Fix msg events * Fix goToConversation util * Fix nuiEvents for messages --- .../messages/hooks/useMessageNotifications.ts | 18 +++++++++++++-- .../apps/messages/hooks/useMessageService.ts | 23 ++++++++++++------- .../apps/messages/utils/goToConversation.ts | 3 ++- 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/phone/src/apps/messages/hooks/useMessageNotifications.ts b/phone/src/apps/messages/hooks/useMessageNotifications.ts index 8df34c8..1a41834 100644 --- a/phone/src/apps/messages/hooks/useMessageNotifications.ts +++ b/phone/src/apps/messages/hooks/useMessageNotifications.ts @@ -1,5 +1,6 @@ +import { useCallback } from 'react'; import { useTranslation } from 'react-i18next'; -import { useHistory } from 'react-router-dom'; +import { matchPath, useHistory } from 'react-router-dom'; import { useApp } from '../../../os/apps/hooks/useApps'; import { useNotifications } from '../../../os/notifications/hooks/useNotifications'; import { goToConversation } from '../utils/goToConversation'; @@ -12,7 +13,20 @@ export const useMessageNotifications = () => { const history = useHistory(); const { removeId, addNotification, addNotificationAlert } = useNotifications(); const { icon, notificationIcon } = useApp('MESSAGES'); - const { getMessageGroupById } = useMessages(); + const { getMessageGroupById, activeMessageGroup } = useMessages(); + + // Remove notifications from groups when opening them + history.listen((location) => { + if ( + activeMessageGroup?.groupId && + matchPath(location.pathname, { + path: `/messages/conversations/${activeMessageGroup.groupId}`, + exact: true, + }) + ) { + removeId(`${NOTIFICATION_ID}:${activeMessageGroup.groupId}`); + } + }); const setNotification = ({ groupId, message }) => { const group = getMessageGroupById(groupId); diff --git a/phone/src/apps/messages/hooks/useMessageService.ts b/phone/src/apps/messages/hooks/useMessageService.ts index 458a21e..7647f7d 100644 --- a/phone/src/apps/messages/hooks/useMessageService.ts +++ b/phone/src/apps/messages/hooks/useMessageService.ts @@ -6,8 +6,11 @@ import { useTranslation } from 'react-i18next'; import { useMessageNotifications } from './useMessageNotifications'; import { useCallback } from 'react'; import Nui from '../../../os/nui-events/utils/Nui'; +import { useLocation } from 'react-router'; +import { MessageEvents } from '../../../../../typings/messages'; export const useMessagesService = () => { + const { pathname } = useLocation(); const [activeMessageGroup, setActiveMessageGroup] = useRecoilState( messageState.activeMessageGroup, ); @@ -31,11 +34,15 @@ export const useMessagesService = () => { const handleMessageBroadcast = useCallback( ({ groupId, message }) => { if (groupId === activeMessageGroup?.groupId) { - Nui.send('phone:fetchMessages', { groupId: activeMessageGroup.groupId }); + Nui.send(MessageEvents.FETCH_MESSAGES, { groupId: activeMessageGroup.groupId }); + if (pathname.includes('messages/conversations')) { + // Dont trigger notification if conversation is open. + return; + } } setNotification({ groupId, message }); }, - [activeMessageGroup, setNotification], + [activeMessageGroup, pathname, setNotification], ); const _setMessageGroups = useCallback( @@ -50,10 +57,10 @@ export const useMessagesService = () => { [activeMessageGroup, setActiveMessageGroup, setMessageGroups], ); - useNuiEvent('MESSAGES', 'phone:fetchMessageGroupsSuccess', _setMessageGroups); - useNuiEvent('MESSAGES', 'phone:fetchMessagesSuccess', setMessages); - useNuiEvent('MESSAGES', 'phone:createMessageGroupSuccess', setCreateMessageGroupResult); - useNuiEvent('MESSAGES', 'phone:createMessageGroupFailed', setCreateMessageGroupResult); - useNuiEvent('MESSAGES', 'createMessagesBroadcast', handleMessageBroadcast); - useNuiEvent('MESSAGES', 'phone:setMessagesAlert', handleAddAlert); + useNuiEvent('MESSAGES', MessageEvents.FETCH_MESSAGE_GROUPS_SUCCESS, _setMessageGroups); + useNuiEvent('MESSAGES', MessageEvents.FETCH_MESSAGES_SUCCESS, setMessages); + useNuiEvent('MESSAGES', MessageEvents.CREATE_MESSAGE_GROUP_SUCCESS, setCreateMessageGroupResult); + useNuiEvent('MESSAGES', MessageEvents.CREATE_MESSAGE_GROUP_FAILED, setCreateMessageGroupResult); + useNuiEvent('MESSAGES', MessageEvents.CREATE_MESSAGE_BROADCAST, handleMessageBroadcast); + useNuiEvent('MESSAGES', MessageEvents.ACTION_RESULT, handleAddAlert); }; diff --git a/phone/src/apps/messages/utils/goToConversation.ts b/phone/src/apps/messages/utils/goToConversation.ts index 52b5905..b70a796 100644 --- a/phone/src/apps/messages/utils/goToConversation.ts +++ b/phone/src/apps/messages/utils/goToConversation.ts @@ -1,7 +1,8 @@ +import { MessageEvents } from '../../../../../typings/messages'; import Nui from '../../../os/nui-events/utils/Nui'; export const goToConversation = (messageGroup, history) => { if (!messageGroup?.groupId || !history) return; history.push(`/messages/conversations/${messageGroup.groupId}`); - Nui.send('phone:fetchMessages', { groupId: messageGroup.groupId }); + Nui.send(MessageEvents.FETCH_MESSAGES, { groupId: messageGroup.groupId }); }; From 6c2eae7f5d52aa28b1a61cbf51c02099f8be0b56 Mon Sep 17 00:00:00 2001 From: Taso Date: Mon, 22 Mar 2021 19:14:53 -0400 Subject: [PATCH 4/5] fix(phone/settings): Fixed localStorage persistence --- phone/src/apps/settings/hooks/useSettings.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/phone/src/apps/settings/hooks/useSettings.ts b/phone/src/apps/settings/hooks/useSettings.ts index 96217ae..38e5370 100644 --- a/phone/src/apps/settings/hooks/useSettings.ts +++ b/phone/src/apps/settings/hooks/useSettings.ts @@ -81,8 +81,10 @@ const localStorageEffect = (key) => ({ setSelf, onSet }) => { const savedVal = localStorage.getItem(key); if (savedVal) { try { - const validString = !isSchemaValid(savedVal); + const validString = isSchemaValid(savedVal); if (validString) { + setSelf(JSON.parse(savedVal)); + } else { console.error('Settings Schema was invalid, applying default settings'); setSelf(config.defaultSettings); } From b789e734477a4be19207d3edef56824ca3c824cd Mon Sep 17 00:00:00 2001 From: Dillon Skaggs Date: Wed, 24 Mar 2021 13:24:03 -0500 Subject: [PATCH 5/5] fix(readme): fix typo (#180) auguest kek --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 861947c..2d896a2 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ -NPWD is our current running project. Our team has been working on the project since Auguest, 2020. This resource isn’t complete yet and currently has no ETA for release. Feel free to test it out in a dev environment by following the installation guide. +NPWD is our current running project. Our team has been working on the project since August, 2020. This resource isn’t complete yet and currently has no ETA for release. Feel free to test it out in a dev environment by following the installation guide. Written completely by the Project Error Dev Team in [React](https://reactjs.org/) with a [TypeScript](https://www.typescriptlang.org/) client/server environment.