Merge branch 'master' into license/change-license

This commit is contained in:
J Francisco Rader authored and GitHub committed 2021-03-24 15:56:45 -03:00
commit f5b4484c1a
7 files changed
+47 -17

No files matched your search

+1 -1
View File
@@ -2,7 +2,7 @@
<img src="https://beta.iodine.gg/zVkK7.png" width="500" height="300" />
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.
@@ -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);
@@ -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);
};
@@ -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 });
};
+3 -1
View File
@@ -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);
}
+3 -4
View File
@@ -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();
+7
View File
@@ -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);
});
};