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

+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);
};