fix(calls): fix references to async selector DialerHistory

This commit is contained in:
Taso committed 2021-07-28 14:26:01 -04:00
1 parent 36d1e993bd
commit 10c5e97088
15 files changed
+61 -67

No files matched your search

-3
View File
@@ -9,7 +9,6 @@ import { Navigation } from './os/navigation-bar/components/Navigation';
import { useSimcardService } from './os/simcard/hooks/useSimcardService';
import { usePhoneService } from './os/phone/hooks/usePhoneService';
import { useApps } from './os/apps/hooks/useApps';
import { useNuiRequest } from 'fivem-nui-react-lib';
import { useTwitterService } from './apps/twitter/hooks/useTwitterService';
import { useMatchService } from './apps/match/hooks/useMatchService';
import { useMarketplaceService } from './apps/marketplace/hooks/useMarketplaceService';
@@ -42,8 +41,6 @@ function Phone() {
const { addAlert } = useSnackbar();
const Nui = useNuiRequest();
// Set language from local storage
// This will only trigger on first mount & settings changes
useEffect(() => {
@@ -1,4 +1,4 @@
import React, { useMemo, useState, useCallback, useEffect } from 'react';
import React, { useMemo, useState, useCallback } from 'react';
import useStyles from './modal.styles';
import { Button, Paper } from '@material-ui/core';
import ArrowBackIcon from '@material-ui/icons/ArrowBack';
@@ -8,7 +8,6 @@ import { useHistory } from 'react-router-dom';
import { useQueryParams } from '../../../../common/hooks/useQueryParams';
import { ShareModal } from './ShareModal';
import { GalleryPhoto, PhotoEvents } from '../../../../../../typings/photo';
import { useNuiRequest } from 'fivem-nui-react-lib';
import { usePhotoActions } from '../../hooks/usePhotoActions';
import { fetchNui } from '../../../../utils/fetchNui';
import { ServerPromiseResp } from '../../../../../../typings/common';
@@ -8,7 +8,6 @@ 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';
import { useFilteredContacts } from '../../hooks/state';
import { fetchNui } from '../../../../utils/fetchNui';
import { ServerPromiseResp } from '../../../../../../typings/common';
+1 -22
View File
@@ -21,8 +21,6 @@ const LoadingSpinner: React.FC = () => (
);
export const DialerApp = () => {
const history = useDialHistory();
const dialer = useApp('DIALER');
return (
<DialerThemeProvider>
@@ -35,7 +33,7 @@ export const DialerApp = () => {
</Route>
<Route exact path="/phone">
<React.Suspense fallback={<LoadingSpinner />}>
<DialerHistory calls={history} />
<DialerHistory />
</React.Suspense>
</Route>
<Route path="/phone/contacts" component={ContactList} />
@@ -46,22 +44,3 @@ export const DialerApp = () => {
</DialerThemeProvider>
);
};
InjectDebugData([
{
app: 'DIALER',
method: CallEvents.SET_CALL_HISTORY,
data: [
{
id: 1,
transmitter: '636-6496',
start: 1615946292,
},
{
id: 2,
transmitter: '777-7777',
start: 1615946292,
},
],
},
]);
@@ -16,6 +16,7 @@ import { fetchNui } from '../../../../utils/fetchNui';
import { ServerPromiseResp } from '../../../../../../typings/common';
import { useSnackbar } from '../../../../ui/hooks/useSnackbar';
import { useMyPhoneNumber } from '../../../../os/simcard/hooks/useMyPhoneNumber';
import { useDialHistory } from '../../hooks/useDialHistory';
const useStyles = makeStyles((theme: Theme) => ({
callForward: {
@@ -26,10 +27,11 @@ const useStyles = makeStyles((theme: Theme) => ({
},
}));
export const DialerHistory = ({ calls }) => {
export const DialerHistory: React.FC = () => {
const { addAlert } = useSnackbar();
const myNumber = useMyPhoneNumber();
const { getDisplayByNumber } = useContactActions();
const calls = useDialHistory();
const classes = useStyles();
+23 -3
View File
@@ -1,9 +1,29 @@
import { atom } from 'recoil';
import { CallHistoryItem } from '../../../../../typings/call';
import { atom, selector } from 'recoil';
import { CallEvents, CallHistoryItem } from '../../../../../typings/call';
import { fetchNui } from '../../../utils/fetchNui';
import { ServerPromiseResp } from '../../../../../typings/common';
import LogDebugEvent from '../../../os/debug/LogDebugEvents';
import { isEnvBrowser } from '../../../utils/misc';
import { MockHistoryData } from '../utils/constants';
export const dialState = {
history: atom<CallHistoryItem[]>({
key: 'dialHistory',
default: [],
default: selector({
key: 'dialHistoryDefault',
get: async () => {
try {
const resp = await fetchNui<ServerPromiseResp<CallHistoryItem[]>>(CallEvents.FETCH_CALLS);
LogDebugEvent({ action: 'ContactsFetched', data: resp.data });
return resp.data;
} catch (e) {
if (isEnvBrowser()) {
return MockHistoryData;
}
console.error(e);
return [];
}
},
}),
}),
};
@@ -1,6 +1,4 @@
import { useRecoilValue } from 'recoil';
import { dialState } from './state';
export const useDialHistory = () => {
return useRecoilValue(dialState.history);
};
export const useDialHistory = () => useRecoilValue(dialState.history);
@@ -1,6 +1,4 @@
import { useSetRecoilState } from 'recoil';
import { useNuiEvent } from 'fivem-nui-react-lib';
import { dialState } from './state';
import { CallEvents } from '../../../../../typings/call';
import { IAlert, useSnackbar } from '../../../ui/hooks/useSnackbar';
import { useTranslation } from 'react-i18next';
@@ -16,7 +14,5 @@ export const useDialService = () => {
});
};
const setHistory = useSetRecoilState(dialState.history);
useNuiEvent('DIALER', CallEvents.SET_CALL_HISTORY, setHistory);
useNuiEvent('DIALER', CallEvents.SEND_ALERT, handleAddAlert);
};
+5 -3
View File
@@ -1,10 +1,12 @@
export const MockHistoryData = [
import { CallHistoryItem } from '../../../../../typings/call';
export const MockHistoryData: CallHistoryItem[] = [
{
id: 1,
identifier: 'ca839e8c-ef9d-40bd-b6a3-d531ee58149f',
transmitter: '704-1549',
receiver: '704-1549',
is_accepted: 0,
is_accepted: true,
start: '1615939174',
end: null,
},
@@ -13,7 +15,7 @@ export const MockHistoryData = [
identifier: 'b8080a50-ad30-4ee9-84cb-00688e2bf167',
transmitter: '704-1549',
receiver: '704-1549',
is_accepted: 0,
is_accepted: false,
start: '1615939850',
end: null,
},
@@ -31,7 +31,7 @@ export const useMarketplaceActions = (): MarketplaceActionValues => {
if (valueLoading !== 'hasValue') return;
setListings((curListings) => [...curListings, listing]);
},
[setListings, valueLoading, contents],
[setListings, valueLoading],
);
return { deleteListing, addListing };
@@ -12,12 +12,13 @@ import NewMessageGroupButton from './form/NewMessageGroupButton';
import { useNuiRequest } from 'fivem-nui-react-lib';
import { MessagesThemeProvider } from '../providers/MessagesThemeProvider';
import { MessageEvents } from '../../../../../typings/messages';
import { LoadingSpinner } from '../../../ui/components/LoadingSpinner';
export const MessagesApp = () => {
const Nui = useNuiRequest();
const messages = useApp('MESSAGES');
const history = useHistory();
useEffect(() => {
Nui.send(MessageEvents.FETCH_MESSAGE_GROUPS);
}, [Nui]);
@@ -27,21 +28,23 @@ export const MessagesApp = () => {
<AppWrapper id="messages-app">
<AppTitle app={messages} />
<AppContent>
<Switch>
<Route path="/messages/conversations/:groupId">
<div>
<MessageModal />
</div>
</Route>
<Route exact path="/messages">
<MessagesList />
</Route>
</Switch>
<Switch>
<Route exact path={['/messages/new/:phoneNumber', '/messages/new']}>
<MessageGroupModal />
</Route>
</Switch>
<React.Suspense fallback={<LoadingSpinner />}>
<Switch>
<Route path="/messages/conversations/:groupId">
<div>
<MessageModal />
</div>
</Route>
<Route exact path="/messages">
<MessagesList />
</Route>
</Switch>
<Switch>
<Route exact path={['/messages/new/:phoneNumber', '/messages/new']}>
<MessageGroupModal />
</Route>
</Switch>
</React.Suspense>
</AppContent>
<Route exact path="/messages">
<NewMessageGroupButton onClick={() => history.push('/messages/new')} />
@@ -22,7 +22,7 @@ import { useHistory, useLocation, useParams } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
import Modal from '../../../../ui/components/Modal';
import { useContactActions } from '../../../contacts/hooks/useContactActions';
import { useSimcard } from '../../../../os/simcard/hooks/useMyPhoneNumber';
import { useMyPhoneNumber } from '../../../../os/simcard/hooks/useMyPhoneNumber';
import { MessageEvents } from '../../../../../../typings/messages';
const LARGE_HEADER_CHARS = 30;
@@ -51,7 +51,7 @@ export const MessageModal = () => {
const Nui = useNuiRequest();
const classes = useStyles();
const history = useHistory();
const { number: myNumber } = useSimcard();
const myNumber = useMyPhoneNumber();
const { pathname } = useLocation();
const { t } = useTranslation();
const { groupId } = useParams<{ groupId: string }>();
-1
View File
@@ -4,7 +4,6 @@ import { useNotesValue } from '../hooks/state';
import { useSetSelectedNote } from '../hooks/state';
import { NoteItem } from '../../../../../typings/notes';
import { makeStyles, Theme } from '@material-ui/core/styles';
import { Notes } from '@material-ui/icons';
const useStyles = makeStyles((theme: Theme) => ({
noNotes: {
@@ -5,7 +5,7 @@ import { AppContent } from '../../../ui/components/AppContent';
import { useContextMenu, MapSettingItem, SettingOption } from '../../../ui/hooks/useContextMenu';
import { usePhoneConfig } from '../../../config/hooks/usePhoneConfig';
import { List } from '../../../ui/components/List';
import { useSimcard } from '../../../os/simcard/hooks/useMyPhoneNumber';
import { useMyPhoneNumber } from '../../../os/simcard/hooks/useMyPhoneNumber';
import { IconSetObject, useApp } from '../../../os/apps/hooks/useApps';
import {
SettingItem,
@@ -59,7 +59,7 @@ const useStyles = makeStyles({
export const SettingsApp = () => {
const settingsApp = useApp('SETTINGS');
const [config] = usePhoneConfig();
const simcard = useSimcard();
const myNumber = useMyPhoneNumber();
const [settings, setSettings] = useSettings();
const { t } = useTranslation();
const { customWallpaperModal, setCustomWallpaperModal } = useCustomWallpaperModal();
@@ -142,7 +142,7 @@ export const SettingsApp = () => {
};
const handleCopyPhoneNumber = () => {
setClipboard(simcard.number);
setClipboard(myNumber);
addAlert({
message: t('GENERIC_WRITE_TO_CLIPBOARD_MESSAGE', {
content: 'number',
@@ -162,7 +162,7 @@ export const SettingsApp = () => {
<List disablePadding subheader={<SubHeaderComp text={t('SETTINGS.CATEGORY.PHONE')} />}>
<SettingItemIconAction
label={t('APPS_SETTINGS_PHONE_NUMBER')}
labelSecondary={simcard.number}
labelSecondary={myNumber}
actionLabel={t('GENERIC_WRITE_TO_CLIPBOARD_TOOLTIP', {
content: 'number',
})}
+1 -1
View File
@@ -4,7 +4,7 @@ import { createLazyAppIcon } from '../utils/createLazyAppIcon';
import { APPS, IApp } from '../config/apps';
import { SvgIconComponent } from '@material-ui/icons';
import { useTheme } from '@material-ui/core';
import { useSettings, useSettingsValue } from '../../../apps/settings/hooks/useSettings';
import { useSettingsValue } from '../../../apps/settings/hooks/useSettings';
export interface IconSetObject {
custom: boolean;