mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-03 06:28:51 +00:00
Make use of library instead of having code duplicated (#201)
* Use fivem-nui-react-lib
This commit is contained in:
1 parent
0cf5bc2bc7
commit
8e79eb1345
60 files changed
+231
-347
No files matched your search
+3
-2
@@ -22,13 +22,14 @@
|
||||
"emoji-mart": "^3.0.0",
|
||||
"enzyme": "^3.11.0",
|
||||
"enzyme-adapter-react-16": "^1.15.5",
|
||||
"fivem-nui-react-lib": "2.2.6",
|
||||
"howler": "^2.2.1",
|
||||
"i18next": "^19.7.0",
|
||||
"jsonschema": "^1.4.0",
|
||||
"parse-url": "^5.0.2",
|
||||
"qs": "^6.9.6",
|
||||
"react": "^16.13.1",
|
||||
"react-dom": "^16.13.1",
|
||||
"react": "17.0.2",
|
||||
"react-dom": "17",
|
||||
"react-hotkeys": "^2.0.0",
|
||||
"react-i18next": "^11.7.1",
|
||||
"react-popper": "^2.2.3",
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import React from 'react';
|
||||
import { RecoilRoot } from 'recoil';
|
||||
import { shallow } from 'enzyme';
|
||||
import Phone from './Phone';
|
||||
import { PhoneContainer } from './PhoneContainer';
|
||||
|
||||
it('renders Phone', () => {
|
||||
shallow(
|
||||
<RecoilRoot>
|
||||
<Phone />
|
||||
<PhoneContainer />
|
||||
</RecoilRoot>,
|
||||
);
|
||||
});
|
||||
@@ -8,7 +8,6 @@ import { Box, Paper, Slide, Typography } from '@material-ui/core';
|
||||
import { useKeyboardService } from './os/keyboard/hooks/useKeyboardService';
|
||||
import { NotificationBar } from './os/notifications/components/NotificationBar';
|
||||
import { Navigation } from './os/navigation-bar/components/Navigation';
|
||||
import { useNuiService } from './os/nui-events/hooks/useNuiService';
|
||||
import { useSimcardService } from './os/simcard/hooks/useSimcardService';
|
||||
import { usePhoneService } from './os/phone/hooks/usePhoneService';
|
||||
import { useApps } from './os/apps/hooks/useApps';
|
||||
@@ -62,7 +61,6 @@ function Phone() {
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
||||
useNuiService();
|
||||
useKeyboardService();
|
||||
usePhoneService();
|
||||
useSimcardService();
|
||||
|
||||
@@ -4,19 +4,22 @@ import { NotificationsProvider } from './os/notifications/providers/Notification
|
||||
import { usePhoneTheme } from './os/phone/hooks/usePhoneTheme';
|
||||
import SnackbarProvider from './ui/providers/SnackbarProvider';
|
||||
import Phone from './Phone';
|
||||
import { NuiProvider } from 'fivem-nui-react-lib';
|
||||
import { SoundProvider } from './os/sound/providers/SoundProvider';
|
||||
|
||||
export const PhoneContainer = () => {
|
||||
const currentTheme = usePhoneTheme();
|
||||
return (
|
||||
<ThemeProvider theme={currentTheme}>
|
||||
<SoundProvider>
|
||||
<NotificationsProvider>
|
||||
<SnackbarProvider>
|
||||
<Phone />
|
||||
</SnackbarProvider>
|
||||
</NotificationsProvider>
|
||||
</SoundProvider>
|
||||
</ThemeProvider>
|
||||
<NuiProvider resource="new-phone-who-dis">
|
||||
<ThemeProvider theme={currentTheme}>
|
||||
<SoundProvider>
|
||||
<NotificationsProvider>
|
||||
<SnackbarProvider>
|
||||
<Phone />
|
||||
</SnackbarProvider>
|
||||
</NotificationsProvider>
|
||||
</SoundProvider>
|
||||
</ThemeProvider>
|
||||
</NuiProvider>
|
||||
);
|
||||
};
|
||||
@@ -1,11 +1,9 @@
|
||||
import React, { useState } from 'react';
|
||||
import Modal from '../../../../ui/components/Modal';
|
||||
import { Button, List, ListItem, TextField, makeStyles } from '@material-ui/core';
|
||||
|
||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
||||
|
||||
import { useBankModal } from '../../hooks/useBankModal';
|
||||
import { BankEvents } from '../../../../../../typings/bank';
|
||||
import { useNuiRequest } from 'fivem-nui-react-lib';
|
||||
|
||||
const useStyles = makeStyles((theme) => ({
|
||||
input: {
|
||||
@@ -30,6 +28,7 @@ const useStyles = makeStyles((theme) => ({
|
||||
}));
|
||||
|
||||
export const TransferModal = () => {
|
||||
const Nui = useNuiRequest();
|
||||
const classes = useStyles();
|
||||
|
||||
const [targetID, setTargetID] = useState('');
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent';
|
||||
import { useNuiEvent } from 'fivem-nui-react-lib';
|
||||
import { bankState } from './state';
|
||||
import { useTransactions } from './useTransactions';
|
||||
import { useCredentials } from './useCredentials';
|
||||
@@ -7,7 +7,6 @@ import { useBankNotification } from './useBankNotification';
|
||||
import { IAlert, useSnackbar } from '../../../ui/hooks/useSnackbar';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { BankEvents } from '../../../../../typings/bank';
|
||||
import { PhoneEvents } from '../../../../../typings/phone';
|
||||
|
||||
export const useBankService = () => {
|
||||
const setTransaction = useSetRecoilState(bankState.transactions);
|
||||
|
||||
@@ -3,14 +3,15 @@ import { Box, Button } from '@material-ui/core';
|
||||
import useStyles from './grid.styles';
|
||||
import { usePhotos } from '../../hooks/usePhotos';
|
||||
import AddIcon from '@material-ui/icons/Add';
|
||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import { useQueryParams } from '../../../../common/hooks/useQueryParams';
|
||||
import { addQueryToLocation } from '../../../../common/utils/addQueryToLocation';
|
||||
import { getLocationFromUrl } from '../../../../common/utils/getLocationFromUrl';
|
||||
import { PhotoEvents } from '../../../../../../typings/photo';
|
||||
import { useNuiRequest } from 'fivem-nui-react-lib';
|
||||
|
||||
export const GalleryGrid = () => {
|
||||
const Nui = useNuiRequest();
|
||||
const classes = useStyles();
|
||||
const history = useHistory();
|
||||
const query = useQueryParams();
|
||||
|
||||
@@ -4,14 +4,15 @@ import { Button, Paper } from '@material-ui/core';
|
||||
import ArrowBackIcon from '@material-ui/icons/ArrowBack';
|
||||
import DeleteIcon from '@material-ui/icons/Delete';
|
||||
import ShareIcon from '@material-ui/icons/Share';
|
||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import { useQueryParams } from '../../../../common/hooks/useQueryParams';
|
||||
import { ICameraPhoto } from '../../hooks/usePhotos';
|
||||
import { ShareModal } from './ShareModal';
|
||||
import { PhotoEvents } from '../../../../../../typings/photo';
|
||||
import { useNuiRequest } from 'fivem-nui-react-lib';
|
||||
|
||||
export const GalleryModal = () => {
|
||||
const Nui = useNuiRequest();
|
||||
const classes = useStyles();
|
||||
const history = useHistory();
|
||||
const query = useQueryParams();
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
import { useCallback, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { SetterOrUpdater, useRecoilState } from 'recoil';
|
||||
import { PhotoEvents } from '../../../../../typings/photo';
|
||||
import { useNuiEvent, useNuiCallback } from 'fivem-nui-react-lib/dist/index';
|
||||
import { useSnackbar } from '../../../ui/hooks/useSnackbar';
|
||||
import { photoState } from './state';
|
||||
|
||||
export interface ICameraPhoto {
|
||||
id: string;
|
||||
image: string;
|
||||
}
|
||||
|
||||
interface IUseCamera {
|
||||
photos: ICameraPhoto[];
|
||||
setPhotos: SetterOrUpdater<ICameraPhoto[]>;
|
||||
takePhoto: () => void;
|
||||
isLoading: boolean;
|
||||
}
|
||||
|
||||
export const useCamera = (): IUseCamera => {
|
||||
const { t } = useTranslation();
|
||||
const { addAlert } = useSnackbar();
|
||||
|
||||
const [photos, setPhotos] = useRecoilState<ICameraPhoto[] | null>(photoState.photos);
|
||||
|
||||
const [isUploading, setUploading] = useState(false);
|
||||
|
||||
const onPhotoSuccess = useCallback(
|
||||
(photo) => {
|
||||
setUploading(false);
|
||||
if (!photo?.image) return;
|
||||
setPhotos((curr) => [photo, ...curr]);
|
||||
},
|
||||
[setPhotos],
|
||||
);
|
||||
|
||||
const onPhotoError = useCallback(
|
||||
(i18nKey) => {
|
||||
setUploading(false);
|
||||
addAlert({ type: 'error', message: t(i18nKey) });
|
||||
},
|
||||
[addAlert, t],
|
||||
);
|
||||
|
||||
const [takePhoto] = useNuiCallback<void, ICameraPhoto>(
|
||||
'CAMERA',
|
||||
PhotoEvents.TAKE_PHOTO,
|
||||
onPhotoSuccess,
|
||||
onPhotoError,
|
||||
);
|
||||
|
||||
useNuiEvent('CAMERA', PhotoEvents.UPLOAD_PHOTO, () => setUploading(true));
|
||||
|
||||
return {
|
||||
photos,
|
||||
setPhotos,
|
||||
takePhoto,
|
||||
isLoading: isUploading,
|
||||
};
|
||||
};
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useSetRecoilState } from 'recoil';
|
||||
import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent';
|
||||
import { useNuiEvent } from 'fivem-nui-react-lib';
|
||||
import { photoState } from './state';
|
||||
import { PhotoEvents } from '../../../../../typings/photo';
|
||||
|
||||
|
||||
@@ -6,15 +6,16 @@ import PhoneIcon from '@material-ui/icons/Phone';
|
||||
import ChatIcon from '@material-ui/icons/Chat';
|
||||
import MoreVertIcon from '@material-ui/icons/MoreVert';
|
||||
import { useContacts } from '../../hooks/useContacts';
|
||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
||||
import { SearchContacts } from './SearchContacts';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import LogDebugEvent from '../../../../os/debug/LogDebugEvents';
|
||||
import { CallEvents } from '../../../../../../typings/call';
|
||||
import { useNuiRequest } from 'fivem-nui-react-lib';
|
||||
|
||||
export const ContactList = () => {
|
||||
const { filteredContacts } = useFilteredContacts();
|
||||
const history = useHistory();
|
||||
const Nui = useNuiRequest();
|
||||
|
||||
const { contacts } = useContacts();
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import { makeStyles } from '@material-ui/core/styles';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useHistory, useParams } from 'react-router-dom';
|
||||
import { useContacts } from '../../hooks/useContacts';
|
||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
||||
import { useNuiRequest } from 'fivem-nui-react-lib';
|
||||
import ArrowBackIcon from '@material-ui/icons/ArrowBack';
|
||||
import LogDebugEvent from '../../../../os/debug/LogDebugEvents';
|
||||
import { useQueryParams } from '../../../../common/hooks/useQueryParams';
|
||||
@@ -48,12 +48,12 @@ const useStyles = makeStyles({
|
||||
});
|
||||
|
||||
const ContactsInfoPage = () => {
|
||||
const Nui = useNuiRequest();
|
||||
const classes = useStyles();
|
||||
|
||||
const history = useHistory();
|
||||
|
||||
|
||||
const { getContact } = useContacts();
|
||||
|
||||
|
||||
const { id } = useParams<ContactInfoRouteParams>();
|
||||
const { addNumber, referal } = useQueryParams<ContactInfoRouteQuery>({
|
||||
referal: '/contacts',
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent';
|
||||
import { useNuiEvent } from 'fivem-nui-react-lib';
|
||||
import { useSetRecoilState } from 'recoil';
|
||||
import { contactsState } from './state';
|
||||
import { useContacts } from './useContacts';
|
||||
|
||||
@@ -4,7 +4,7 @@ import { makeStyles, Theme } from '@material-ui/core/styles';
|
||||
import PhoneIcon from '@material-ui/icons/Phone';
|
||||
import PersonAddIcon from '@material-ui/icons/PersonAdd';
|
||||
import { DialInputCtx, IDialInputCtx } from '../context/InputContext';
|
||||
import Nui from '../../../os/nui-events/utils/Nui';
|
||||
import { useNuiRequest } from 'fivem-nui-react-lib';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import { CallEvents } from '../../../../../typings/call';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
@@ -29,6 +29,7 @@ const useStyles = makeStyles((theme: Theme) => ({
|
||||
}));
|
||||
|
||||
export const DialerInput = () => {
|
||||
const Nui = useNuiRequest();
|
||||
const classes = useStyles();
|
||||
const history = useHistory();
|
||||
const { t } = useTranslation();
|
||||
|
||||
@@ -5,7 +5,7 @@ import PhoneIcon from '@material-ui/icons/Phone';
|
||||
import PersonAddIcon from '@material-ui/icons/PersonAdd';
|
||||
import { List } from '../../../../ui/components/List';
|
||||
import { ListItem } from '../../../../ui/components/ListItem';
|
||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
||||
import { useNuiRequest } from 'fivem-nui-react-lib';
|
||||
import { useSimcard } from '../../../../os/simcard/hooks/useSimcard';
|
||||
import { useContacts } from '../../../contacts/hooks/useContacts';
|
||||
import { CallEvents, ICall } from '../../../../../../typings/call';
|
||||
@@ -25,6 +25,7 @@ const useStyles = makeStyles((theme: Theme) => ({
|
||||
}));
|
||||
|
||||
export const DialerHistory = ({ calls }) => {
|
||||
const Nui = useNuiRequest();
|
||||
const { number: myNumber } = useSimcard();
|
||||
const { getDisplayByNumber } = useContacts();
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useSetRecoilState } from 'recoil';
|
||||
import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent';
|
||||
import { useNuiEvent } from 'fivem-nui-react-lib';
|
||||
import { dialState } from './state';
|
||||
import { CallEvents } from '../../../../../typings/call';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent';
|
||||
import { useNuiEvent } from 'fivem-nui-react-lib';
|
||||
import { useSetRecoilState } from 'recoil';
|
||||
import { exampleState } from './state';
|
||||
import { useExample } from './useExample';
|
||||
|
||||
@@ -7,7 +7,7 @@ import DeleteIcon from '@material-ui/icons/Delete';
|
||||
import ReportIcon from '@material-ui/icons/Report';
|
||||
import ChatIcon from '@material-ui/icons/Chat';
|
||||
import PhoneIcon from '@material-ui/icons/Phone';
|
||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
||||
import { useNuiRequest } from 'fivem-nui-react-lib';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useHistory } from 'react-router';
|
||||
import { CallEvents } from '../../../../../../typings/call';
|
||||
@@ -19,6 +19,7 @@ const useStyles = makeStyles((theme: Theme) => ({
|
||||
}));
|
||||
|
||||
export const ListingActions = ({ listing }: { listing: MarketplaceListing }) => {
|
||||
const Nui = useNuiRequest();
|
||||
const classes = useStyles();
|
||||
const { number: myNumber } = useSimcard();
|
||||
const { t } = useTranslation();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import React, { useState } from 'react';
|
||||
import { makeStyles, Button, TextField, Typography } from '@material-ui/core';
|
||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
||||
import { makeStyles, Button, TextField } from '@material-ui/core';
|
||||
import { useNuiRequest } from 'fivem-nui-react-lib';
|
||||
import { MarketplaceEvents } from '../../../../../../typings/marketplace';
|
||||
import { useSnackbar } from '../../../../ui/hooks/useSnackbar';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
@@ -31,6 +31,7 @@ const useStyles = makeStyles((theme) => ({
|
||||
}));
|
||||
|
||||
export const ListingForm = () => {
|
||||
const Nui = useNuiRequest();
|
||||
const classes = useStyles();
|
||||
const { t } = useTranslation();
|
||||
const { addAlert } = useSnackbar();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent';
|
||||
import { useNuiEvent } from 'fivem-nui-react-lib';
|
||||
import { selloutState } from './state';
|
||||
import { useListing } from './useListing';
|
||||
import { useSetRecoilState } from 'recoil';
|
||||
|
||||
@@ -7,8 +7,7 @@ import { AppContent } from '../../../ui/components/AppContent';
|
||||
import { useApp } from '../../../os/apps/hooks/useApps';
|
||||
import InjectDebugData from '../../../os/debug/InjectDebugData';
|
||||
import { MatchThemeProvider } from '../providers/MatchThemeProvider';
|
||||
|
||||
import Nui from '../../../os/nui-events/utils/Nui';
|
||||
import { useNuiRequest } from 'fivem-nui-react-lib';
|
||||
import MatchBottomNavigation from '../components/BottomNavigation';
|
||||
import MatchPage from './views/MatchPage';
|
||||
import ProfileEditor from './views/ProfileEditor';
|
||||
@@ -17,13 +16,14 @@ import { MatchEvents } from '../../../../../typings/match';
|
||||
import { useProfile } from '../hooks/useProfile';
|
||||
|
||||
export const MatchApp = () => {
|
||||
const Nui = useNuiRequest();
|
||||
const match = useApp('MATCH');
|
||||
const [activePage, setActivePage] = useState(0);
|
||||
const { noProfileExists } = useProfile();
|
||||
|
||||
useEffect(() => {
|
||||
Nui.send(MatchEvents.INITIALIZE);
|
||||
}, []);
|
||||
}, [Nui]);
|
||||
|
||||
const handlePageChange = (e, page) => setActivePage(page);
|
||||
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import React, { useState } from 'react';
|
||||
import { makeStyles } from '@material-ui/core/styles';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
||||
import { useNuiRequest } from 'fivem-nui-react-lib';
|
||||
import {
|
||||
Profile as IProfile,
|
||||
FormattedProfile,
|
||||
@@ -40,10 +39,11 @@ interface IProps {
|
||||
}
|
||||
|
||||
export function ProfileForm({ profile, showPreview }: IProps) {
|
||||
const Nui = useNuiRequest();
|
||||
const classes = useStyles();
|
||||
const { t } = useTranslation();
|
||||
const { config } = usePhone();
|
||||
|
||||
|
||||
// note that this assumes we are defensively checking
|
||||
// that profile is not null in a parent above this component.
|
||||
// Annoyingling adding conditionals above this line to not render
|
||||
|
||||
@@ -6,7 +6,7 @@ import { useMatches } from '../../hooks/useMatches';
|
||||
import Loader from '../Loader';
|
||||
import PageText from '../PageText';
|
||||
import Match from '../matches/Match';
|
||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
||||
import { useNuiRequest } from 'fivem-nui-react-lib';
|
||||
import { MatchEvents } from '../../../../../../typings/match';
|
||||
|
||||
const useStyles = makeStyles({
|
||||
@@ -18,6 +18,7 @@ const useStyles = makeStyles({
|
||||
const MINIMUM_LOAD_TIME = 1500;
|
||||
|
||||
function MatchList() {
|
||||
const Nui = useNuiRequest();
|
||||
const classes = useStyles();
|
||||
const { t } = useTranslation();
|
||||
const { matches, error } = useMatches();
|
||||
@@ -34,7 +35,7 @@ function MatchList() {
|
||||
window.setTimeout(() => {
|
||||
setLoaded(true);
|
||||
}, MINIMUM_LOAD_TIME);
|
||||
}, []);
|
||||
}, [Nui]);
|
||||
|
||||
if (error) return <PageText text={t('APPS_MATCH_MATCHES_ERROR')} />;
|
||||
if (!loaded || !matches) return <Loader />;
|
||||
|
||||
@@ -3,7 +3,7 @@ import { matchState } from './state';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent';
|
||||
import { useNuiEvent } from 'fivem-nui-react-lib';
|
||||
import { Profile, FormattedProfile, Match, MatchEvents } from '../../../../../typings/match';
|
||||
import { IAlert, useSnackbar } from '../../../ui/hooks/useSnackbar';
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import { useRecoilState, useRecoilValue } from 'recoil';
|
||||
import { matchState } from './state';
|
||||
|
||||
import { FormattedProfile, MatchEvents } from '../../../../../typings/match';
|
||||
import Nui from '../../../os/nui-events/utils/Nui';
|
||||
import { useNuiRequest } from 'fivem-nui-react-lib';
|
||||
|
||||
interface IUseProfiles {
|
||||
profiles: FormattedProfile[];
|
||||
@@ -12,6 +12,7 @@ interface IUseProfiles {
|
||||
}
|
||||
|
||||
export const useProfiles = (): IUseProfiles => {
|
||||
const Nui = useNuiRequest();
|
||||
const [profiles, setProfiles] = useRecoilState(matchState.profiles);
|
||||
const error = useRecoilValue(matchState.errorLoadingProfiles);
|
||||
|
||||
|
||||
@@ -9,17 +9,18 @@ import { Route, Switch, useHistory } from 'react-router-dom';
|
||||
import { MessageModal } from './modal/MessageModal';
|
||||
import InjectDebugData from '../../../os/debug/InjectDebugData';
|
||||
import NewMessageGroupButton from './form/NewMessageGroupButton';
|
||||
import Nui from '../../../os/nui-events/utils/Nui';
|
||||
import { useNuiRequest } from 'fivem-nui-react-lib';
|
||||
import { MessagesThemeProvider } from '../providers/MessagesThemeProvider';
|
||||
import { MessageEvents } from '../../../../../typings/messages';
|
||||
|
||||
export const MessagesApp = () => {
|
||||
const Nui = useNuiRequest();
|
||||
const messages = useApp('MESSAGES');
|
||||
const history = useHistory();
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
Nui.send(MessageEvents.FETCH_MESSAGE_GROUPS);
|
||||
}, []);
|
||||
}, [Nui]);
|
||||
|
||||
return (
|
||||
<MessagesThemeProvider>
|
||||
|
||||
@@ -3,7 +3,7 @@ import { useTranslation } from 'react-i18next';
|
||||
import { Paper, Box, makeStyles, TextField, Button } from '@material-ui/core';
|
||||
import SendIcon from '@material-ui/icons/Send';
|
||||
import ImageIcon from '@material-ui/icons/Image';
|
||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
||||
import { useNuiRequest } from 'fivem-nui-react-lib';
|
||||
import { MessageEvents } from '../../../../../../typings/messages';
|
||||
|
||||
interface IProps {
|
||||
@@ -17,6 +17,7 @@ const useStyles = makeStyles({
|
||||
});
|
||||
|
||||
const MessageInput = ({ messageGroupId, onAddImageClick }: IProps) => {
|
||||
const Nui = useNuiRequest();
|
||||
const { t } = useTranslation();
|
||||
const classes = useStyles();
|
||||
const [message, setMessage] = useState('');
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import React, { useCallback, useEffect, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Box, Button, TextField } from '@material-ui/core';
|
||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
||||
import { useNuiRequest } from 'fivem-nui-react-lib';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import { Autocomplete } from '@material-ui/lab';
|
||||
import { useContacts } from '../../../contacts/hooks/useContacts';
|
||||
@@ -11,6 +11,7 @@ import { PHONE_NUMBER_REGEX } from '../../../../../../typings/phone';
|
||||
import { useSnackbar } from '../../../../ui/hooks/useSnackbar';
|
||||
|
||||
const NewMessageGroupForm = ({ phoneNumber }: { phoneNumber?: string }) => {
|
||||
const Nui = useNuiRequest();
|
||||
const history = useHistory();
|
||||
const { t } = useTranslation();
|
||||
const { addAlert } = useSnackbar();
|
||||
@@ -42,7 +43,7 @@ const NewMessageGroupForm = ({ phoneNumber }: { phoneNumber?: string }) => {
|
||||
setParticipants([]);
|
||||
history.push('/messages');
|
||||
}
|
||||
}, [history, label, participants, isGroupChat]);
|
||||
}, [history, label, participants, isGroupChat, Nui]);
|
||||
|
||||
const onAutocompleteChange = (_e, value: any) => {
|
||||
const lastIdx = value.length - 1;
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { Box, List } from '@material-ui/core';
|
||||
import { MessageEvents, MessageGroup } from '../../../../../../typings/messages';
|
||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
||||
import { MessageGroup } from '../../../../../../typings/messages';
|
||||
import useMessages from '../../hooks/useMessages';
|
||||
import MessageGroupItem from './MessageGroupItem';
|
||||
import useStyles from './list.styles';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import { goToConversation } from '../../utils/goToConversation';
|
||||
import { SearchField } from '../../../../ui/components/SearchField';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
@@ -17,6 +15,7 @@ const MessagesList = (): any => {
|
||||
|
||||
const {
|
||||
messageGroups,
|
||||
goToConversation,
|
||||
createMessageGroupResult,
|
||||
clearMessageGroupResult,
|
||||
getMessageGroupById,
|
||||
@@ -41,7 +40,7 @@ const MessagesList = (): any => {
|
||||
const findGroup = getMessageGroupById(createMessageGroupResult.groupId);
|
||||
clearMessageGroupResult();
|
||||
if (findGroup) {
|
||||
goToConversation(findGroup, history);
|
||||
goToConversation(findGroup);
|
||||
}
|
||||
}
|
||||
}, [
|
||||
@@ -51,12 +50,13 @@ const MessagesList = (): any => {
|
||||
history,
|
||||
setActiveMessageGroup,
|
||||
getMessageGroupById,
|
||||
goToConversation,
|
||||
]);
|
||||
|
||||
if (!messageGroups) return null;
|
||||
|
||||
const handleClick = (messageGroup: MessageGroup) => () => {
|
||||
goToConversation(messageGroup, history);
|
||||
goToConversation(messageGroup);
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import qs from 'qs';
|
||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
||||
import { useNuiRequest } from 'fivem-nui-react-lib';
|
||||
import Modal from '../../../../ui/components/Modal';
|
||||
import PhotoLibraryIcon from '@material-ui/icons/PhotoLibrary';
|
||||
import { Box, Typography, Button } from '@material-ui/core';
|
||||
@@ -18,6 +18,7 @@ interface IProps {
|
||||
}
|
||||
|
||||
export const MessageImageModal = ({ isOpen, messageGroupId, onClose, image }: IProps) => {
|
||||
const Nui = useNuiRequest();
|
||||
const history = useHistory();
|
||||
const { pathname, search } = useLocation();
|
||||
const [queryParamImagePreview, setQueryParamImagePreview] = useState(null);
|
||||
@@ -35,7 +36,7 @@ export const MessageImageModal = ({ isOpen, messageGroupId, onClose, image }: IP
|
||||
});
|
||||
onClose();
|
||||
},
|
||||
[messageGroupId, onClose],
|
||||
[messageGroupId, onClose, Nui],
|
||||
);
|
||||
|
||||
const sendFromQueryParam = useCallback(
|
||||
|
||||
@@ -17,7 +17,7 @@ import useStyles from './modal.styles';
|
||||
import useMessages from '../../hooks/useMessages';
|
||||
import Conversation, { CONVERSATION_ELEMENT_ID } from './Conversation';
|
||||
import MessageSkeletonList from './MessageSkeletonList';
|
||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
||||
import { useNuiRequest } from 'fivem-nui-react-lib';
|
||||
import { useHistory, useLocation, useParams } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import Modal from '../../../../ui/components/Modal';
|
||||
@@ -48,6 +48,7 @@ const memberDisplay = (display, number, myNumber, t) => {
|
||||
};
|
||||
|
||||
export const MessageModal = () => {
|
||||
const Nui = useNuiRequest();
|
||||
const classes = useStyles();
|
||||
const history = useHistory();
|
||||
const { number: myNumber } = useSimcard();
|
||||
@@ -97,7 +98,7 @@ export const MessageModal = () => {
|
||||
groupId: activeMessageGroup.groupId,
|
||||
});
|
||||
}
|
||||
}, [activeMessageGroup]);
|
||||
}, [activeMessageGroup, Nui]);
|
||||
|
||||
// don't allow too many characters, it takes too much room
|
||||
let header = activeMessageGroup ? activeMessageGroup.groupDisplay : '';
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import { useCallback } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
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';
|
||||
import useMessages from './useMessages';
|
||||
|
||||
const NOTIFICATION_ID = 'messages:broadcast';
|
||||
@@ -13,7 +11,7 @@ export const useMessageNotifications = () => {
|
||||
const history = useHistory();
|
||||
const { removeId, addNotification, addNotificationAlert } = useNotifications();
|
||||
const { icon, notificationIcon } = useApp('MESSAGES');
|
||||
const { getMessageGroupById, activeMessageGroup } = useMessages();
|
||||
const { getMessageGroupById, activeMessageGroup, goToConversation } = useMessages();
|
||||
|
||||
// Remove notifications from groups when opening them
|
||||
history.listen((location) => {
|
||||
@@ -39,7 +37,7 @@ export const useMessageNotifications = () => {
|
||||
id,
|
||||
sound: true,
|
||||
title: group.label || group.groupDisplay,
|
||||
onClick: () => goToConversation(group, history),
|
||||
onClick: () => goToConversation(group),
|
||||
content: message,
|
||||
icon,
|
||||
notificationIcon,
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import { useRecoilState, useSetRecoilState } from 'recoil';
|
||||
import { messageState } from './state';
|
||||
import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent';
|
||||
import { useNuiEvent, useNuiRequest } from 'fivem-nui-react-lib';
|
||||
import { IAlert, useSnackbar } from '../../../ui/hooks/useSnackbar';
|
||||
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';
|
||||
import { TOptionsBase } from 'i18next';
|
||||
|
||||
export const useMessagesService = () => {
|
||||
const Nui = useNuiRequest();
|
||||
const { pathname } = useLocation();
|
||||
const [activeMessageGroup, setActiveMessageGroup] = useRecoilState(
|
||||
messageState.activeMessageGroup,
|
||||
@@ -43,7 +43,7 @@ export const useMessagesService = () => {
|
||||
}
|
||||
setNotification({ groupId, message });
|
||||
},
|
||||
[activeMessageGroup, pathname, setNotification],
|
||||
[activeMessageGroup, pathname, setNotification, Nui],
|
||||
);
|
||||
|
||||
const _setMessageGroups = useCallback(
|
||||
|
||||
@@ -1,7 +1,14 @@
|
||||
import { useCallback } from 'react';
|
||||
import { useRecoilState, useRecoilValue } from 'recoil';
|
||||
import { CreateMessageGroupResult, Message, MessageGroup } from '../../../../../typings/messages';
|
||||
import {
|
||||
CreateMessageGroupResult,
|
||||
Message,
|
||||
MessageEvents,
|
||||
MessageGroup,
|
||||
} from '../../../../../typings/messages';
|
||||
import { messageState } from './state';
|
||||
import { useNuiRequest } from 'fivem-nui-react-lib';
|
||||
import { useHistory } from 'react-router';
|
||||
|
||||
interface IUseMessages {
|
||||
messages?: Message[] | null;
|
||||
@@ -12,9 +19,13 @@ interface IUseMessages {
|
||||
getMessageGroupById: (id: string) => MessageGroup | null;
|
||||
setActiveMessageGroup: (groupId: string) => MessageGroup | null;
|
||||
activeMessageGroup: MessageGroup | null;
|
||||
goToConversation(g: Pick<MessageGroup, 'groupId'>): void;
|
||||
}
|
||||
|
||||
export default (): IUseMessages => {
|
||||
const useMessages = (): IUseMessages => {
|
||||
const Nui = useNuiRequest();
|
||||
const history = useHistory();
|
||||
|
||||
const [messages, setMessages] = useRecoilState<Message[] | null>(messageState.messages);
|
||||
const messageGroups = useRecoilValue<MessageGroup[] | null>(messageState.messageGroups);
|
||||
const [activeMessageGroup, _setActiveMessageGroup] = useRecoilState<MessageGroup | null>(
|
||||
@@ -44,6 +55,12 @@ export default (): IUseMessages => {
|
||||
[_setActiveMessageGroup, getMessageGroupById],
|
||||
);
|
||||
|
||||
const goToConversation = (messageGroup) => {
|
||||
if (!messageGroup?.groupId || !history) return;
|
||||
history.push(`/messages/conversations/${messageGroup.groupId}`);
|
||||
Nui.send(MessageEvents.FETCH_MESSAGES, { groupId: messageGroup.groupId });
|
||||
};
|
||||
|
||||
return {
|
||||
messages,
|
||||
setMessages,
|
||||
@@ -53,5 +70,8 @@ export default (): IUseMessages => {
|
||||
getMessageGroupById,
|
||||
activeMessageGroup,
|
||||
setActiveMessageGroup,
|
||||
goToConversation,
|
||||
};
|
||||
};
|
||||
|
||||
export default useMessages;
|
||||
@@ -1,8 +0,0 @@
|
||||
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(MessageEvents.FETCH_MESSAGES, { groupId: messageGroup.groupId });
|
||||
};
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useSetRecoilState } from 'recoil';
|
||||
import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent';
|
||||
import { useNuiEvent } from 'fivem-nui-react-lib';
|
||||
import { noteStates } from './state';
|
||||
import { IAlert, useSnackbar } from '../../../ui/hooks/useSnackbar';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
@@ -12,13 +12,14 @@ import React from 'react';
|
||||
import ArrowBackIcon from '@material-ui/icons/ArrowBack';
|
||||
import { useNoteDetail } from '../hooks/useNoteDetail';
|
||||
import useStyles from './modal.styles';
|
||||
import Nui from '../../../os/nui-events/utils/Nui';
|
||||
import { useNuiRequest } from 'fivem-nui-react-lib';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import { StatusButton } from '../../../ui/components/StatusButton';
|
||||
import { NotesEvents } from '../../../../../typings/notes';
|
||||
|
||||
export const NoteModal = () => {
|
||||
const Nui = useNuiRequest();
|
||||
const classes = useStyles();
|
||||
const history = useHistory();
|
||||
const { t } = useTranslation();
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import React, { useCallback, useState, useEffect } from 'react';
|
||||
import { makeStyles } from '@material-ui/core/styles';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
import Nui from '../../../os/nui-events/utils/Nui';
|
||||
import { useNuiRequest } from 'fivem-nui-react-lib';
|
||||
import Modal from '../../../ui/components/Modal';
|
||||
import { IMAGE_DELIMITER } from '../utils/images';
|
||||
import { isImageValid } from '../../../common/utils/isImageValid';
|
||||
@@ -51,6 +50,7 @@ interface Image {
|
||||
}
|
||||
|
||||
export const AddTweetModal = () => {
|
||||
const Nui = useNuiRequest();
|
||||
const classes = useStyles();
|
||||
const { message, setMessage, modalVisible, setModalVisible } = useModal();
|
||||
const { config } = usePhone();
|
||||
|
||||
@@ -3,8 +3,7 @@ import { useTranslation } from 'react-i18next';
|
||||
import { makeStyles } from '@material-ui/core/styles';
|
||||
import { TextField } from '@material-ui/core';
|
||||
import TweetList from './tweet/TweetList';
|
||||
|
||||
import Nui from '../../../os/nui-events/utils/Nui';
|
||||
import { useNuiRequest } from 'fivem-nui-react-lib';
|
||||
import SearchButton from './buttons/SearchButton';
|
||||
import { useFilteredTweets } from '../hooks/useFilteredTweets';
|
||||
import { TwitterEvents } from '../../../../../typings/twitter';
|
||||
@@ -22,6 +21,7 @@ const useStyles = makeStyles({
|
||||
});
|
||||
|
||||
function TwitterSearch() {
|
||||
const Nui = useNuiRequest();
|
||||
const classes = useStyles();
|
||||
const { t } = useTranslation();
|
||||
const [searchValue, setSearchValue] = useState('');
|
||||
|
||||
@@ -2,13 +2,13 @@ import React, { useState } from 'react';
|
||||
import { Button, CircularProgress } from '@material-ui/core';
|
||||
import FavoriteBorderIcon from '@material-ui/icons/FavoriteBorder';
|
||||
import FavoriteIcon from '@material-ui/icons/Favorite';
|
||||
|
||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
||||
import { useNuiRequest } from 'fivem-nui-react-lib';
|
||||
import { TwitterEvents } from '../../../../../../typings/twitter';
|
||||
|
||||
const LOADING_TIME = 1250;
|
||||
|
||||
function LikeButton({ tweetId, isLiked }) {
|
||||
const Nui = useNuiRequest();
|
||||
const [liked, setLiked] = useState(isLiked);
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
|
||||
@@ -2,13 +2,13 @@ import React, { useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Button, CircularProgress, MenuItem } from '@material-ui/core';
|
||||
import DoneIcon from '@material-ui/icons/Done';
|
||||
|
||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
||||
import { useNuiRequest } from 'fivem-nui-react-lib';
|
||||
import { TwitterEvents } from '../../../../../../typings/twitter';
|
||||
|
||||
const LOADING_TIME = 1250;
|
||||
|
||||
function ReportButton({ handleClose, tweetId, isReported }) {
|
||||
const Nui = useNuiRequest();
|
||||
const { t } = useTranslation();
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import React, { useState } from 'react';
|
||||
import { CircularProgress, makeStyles, Button } from '@material-ui/core';
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import { faRetweet } from '@fortawesome/free-solid-svg-icons';
|
||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
||||
import { useNuiRequest } from 'fivem-nui-react-lib';
|
||||
import { TwitterEvents } from '../../../../../../typings/twitter';
|
||||
|
||||
interface IProps {
|
||||
@@ -20,6 +20,7 @@ const useStyles = makeStyles((theme) => ({
|
||||
const LOADING_TIME = 1250;
|
||||
|
||||
export const RetweetButton = ({ tweetId, isRetweet, retweetId }: IProps) => {
|
||||
const Nui = useNuiRequest();
|
||||
const [retweeted, setRetweeted] = useState(false);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const classes = useStyles();
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import React, { useState } from 'react';
|
||||
import { makeStyles } from '@material-ui/core/styles';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
||||
import { useNuiRequest } from 'fivem-nui-react-lib';
|
||||
import { useProfile } from '../../hooks/useProfile';
|
||||
import Avatar from '../Avatar';
|
||||
import ProfileUpdateButton from '../buttons/ProfileUpdateButton';
|
||||
@@ -23,6 +22,7 @@ const useStyles = makeStyles((theme) => ({
|
||||
}));
|
||||
|
||||
export function Profile() {
|
||||
const Nui = useNuiRequest();
|
||||
const classes = useStyles();
|
||||
const { t } = useTranslation();
|
||||
const { profile } = useProfile();
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import React, { useState } from 'react';
|
||||
import { makeStyles } from '@material-ui/core/styles';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
||||
import { useNuiRequest } from 'fivem-nui-react-lib';
|
||||
import ProfileField from '../../../../ui/components/ProfileField';
|
||||
import { useProfile } from '../../hooks/useProfile';
|
||||
import ProfileUpdateButton from '../buttons/ProfileUpdateButton';
|
||||
@@ -25,6 +24,7 @@ const useStyles = makeStyles((theme) => ({
|
||||
}));
|
||||
|
||||
export function ProfilePrompt() {
|
||||
const Nui = useNuiRequest();
|
||||
const classes = useStyles();
|
||||
const { t } = useTranslation();
|
||||
const { profile } = useProfile();
|
||||
|
||||
@@ -3,13 +3,14 @@ import { useTranslation } from 'react-i18next';
|
||||
import { Button, Menu, MenuItem } from '@material-ui/core';
|
||||
import MoreIcon from '@material-ui/icons/MoreVert';
|
||||
import { usePhone } from '../../../../os/phone/hooks/usePhone';
|
||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
||||
import { useNuiRequest } from 'fivem-nui-react-lib';
|
||||
import ReportButton from '../buttons/ReportButton';
|
||||
import { TwitterEvents } from '../../../../../../typings/twitter';
|
||||
|
||||
export const ShowMore = ({ id, isReported, isMine }) => {
|
||||
const [anchorEl, setAnchorEl] = useState<Element | null>(null);
|
||||
const Nui = useNuiRequest();
|
||||
const { t } = useTranslation();
|
||||
const [anchorEl, setAnchorEl] = useState<Element | null>(null);
|
||||
const { config } = usePhone();
|
||||
|
||||
if (!config) return null;
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
import React, { useEffect } from 'react';
|
||||
|
||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
||||
import { useNuiRequest } from 'fivem-nui-react-lib';
|
||||
import { useTweets } from '../../hooks/useTweets';
|
||||
import { useTwitterNotifications } from '../../hooks/useTwitterNotifications';
|
||||
import TweetList from './TweetList';
|
||||
import { TwitterEvents } from '../../../../../../typings/twitter';
|
||||
|
||||
export function TweetListContainer() {
|
||||
const Nui = useNuiRequest();
|
||||
const { tweets } = useTweets();
|
||||
const { setUnreadCount } = useTwitterNotifications();
|
||||
|
||||
useEffect(() => {
|
||||
Nui.send(TwitterEvents.FETCH_TWEETS, {});
|
||||
}, []);
|
||||
}, [Nui]);
|
||||
|
||||
useEffect(() => {
|
||||
if (tweets?.length) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useRecoilState, useSetRecoilState } from 'recoil';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent';
|
||||
import { useNuiEvent } from 'fivem-nui-react-lib';
|
||||
import { IMAGE_DELIMITER } from '../utils/images';
|
||||
import { APP_TWITTER } from '../utils/constants';
|
||||
import { twitterState } from './state';
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { useEffect } from 'react';
|
||||
import Nui from '../../nui-events/utils/Nui';
|
||||
import { useNuiRequest } from 'fivem-nui-react-lib';
|
||||
|
||||
export const AppWithStartup = ({ children, id }) => {
|
||||
const Nui = useNuiRequest();
|
||||
useEffect(() => {
|
||||
Nui.send(`npwd:app:${id}`);
|
||||
}, [id]);
|
||||
}, [Nui, id]);
|
||||
return children;
|
||||
};
|
||||
@@ -1,8 +1,8 @@
|
||||
import { useRecoilState } from 'recoil';
|
||||
import { CallProps } from '../../../../../typings/call';
|
||||
import Nui from '../../nui-events/utils/Nui';
|
||||
import { callerState } from './state';
|
||||
import { CallEvents } from '../../../../../typings/call';
|
||||
import { useNuiRequest } from 'fivem-nui-react-lib';
|
||||
|
||||
interface CallHook {
|
||||
call: CallProps;
|
||||
@@ -13,6 +13,7 @@ interface CallHook {
|
||||
}
|
||||
|
||||
export const useCall = (): CallHook => {
|
||||
const Nui = useNuiRequest();
|
||||
const [call, setCall] = useRecoilState(callerState.currentCall);
|
||||
|
||||
const acceptCall = () => {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useNuiEvent } from '../../nui-events/hooks/useNuiEvent';
|
||||
import { useSetRecoilState } from 'recoil';
|
||||
import { useCall } from './useCall';
|
||||
import { CallEvents, CallProps } from '../../../../../typings/call';
|
||||
@@ -8,6 +7,7 @@ import { useCallModal } from './useCallModal';
|
||||
import { useHistory, useLocation } from 'react-router-dom';
|
||||
import { callerState } from './state';
|
||||
import { useCallNotifications } from './useCallNotifications';
|
||||
import { useNuiEvent } from 'fivem-nui-react-lib';
|
||||
|
||||
// InjectDebugData<CallProps | boolean>([
|
||||
// {
|
||||
@@ -55,9 +55,9 @@ export const useCallService = () => {
|
||||
}, [history, modal, pathname, modalHasBeenOpenedThisCall]);
|
||||
|
||||
const _setCall = (_call: CallProps) => {
|
||||
setCall(_call);
|
||||
setCall({ ...call, ..._call });
|
||||
setNotification(_call);
|
||||
};
|
||||
useNuiEvent<CallProps>('CALL', CallEvents.SET_CALLER, _setCall, call);
|
||||
useNuiEvent<boolean>('CALL', CallEvents.SET_CALL_MODAL, setModal);
|
||||
useNuiEvent('CALL', CallEvents.SET_CALLER, _setCall);
|
||||
useNuiEvent('CALL', CallEvents.SET_CALL_MODAL, setModal);
|
||||
};
|
||||
@@ -1,55 +0,0 @@
|
||||
import { MutableRefObject, useEffect, useRef } from 'react';
|
||||
import { eventNameFactory } from '../utils/nuiUtils';
|
||||
import DebugLog from '../../debug/LogDebugEvents';
|
||||
|
||||
interface IOptions {
|
||||
capture?: boolean;
|
||||
passive?: boolean;
|
||||
once?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* A hook that manage events listeners for receiving data from the NUI
|
||||
* @param app The app name in which this hoook is used
|
||||
* @param method The specific `method` field that should be listened for.
|
||||
* @param handler The callback function that will handle data relayed by this hook
|
||||
* @param options Any options to pass to the addEventListener
|
||||
**/
|
||||
|
||||
const defaultOptions = {};
|
||||
|
||||
export const useNuiEvent = <S = Record<string, unknown>>(
|
||||
app: string,
|
||||
method: string,
|
||||
handler: Function,
|
||||
currentState?: S,
|
||||
options: IOptions = defaultOptions,
|
||||
) => {
|
||||
const savedHandler: MutableRefObject<any> = useRef();
|
||||
|
||||
// When handler value changes set mutable ref to handler val
|
||||
useEffect(() => {
|
||||
savedHandler.current = handler;
|
||||
}, [handler]);
|
||||
|
||||
// Will run every rerender
|
||||
useEffect(() => {
|
||||
const eventName = eventNameFactory(app, method);
|
||||
const eventListener = (event) => {
|
||||
if (savedHandler.current && savedHandler.current.call) {
|
||||
const { data } = event;
|
||||
DebugLog({
|
||||
action: `NUI Data Received (${eventName})`,
|
||||
data: event.data,
|
||||
level: 1,
|
||||
});
|
||||
const newData = currentState ? { ...currentState, ...data } : data;
|
||||
savedHandler.current(newData);
|
||||
}
|
||||
};
|
||||
|
||||
window.addEventListener(eventName, eventListener, options);
|
||||
// Remove Event Listener on component cleanup
|
||||
return () => window.removeEventListener(eventName, eventListener, options);
|
||||
}, [app, method, currentState, options]);
|
||||
};
|
||||
@@ -1,104 +0,0 @@
|
||||
import { FetchData } from '@sentry/tracing/dist/browser/request';
|
||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||
import Nui, { IAbortableFetch } from '../utils/Nui';
|
||||
import { eventNameFactory } from '../utils/nuiUtils';
|
||||
import { useNuiEvent } from './useNuiEvent';
|
||||
|
||||
type UseNuiEventCallbackResponse<I, R> = [
|
||||
(d?: I) => void,
|
||||
{ loading: boolean; error: any; response: R },
|
||||
];
|
||||
|
||||
export const useNuiEventCallback = <I = FetchData, R = FetchData>(
|
||||
app: string,
|
||||
method: string,
|
||||
handler?: (res: R) => void,
|
||||
errHandler?: Function,
|
||||
): UseNuiEventCallbackResponse<I, R> => {
|
||||
const fetchRef = useRef<IAbortableFetch>();
|
||||
const timeoutRef = useRef<NodeJS.Timeout>();
|
||||
|
||||
// These are Refs to avoid re renders.
|
||||
// We dont care if "app" and "method" arguments change.
|
||||
const eventNameRef = useRef<string>(eventNameFactory(app, method));
|
||||
const methodNameRef = useRef<string>(method);
|
||||
const appNameRef = useRef<string>(app);
|
||||
|
||||
const [timedOut, setTimedOut] = useState<boolean>(false);
|
||||
const [loading, setLoading] = useState<boolean>(false);
|
||||
const [error, setError] = useState<any>(null);
|
||||
const [response, setResponse] = useState<R>(null);
|
||||
|
||||
const onSuccess = useCallback(
|
||||
(data: R) => {
|
||||
if (!loading) {
|
||||
return;
|
||||
}
|
||||
// If we receive eventNameSuccess event, clear timeout
|
||||
timeoutRef.current && clearTimeout(timeoutRef.current);
|
||||
// If already timed out, don't do shit :)
|
||||
if (timedOut) {
|
||||
return;
|
||||
}
|
||||
// Set new state after success event received
|
||||
setResponse(data);
|
||||
setError(null);
|
||||
setLoading(false);
|
||||
handler?.(data);
|
||||
},
|
||||
[handler, timedOut, loading],
|
||||
);
|
||||
|
||||
const onError = useCallback(
|
||||
(err: any) => {
|
||||
if (!loading) {
|
||||
return;
|
||||
}
|
||||
// If we receive eventNameSuccess event, clear timeout
|
||||
timeoutRef.current && clearTimeout(timeoutRef.current);
|
||||
// If already timed out, don't do shit :)
|
||||
if (timedOut) {
|
||||
return;
|
||||
}
|
||||
// Set new state after error event received
|
||||
setError(err);
|
||||
setResponse(null);
|
||||
setLoading(false);
|
||||
errHandler?.(err);
|
||||
},
|
||||
[errHandler, timedOut, loading],
|
||||
);
|
||||
|
||||
// React to loading change and starting timeout timer.
|
||||
useEffect(() => {
|
||||
if (loading && !timeoutRef.current) {
|
||||
clearTimeout(timeoutRef.current);
|
||||
timeoutRef.current = setTimeout(() => {
|
||||
setTimedOut(true);
|
||||
onError(
|
||||
new Error(`${eventNameRef.current} NUI Event Callback timed out after 10000 seconds`),
|
||||
);
|
||||
fetchRef.current && fetchRef.current.abort();
|
||||
timeoutRef.current = undefined;
|
||||
fetchRef.current = undefined;
|
||||
}, 10000);
|
||||
}
|
||||
}, [loading, onError]);
|
||||
|
||||
// Handle the success and error events for this method
|
||||
useNuiEvent(appNameRef.current, `${methodNameRef.current}Success`, onSuccess);
|
||||
useNuiEvent(appNameRef.current, `${methodNameRef.current}Error`, onError);
|
||||
|
||||
// Only fetch if we are not loading/waiting the events.
|
||||
const fetch = useCallback((data?: I) => {
|
||||
setLoading((curr) => {
|
||||
if (!curr) {
|
||||
fetchRef.current = Nui.sendAbortable(methodNameRef.current, data);
|
||||
return true;
|
||||
}
|
||||
return curr;
|
||||
});
|
||||
}, []);
|
||||
|
||||
return [fetch, { loading, response, error }];
|
||||
};
|
||||
@@ -1,27 +0,0 @@
|
||||
import { useEffect } from 'react';
|
||||
import { eventNameFactory } from '../utils/nuiUtils';
|
||||
|
||||
interface IOptions {
|
||||
capture?: boolean;
|
||||
passive?: boolean;
|
||||
once?: boolean;
|
||||
}
|
||||
|
||||
export const useNuiService = (options: IOptions = {}) => {
|
||||
const { capture, passive, once } = options;
|
||||
const eventListener = (event: any) => {
|
||||
const { app, method, data } = event.data;
|
||||
if (app && method && data !== undefined) {
|
||||
window.dispatchEvent(
|
||||
new MessageEvent(eventNameFactory(app, method), {
|
||||
data,
|
||||
}),
|
||||
);
|
||||
}
|
||||
};
|
||||
useEffect(() => {
|
||||
const opts = { capture, passive, once };
|
||||
window.addEventListener('message', eventListener, opts);
|
||||
return () => window.removeEventListener('message', eventListener, opts);
|
||||
}, [capture, passive, once]);
|
||||
};
|
||||
@@ -1,36 +0,0 @@
|
||||
export interface IAbortableFetch {
|
||||
abort: () => void;
|
||||
promise: Promise<Response>;
|
||||
}
|
||||
|
||||
function abortableFetch(request, opts): IAbortableFetch {
|
||||
const controller = new AbortController();
|
||||
const signal = controller.signal;
|
||||
|
||||
return {
|
||||
abort: () => controller.abort(),
|
||||
promise: fetch(request, { ...opts, signal }),
|
||||
};
|
||||
}
|
||||
|
||||
function getParams(event, data): [RequestInfo, RequestInit] {
|
||||
return [
|
||||
`https://new-phone-who-dis/${event}`,
|
||||
{
|
||||
method: 'post',
|
||||
headers: {
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
},
|
||||
body: JSON.stringify(data),
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
export default {
|
||||
async send(event: any, data = {}) {
|
||||
return fetch(...getParams(event, data));
|
||||
},
|
||||
sendAbortable(event: any, data = {}): IAbortableFetch {
|
||||
return abortableFetch(...getParams(event, data));
|
||||
},
|
||||
};
|
||||
@@ -1,3 +0,0 @@
|
||||
export const eventNameFactory = (app: string, method: string) => `${app}:${method}`;
|
||||
|
||||
export const eventNameMethod = (name: string) => name.split(':')[1] || null;
|
||||
@@ -2,7 +2,7 @@ import { useRecoilValue } from 'recoil';
|
||||
import { IServerConfig } from '../../../../../typings/config';
|
||||
import ServerConfig from '../../../config.autogen.json';
|
||||
import { useNotifications } from '../../notifications/hooks/useNotifications';
|
||||
import Nui from '../../nui-events/utils/Nui';
|
||||
import { useNuiRequest } from 'fivem-nui-react-lib';
|
||||
import { phoneState } from './state';
|
||||
import { PhoneEvents } from '../../../../../typings/phone';
|
||||
|
||||
@@ -15,6 +15,7 @@ interface IUsePhone {
|
||||
}
|
||||
|
||||
export const usePhone = (): IUsePhone => {
|
||||
const Nui = useNuiRequest();
|
||||
const isPhoneOpen = useRecoilValue(phoneState.visibility);
|
||||
const isPhoneReady = useRecoilValue(phoneState.phoneReady);
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useNuiEvent } from 'fivem-nui-react-lib';
|
||||
import { useSetRecoilState } from 'recoil';
|
||||
import { phoneState } from './state';
|
||||
import { useNuiEvent } from '../../nui-events/hooks/useNuiEvent';
|
||||
|
||||
export const usePhoneService = () => {
|
||||
const setVisibility = useSetRecoilState(phoneState.visibility);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { useNuiEvent } from '../../nui-events/hooks/useNuiEvent';
|
||||
import { useSetRecoilState } from 'recoil';
|
||||
import { simcardState } from './state';
|
||||
import { useSimcard } from './useSimcard';
|
||||
import InjectDebugData from '../../debug/InjectDebugData';
|
||||
import { useNuiEvent } from 'fivem-nui-react-lib';
|
||||
|
||||
InjectDebugData([
|
||||
{
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import React, { useState } from 'react';
|
||||
import { Snackbar, Typography } from '@material-ui/core';
|
||||
import { useNuiEvent } from '../../os/nui-events/hooks/useNuiEvent';
|
||||
import { Alert } from './Alert';
|
||||
import { makeStyles } from '@material-ui/core/styles';
|
||||
import { useNuiEvent } from 'fivem-nui-react-lib';
|
||||
|
||||
const useStyles = makeStyles({
|
||||
root: {
|
||||
|
||||
+29
-11
@@ -6718,6 +6718,13 @@ findup-sync@^3.0.0:
|
||||
micromatch "^3.0.4"
|
||||
resolve-dir "^1.0.1"
|
||||
|
||||
[email protected]:
|
||||
version "2.2.6"
|
||||
resolved "https://registry.yarnpkg.com/fivem-nui-react-lib/-/fivem-nui-react-lib-2.2.6.tgz#2ffc01aee5a01aeb444c7c404e3e2b374b9798d7"
|
||||
integrity sha512-h8WJsyP7/VehkmRdfs9/pjGK73LmZSEeWH4kW0Mo9InC0qIulcTfJnnvdp40fIJ6SSCZLjteSQrUN6f+ZUoKdA==
|
||||
dependencies:
|
||||
typescript "^4.1.2"
|
||||
|
||||
flat-cache@^3.0.4:
|
||||
version "3.0.4"
|
||||
resolved "https://registry.yarnpkg.com/flat-cache/-/flat-cache-3.0.4.tgz#61b0338302b2fe9f957dcc32fc2a87f1c3048b11"
|
||||
@@ -11718,15 +11725,14 @@ react-devtools@^4.10.1:
|
||||
react-devtools-core "4.10.1"
|
||||
update-notifier "^2.1.0"
|
||||
|
||||
react-dom@^16.13.1:
|
||||
version "16.13.1"
|
||||
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.13.1.tgz#c1bd37331a0486c078ee54c4740720993b2e0e7f"
|
||||
integrity sha512-81PIMmVLnCNLO/fFOQxdQkvEq/+Hfpv24XNJfpyZhTRfO0QcmQIF/PgCa1zCOj2w1hrn12MFLyaJ/G0+Mxtfag==
|
||||
react-dom@17:
|
||||
version "17.0.2"
|
||||
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-17.0.2.tgz#ecffb6845e3ad8dbfcdc498f0d0a939736502c23"
|
||||
integrity sha512-s4h96KtLDUQlsENhMn1ar8t2bEa+q/YAtj8pPPdIjPDGBDIVNsrD9aXNWqspUe6AzKCIG0C1HZZLqLV7qpOBGA==
|
||||
dependencies:
|
||||
loose-envify "^1.1.0"
|
||||
object-assign "^4.1.1"
|
||||
prop-types "^15.6.2"
|
||||
scheduler "^0.19.1"
|
||||
scheduler "^0.20.2"
|
||||
|
||||
react-error-overlay@^6.0.9:
|
||||
version "6.0.9"
|
||||
@@ -11891,14 +11897,13 @@ react-transition-group@^4.4.0:
|
||||
loose-envify "^1.4.0"
|
||||
prop-types "^15.6.2"
|
||||
|
||||
react@^16.13.1:
|
||||
version "16.13.1"
|
||||
resolved "https://registry.yarnpkg.com/react/-/react-16.13.1.tgz#2e818822f1a9743122c063d6410d85c1e3afe48e"
|
||||
integrity sha512-YMZQQq32xHLX0bz5Mnibv1/LHb3Sqzngu7xstSM+vrkE5Kzr9xE0yMByK5kMoTK30YVJE61WfbxIFFvfeDKT1w==
|
||||
react@17.0.2:
|
||||
version "17.0.2"
|
||||
resolved "https://registry.yarnpkg.com/react/-/react-17.0.2.tgz#d0b5cc516d29eb3eee383f75b62864cfb6800037"
|
||||
integrity sha512-gnhPt75i/dq/z3/6q/0asP78D0u592D5L1pd7M8P+dck6Fu/jJeL6iVVK23fptSUZj8Vjf++7wXA8UNclGQcbA==
|
||||
dependencies:
|
||||
loose-envify "^1.1.0"
|
||||
object-assign "^4.1.1"
|
||||
prop-types "^15.6.2"
|
||||
|
||||
read-pkg-up@^2.0.0:
|
||||
version "2.0.0"
|
||||
@@ -12500,6 +12505,14 @@ scheduler@^0.19.1:
|
||||
loose-envify "^1.1.0"
|
||||
object-assign "^4.1.1"
|
||||
|
||||
scheduler@^0.20.2:
|
||||
version "0.20.2"
|
||||
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.20.2.tgz#4baee39436e34aa93b4874bddcbf0fe8b8b50e91"
|
||||
integrity sha512-2eWfGgAqqWFGqtdMmcL5zCMK1U8KlXv8SQFGglL3CEtd0aDVDWgeF/YoCmvln55m5zSk3J/20hTaSBeSObsQDQ==
|
||||
dependencies:
|
||||
loose-envify "^1.1.0"
|
||||
object-assign "^4.1.1"
|
||||
|
||||
schema-utils@^1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-1.0.0.tgz#0b79a93204d7b600d4b2850d1f66c2a34951c770"
|
||||
@@ -13746,6 +13759,11 @@ [email protected]:
|
||||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.7.tgz#98d600a5ebdc38f40cb277522f12dc800e9e25fa"
|
||||
integrity sha512-BLbiRkiBzAwsjut4x/dsibSTB6yWpwT5qWmC2OfuCg3GgVQCSgMs4vEctYPhsaGtd0AeuuHMkjZ2h2WG8MSzRw==
|
||||
|
||||
typescript@^4.1.2:
|
||||
version "4.2.3"
|
||||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.2.3.tgz#39062d8019912d43726298f09493d598048c1ce3"
|
||||
integrity sha512-qOcYwxaByStAWrBf4x0fibwZvMRG+r4cQoTjbPtUlrWjBHbmCAww1i448U0GJ+3cNNEtebDteo/cHOR3xJ4wEw==
|
||||
|
||||
[email protected]:
|
||||
version "3.4.10"
|
||||
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.4.10.tgz#9ad9563d8eb3acdfb8d38597d2af1d815f6a755f"
|
||||
|
||||
Reference in new issue
Block a user