mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 14:38:45 +00:00
refactor(contacts): Refactor contacts to efficient data fetching
This commit is contained in:
1 parent
54d456cc8a
commit
d036243d64
29 files changed
+417
-352
No files matched your search
@@ -10,7 +10,6 @@ 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 { useContactsService } from './apps/contacts/hooks/useContactsService';
|
||||
import { useTwitterService } from './apps/twitter/hooks/useTwitterService';
|
||||
import { useMatchService } from './apps/match/hooks/useMatchService';
|
||||
import { useMarketplaceService } from './apps/marketplace/hooks/useMarketplaceService';
|
||||
@@ -71,7 +70,6 @@ function Phone() {
|
||||
useKeyboardService();
|
||||
usePhoneService();
|
||||
useSimcardService();
|
||||
useContactsService();
|
||||
useTwitterService();
|
||||
useMatchService();
|
||||
useMarketplaceService();
|
||||
|
||||
@@ -5,11 +5,11 @@ import { AppContent } from '../../../ui/components/AppContent';
|
||||
import { useApp } from '../../../os/apps/hooks/useApps';
|
||||
import InjectDebugData from '../../../os/debug/InjectDebugData';
|
||||
import { Route } from 'react-router-dom';
|
||||
|
||||
import ContactsInfoPage from './views/ContactInfo';
|
||||
import { ContactPage } from './views/ContactsPage';
|
||||
import { ContactsThemeProvider } from '../providers/ContactsThemeProvider';
|
||||
import { ContactEvents } from '../../../../../typings/contact';
|
||||
import { LoadingSpinner } from '../../../ui/components/LoadingSpinner';
|
||||
|
||||
export const ContactsApp = () => {
|
||||
const contacts = useApp('CONTACTS');
|
||||
@@ -19,41 +19,12 @@ export const ContactsApp = () => {
|
||||
<AppWrapper id="contact-app">
|
||||
<AppTitle app={contacts} />
|
||||
<AppContent>
|
||||
<Route path="/contacts/" exact component={ContactPage} />
|
||||
<Route path="/contacts/:id" exact component={ContactsInfoPage} />
|
||||
<React.Suspense fallback={<LoadingSpinner />}>
|
||||
<Route path="/contacts/" exact component={ContactPage} />
|
||||
<Route path="/contacts/:id" exact component={ContactsInfoPage} />
|
||||
</React.Suspense>
|
||||
</AppContent>
|
||||
</AppWrapper>
|
||||
</ContactsThemeProvider>
|
||||
);
|
||||
};
|
||||
|
||||
InjectDebugData([
|
||||
{
|
||||
app: 'CONTACTS',
|
||||
method: ContactEvents.SEND_CONTACTS,
|
||||
data: [
|
||||
{
|
||||
id: 1,
|
||||
display: 'Ruqen',
|
||||
number: '555-15196',
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
display: 'Taso',
|
||||
number: '215-8139',
|
||||
avatar: 'http://i.tasoagc.dev/i9Ig',
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
display: 'Chip',
|
||||
number: '603-275-8373',
|
||||
avatar: 'http://i.tasoagc.dev/2QYV',
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
display: 'Kidz',
|
||||
number: '444-4444',
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
||||
@@ -1,24 +1,21 @@
|
||||
import React from 'react';
|
||||
import ListItemText from '@material-ui/core/ListItemText';
|
||||
import { Button, ListItemAvatar, Avatar as MuiAvatar, List, ListItem } from '@material-ui/core';
|
||||
import { useFilteredContacts } from '../../hooks/useFilteredContacts';
|
||||
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 { 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';
|
||||
|
||||
export const ContactList = () => {
|
||||
const { filteredContacts } = useFilteredContacts();
|
||||
const filteredContacts = useFilteredContacts();
|
||||
const history = useHistory();
|
||||
const Nui = useNuiRequest();
|
||||
|
||||
const { contacts } = useContacts();
|
||||
|
||||
const openContactInfo = (contactId: number) => {
|
||||
history.push(`/contacts/${contactId}`);
|
||||
};
|
||||
@@ -43,38 +40,31 @@ export const ContactList = () => {
|
||||
history.push(`/messages/new/${phoneNumber}`);
|
||||
};
|
||||
|
||||
const filteredRegEx = new RegExp(filteredContacts, 'gi');
|
||||
|
||||
return (
|
||||
<>
|
||||
<SearchContacts />
|
||||
<List>
|
||||
{contacts
|
||||
.filter(
|
||||
(contact) =>
|
||||
contact.display.match(filteredRegEx) || contact.number.match(filteredRegEx),
|
||||
)
|
||||
.map((contact) => (
|
||||
<ListItem key={contact.id} divider>
|
||||
<ListItemAvatar>
|
||||
{contact.avatar ? (
|
||||
<MuiAvatar src={contact.avatar} />
|
||||
) : (
|
||||
<MuiAvatar>{contact.display.slice(0, 1).toUpperCase()}</MuiAvatar>
|
||||
)}
|
||||
</ListItemAvatar>
|
||||
<ListItemText primary={contact.display} secondary={contact.number} />
|
||||
<Button onClick={() => startCall(contact.number)}>
|
||||
<PhoneIcon />
|
||||
</Button>
|
||||
<Button onClick={() => handleMessage(contact.number)}>
|
||||
<ChatIcon />
|
||||
</Button>
|
||||
<Button style={{ margin: -15 }} onClick={() => openContactInfo(contact.id)}>
|
||||
<MoreVertIcon />
|
||||
</Button>
|
||||
</ListItem>
|
||||
))}
|
||||
{filteredContacts.map((contact) => (
|
||||
<ListItem key={contact.id} divider>
|
||||
<ListItemAvatar>
|
||||
{contact.avatar ? (
|
||||
<MuiAvatar src={contact.avatar} />
|
||||
) : (
|
||||
<MuiAvatar>{contact.display.slice(0, 1).toUpperCase()}</MuiAvatar>
|
||||
)}
|
||||
</ListItemAvatar>
|
||||
<ListItemText primary={contact.display} secondary={contact.number} />
|
||||
<Button onClick={() => startCall(contact.number)}>
|
||||
<PhoneIcon />
|
||||
</Button>
|
||||
<Button onClick={() => handleMessage(contact.number)}>
|
||||
<ChatIcon />
|
||||
</Button>
|
||||
<Button style={{ margin: -15 }} onClick={() => openContactInfo(contact.id)}>
|
||||
<MoreVertIcon />
|
||||
</Button>
|
||||
</ListItem>
|
||||
))}
|
||||
</List>
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -1,21 +1,29 @@
|
||||
import React from 'react';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { Box } from '@material-ui/core';
|
||||
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { useFilteredContacts } from '../../hooks/useFilteredContacts';
|
||||
import { SearchField } from '../../../../ui/components/SearchField';
|
||||
import { useDebounce } from '../../../../os/phone/hooks/useDebounce';
|
||||
import { useSetContactFilterInput } from '../../hooks/state';
|
||||
|
||||
export const SearchContacts = () => {
|
||||
const { setFilteredContacts, filteredContacts } = useFilteredContacts();
|
||||
const { t } = useTranslation();
|
||||
const setFilterVal = useSetContactFilterInput();
|
||||
const [inputVal, setInputVal] = useState('');
|
||||
|
||||
const debouncedVal = useDebounce<string>(inputVal, 500);
|
||||
|
||||
useEffect(() => {
|
||||
setFilterVal(debouncedVal);
|
||||
}, [debouncedVal, setFilterVal]);
|
||||
|
||||
return (
|
||||
<Box>
|
||||
<SearchField
|
||||
onChange={(e) => setFilteredContacts(e.target.value)}
|
||||
onChange={(e) => setInputVal(e.target.value)}
|
||||
placeholder={t('APPS_CONTACT_PLACEHOLDER_SEARCH_CONTACTS')}
|
||||
value={filteredContacts}
|
||||
value={inputVal}
|
||||
/>
|
||||
</Box>
|
||||
);
|
||||
|
||||
@@ -3,13 +3,15 @@ import { Avatar as MuiAvatar, Box, Button, Paper } from '@material-ui/core';
|
||||
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 { useNuiRequest } from 'fivem-nui-react-lib';
|
||||
import { useContactActions } from '../../hooks/useContactActions';
|
||||
import ArrowBackIcon from '@material-ui/icons/ArrowBack';
|
||||
import LogDebugEvent from '../../../../os/debug/LogDebugEvents';
|
||||
import { useQueryParams } from '../../../../common/hooks/useQueryParams';
|
||||
import { ContactEvents } from '../../../../../../typings/contact';
|
||||
import { Contact, ContactEvents } from '../../../../../../typings/contact';
|
||||
import { TextField } from '../../../../ui/components/Input';
|
||||
import { fetchNui } from '../../../../utils/fetchNui';
|
||||
import { ServerPromiseResp } from '../../../../../../typings/common';
|
||||
import { useSnackbar } from '../../../../ui/hooks/useSnackbar';
|
||||
|
||||
interface ContactInfoRouteParams {
|
||||
mode: string;
|
||||
@@ -49,11 +51,12 @@ const useStyles = makeStyles({
|
||||
});
|
||||
|
||||
const ContactsInfoPage = () => {
|
||||
const Nui = useNuiRequest();
|
||||
const classes = useStyles();
|
||||
const history = useHistory();
|
||||
|
||||
const { getContact } = useContacts();
|
||||
const { getContact, addContact, updateContact, deleteContact } = useContactActions();
|
||||
|
||||
const { addAlert } = useSnackbar();
|
||||
|
||||
const { id } = useParams<ContactInfoRouteParams>();
|
||||
const { addNumber, referal } = useQueryParams<ContactInfoRouteQuery>({
|
||||
@@ -81,12 +84,27 @@ const ContactsInfoPage = () => {
|
||||
data: contact,
|
||||
level: 2,
|
||||
});
|
||||
Nui.send(ContactEvents.ADD_CONTACT, {
|
||||
fetchNui<ServerPromiseResp<Contact>>(ContactEvents.ADD_CONTACT, {
|
||||
display: name,
|
||||
number,
|
||||
avatar,
|
||||
}).then((serverResp) => {
|
||||
if (serverResp.status !== 'ok') {
|
||||
return addAlert({
|
||||
message: t('APPS_CONTACT_ADD_FAILED'),
|
||||
type: 'error',
|
||||
});
|
||||
}
|
||||
|
||||
// Sanity checks maybe?
|
||||
|
||||
addContact(serverResp.data);
|
||||
addAlert({
|
||||
message: t('APPS_CONTACT_ADD_SUCCESS'),
|
||||
type: 'error',
|
||||
});
|
||||
history.replace(referal);
|
||||
});
|
||||
history.replace(referal);
|
||||
};
|
||||
|
||||
const handleContactSave = () => {
|
||||
@@ -95,13 +113,33 @@ const ContactsInfoPage = () => {
|
||||
data: contact,
|
||||
level: 2,
|
||||
});
|
||||
Nui.send(ContactEvents.UPDATE_CONTACT, {
|
||||
fetchNui<ServerPromiseResp>(ContactEvents.UPDATE_CONTACT, {
|
||||
id: contact.id,
|
||||
display: name,
|
||||
number,
|
||||
avatar,
|
||||
}).then((resp) => {
|
||||
if (resp.status !== 'ok') {
|
||||
return addAlert({
|
||||
message: t('APPS_CONTACT_UPDATE_FAILED'),
|
||||
type: 'error',
|
||||
});
|
||||
}
|
||||
|
||||
updateContact({
|
||||
id: contact.id,
|
||||
display: name,
|
||||
number,
|
||||
avatar,
|
||||
});
|
||||
|
||||
addAlert({
|
||||
message: t('APPS_CONTACT_UPDATE_SUCCESS'),
|
||||
type: 'success',
|
||||
});
|
||||
|
||||
history.goBack();
|
||||
});
|
||||
history.goBack();
|
||||
};
|
||||
|
||||
const handleContactDelete = () => {
|
||||
@@ -110,8 +148,20 @@ const ContactsInfoPage = () => {
|
||||
data: contact,
|
||||
level: 2,
|
||||
});
|
||||
Nui.send(ContactEvents.DELETE_CONTACT, contact.id);
|
||||
history.goBack();
|
||||
fetchNui<ServerPromiseResp>(ContactEvents.DELETE_CONTACT, { id: contact.id }).then((resp) => {
|
||||
if (resp.status !== 'ok') {
|
||||
return addAlert({
|
||||
message: t('APPS_CONTACT_DELETE_FAILED'),
|
||||
type: 'error',
|
||||
});
|
||||
}
|
||||
history.goBack();
|
||||
deleteContact(contact.id);
|
||||
addAlert({
|
||||
message: t('APPS_CONTACT_DELETE_SUCCESS'),
|
||||
type: 'error',
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
@@ -1,17 +1,57 @@
|
||||
import { atom } from 'recoil';
|
||||
import { Contact } from '../../../../../typings/contact';
|
||||
import { atom, selector, useRecoilState, useRecoilValue, useSetRecoilState } from 'recoil';
|
||||
import { Contact, ContactEvents } from '../../../../../typings/contact';
|
||||
import { fetchNui } from '../../../utils/fetchNui';
|
||||
import { ServerPromiseResp } from '../../../../../typings/common';
|
||||
import { isEnvBrowser } from '../../../utils/misc';
|
||||
import LogDebugEvent from '../../../os/debug/LogDebugEvents';
|
||||
import { BrowserContactsState } from '../utils/constants';
|
||||
|
||||
export const contactsState = {
|
||||
contacts: atom<Contact[]>({
|
||||
key: 'contactsList',
|
||||
default: [],
|
||||
default: selector({
|
||||
key: 'contactsListDefault',
|
||||
get: async () => {
|
||||
try {
|
||||
const resp = await fetchNui<ServerPromiseResp<Contact[]>>(ContactEvents.GET_CONTACTS);
|
||||
LogDebugEvent({ action: 'ContactsFetched', data: resp.data });
|
||||
return resp.data;
|
||||
} catch (e) {
|
||||
if (isEnvBrowser()) {
|
||||
return BrowserContactsState;
|
||||
}
|
||||
console.error(e);
|
||||
return [];
|
||||
}
|
||||
},
|
||||
}),
|
||||
}),
|
||||
showModal: atom<boolean>({
|
||||
key: 'showModal',
|
||||
default: false,
|
||||
}),
|
||||
filterContacts: atom<string>({
|
||||
key: 'filterContacts',
|
||||
filterInput: atom<string>({
|
||||
key: 'filterInput',
|
||||
default: '',
|
||||
}),
|
||||
filteredContacts: selector({
|
||||
key: 'filteredContacts',
|
||||
get: ({ get }) => {
|
||||
const filterInputVal: string = get(contactsState.filterInput);
|
||||
const contacts: Contact[] = get(contactsState.contacts);
|
||||
|
||||
if (!filterInputVal) return contacts;
|
||||
|
||||
const regExp = new RegExp(filterInputVal, 'gi');
|
||||
|
||||
return contacts.filter(
|
||||
(contact) => contact.display.match(regExp) || contact.number.match(regExp),
|
||||
);
|
||||
},
|
||||
}),
|
||||
};
|
||||
|
||||
export const useSetContacts = () => useSetRecoilState(contactsState.contacts);
|
||||
export const useContacts = () => useRecoilState(contactsState.contacts);
|
||||
export const useContactsValue = () => useRecoilValue(contactsState.contacts);
|
||||
|
||||
export const useFilteredContacts = () => useRecoilValue(contactsState.filteredContacts);
|
||||
|
||||
export const useContactFilterInput = () => useRecoilState(contactsState.filterInput);
|
||||
export const useSetContactFilterInput = () => useSetRecoilState(contactsState.filterInput);
|
||||
@@ -0,0 +1,91 @@
|
||||
import { useContacts } from './state';
|
||||
|
||||
import { Contact } from '../../../../../typings/contact';
|
||||
import { useCallback } from 'react';
|
||||
|
||||
interface UseContactsValue {
|
||||
getDisplayByNumber: (number: string) => string;
|
||||
getContactByNumber: (number: string) => Contact | null;
|
||||
getContact: (id: number) => Contact | null;
|
||||
getPictureByNumber: (number: string) => string | null;
|
||||
deleteContact: (id: number) => void;
|
||||
addContact: (contact: Contact) => void;
|
||||
updateContact: (contact: Contact) => void;
|
||||
}
|
||||
|
||||
export const useContactActions = (): UseContactsValue => {
|
||||
const [contacts, setContacts] = useContacts();
|
||||
|
||||
const getDisplayByNumber = useCallback(
|
||||
(number: string) => {
|
||||
const found = contacts.find((contact) => contact.number === number);
|
||||
return found ? found.display : number;
|
||||
},
|
||||
[contacts],
|
||||
);
|
||||
|
||||
const getPictureByNumber = useCallback(
|
||||
(number: string) => {
|
||||
const found = contacts.find((contact) => contact.number === number);
|
||||
return found ? found.avatar : null;
|
||||
},
|
||||
[contacts],
|
||||
);
|
||||
|
||||
const getContactByNumber = useCallback(
|
||||
(number: string): Contact | null => {
|
||||
for (const contact of contacts) {
|
||||
if (contact.number === number) return contact;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
[contacts],
|
||||
);
|
||||
|
||||
const getContact = useCallback(
|
||||
(id: number): Contact | null => {
|
||||
for (const contact of contacts) {
|
||||
if (contact.id === id) return contact;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
[contacts],
|
||||
);
|
||||
|
||||
const deleteContact = useCallback(
|
||||
(id: number): void => {
|
||||
const contactIndex = contacts.findIndex((contact) => contact.id === id);
|
||||
const newContacts = [...contacts].slice(contactIndex);
|
||||
setContacts(newContacts);
|
||||
},
|
||||
[contacts, setContacts],
|
||||
);
|
||||
|
||||
const addContact = useCallback(
|
||||
(contact: Contact) => {
|
||||
const newContactState = [...contacts, contact];
|
||||
setContacts(newContactState);
|
||||
},
|
||||
[contacts, setContacts],
|
||||
);
|
||||
|
||||
const updateContact = useCallback(
|
||||
(updatedContact: Contact) => {
|
||||
const targetContactIndex = contacts.findIndex((contact) => contact.id === updatedContact.id);
|
||||
const newContactsArray = [...contacts];
|
||||
newContactsArray[targetContactIndex] = updatedContact;
|
||||
setContacts(newContactsArray);
|
||||
},
|
||||
[contacts, setContacts],
|
||||
);
|
||||
|
||||
return {
|
||||
getDisplayByNumber,
|
||||
getContact,
|
||||
getContactByNumber,
|
||||
getPictureByNumber,
|
||||
deleteContact,
|
||||
updateContact,
|
||||
addContact,
|
||||
};
|
||||
};
|
||||
@@ -1,55 +0,0 @@
|
||||
import { useRecoilValue } from 'recoil';
|
||||
import { contactsState } from './state';
|
||||
|
||||
import { Contact } from '../../../../../typings/contact';
|
||||
import { useCallback } from 'react';
|
||||
|
||||
interface IUseContacts {
|
||||
contacts: Contact[];
|
||||
getDisplayByNumber: (number: string) => string;
|
||||
getContactByNumber: (number: string) => Contact | null;
|
||||
getContact: (id: number) => Contact | null;
|
||||
getPictureByNumber: (number: string) => string | null;
|
||||
}
|
||||
|
||||
export const useContacts = (): IUseContacts => {
|
||||
const contacts = useRecoilValue<Contact[]>(contactsState.contacts);
|
||||
|
||||
const getDisplayByNumber = useCallback(
|
||||
(number: string) => {
|
||||
const found = contacts.find((contact) => contact.number === number);
|
||||
return found ? found.display : number;
|
||||
},
|
||||
[contacts],
|
||||
);
|
||||
|
||||
const getPictureByNumber = useCallback(
|
||||
(number: string) => {
|
||||
const found = contacts.find((contact) => contact.number === number);
|
||||
return found ? found.avatar : null;
|
||||
},
|
||||
[contacts],
|
||||
);
|
||||
|
||||
const getContactByNumber = useCallback(
|
||||
(number: string): Contact | null => {
|
||||
for (const contact of contacts) {
|
||||
if (contact.number === number) return contact;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
[contacts],
|
||||
);
|
||||
|
||||
const getContact = useCallback(
|
||||
(id: number): Contact | null => {
|
||||
for (const contact of contacts) {
|
||||
if (contact.id === id) return contact;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
[contacts],
|
||||
);
|
||||
|
||||
return { contacts, getDisplayByNumber, getContact, getContactByNumber, getPictureByNumber };
|
||||
};
|
||||
@@ -1,24 +0,0 @@
|
||||
import { useNuiEvent } from 'fivem-nui-react-lib';
|
||||
import { useSetRecoilState } from 'recoil';
|
||||
import { contactsState } from './state';
|
||||
import { useContacts } from './useContacts';
|
||||
import { IAlert, useSnackbar } from '../../../ui/hooks/useSnackbar';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { ContactEvents } from '../../../../../typings/contact';
|
||||
|
||||
export const useContactsService = () => {
|
||||
const setContacts = useSetRecoilState(contactsState.contacts);
|
||||
const { addAlert } = useSnackbar();
|
||||
const { t } = useTranslation();
|
||||
|
||||
const handleAddAlert = ({ message, type }: IAlert) => {
|
||||
addAlert({
|
||||
message: t(`APPS_${message}`),
|
||||
type,
|
||||
});
|
||||
};
|
||||
|
||||
useNuiEvent('CONTACTS', ContactEvents.SEND_CONTACTS, setContacts);
|
||||
useNuiEvent('CONTACTS', ContactEvents.SEND_ALERT, handleAddAlert);
|
||||
return useContacts();
|
||||
};
|
||||
@@ -1,12 +0,0 @@
|
||||
import { useRecoilState } from 'recoil';
|
||||
import { contactsState } from './state';
|
||||
|
||||
interface FilterdContactsProps {
|
||||
filteredContacts: string;
|
||||
setFilteredContacts: (searchTerm: string) => void;
|
||||
}
|
||||
|
||||
export const useFilteredContacts = (): FilterdContactsProps => {
|
||||
const [filteredContacts, setFilteredContacts] = useRecoilState(contactsState.filterContacts);
|
||||
return { filteredContacts, setFilteredContacts };
|
||||
};
|
||||
@@ -1,12 +0,0 @@
|
||||
import { useRecoilState } from 'recoil';
|
||||
import { contactsState } from './state';
|
||||
|
||||
interface ModalProps {
|
||||
showModal: boolean;
|
||||
setShowModal: (show: boolean) => void;
|
||||
}
|
||||
|
||||
export const useModal = (): ModalProps => {
|
||||
const [showModal, setShowModal] = useRecoilState(contactsState.showModal);
|
||||
return { showModal, setShowModal };
|
||||
};
|
||||
@@ -0,0 +1,24 @@
|
||||
export const BrowserContactsState = [
|
||||
{
|
||||
id: 1,
|
||||
display: 'Ruqen',
|
||||
number: '555-15196',
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
display: 'Taso',
|
||||
number: '215-8139',
|
||||
avatar: 'http://i.tasoagc.dev/i9Ig',
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
display: 'Chip',
|
||||
number: '603-275-8373',
|
||||
avatar: 'http://i.tasoagc.dev/2QYV',
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
display: 'Kidz',
|
||||
number: '444-4444',
|
||||
},
|
||||
];
|
||||
@@ -12,6 +12,13 @@ import InjectDebugData from '../../../os/debug/InjectDebugData';
|
||||
import { ContactList } from '../../contacts/components/List/ContactList';
|
||||
import { DialerThemeProvider } from '../providers/DialerThemeProvider';
|
||||
import { CallEvents } from '../../../../../typings/call';
|
||||
import { Box, CircularProgress } from '@material-ui/core';
|
||||
|
||||
const LoadingSpinner: React.FC = () => (
|
||||
<Box>
|
||||
<CircularProgress />
|
||||
</Box>
|
||||
);
|
||||
|
||||
export const DialerApp = () => {
|
||||
const history = useDialHistory();
|
||||
@@ -27,7 +34,9 @@ export const DialerApp = () => {
|
||||
<DialPage />
|
||||
</Route>
|
||||
<Route exact path="/phone">
|
||||
<DialerHistory calls={history} />
|
||||
<React.Suspense fallback={<LoadingSpinner />}>
|
||||
<DialerHistory calls={history} />
|
||||
</React.Suspense>
|
||||
</Route>
|
||||
<Route path="/phone/contacts" component={ContactList} />
|
||||
</Switch>
|
||||
|
||||
@@ -7,7 +7,7 @@ import { List } from '../../../../ui/components/List';
|
||||
import { ListItem } from '../../../../ui/components/ListItem';
|
||||
import { useNuiRequest } from 'fivem-nui-react-lib';
|
||||
import { useSimcard } from '../../../../os/simcard/hooks/useSimcard';
|
||||
import { useContacts } from '../../../contacts/hooks/useContacts';
|
||||
import { useContactActions } from '../../../contacts/hooks/useContactActions';
|
||||
import { CallEvents, CallHistoryItem } from '../../../../../../typings/call';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Box, IconButton, ListItemIcon, ListItemText } from '@material-ui/core';
|
||||
@@ -27,7 +27,7 @@ const useStyles = makeStyles((theme: Theme) => ({
|
||||
export const DialerHistory = ({ calls }) => {
|
||||
const Nui = useNuiRequest();
|
||||
const { number: myNumber } = useSimcard();
|
||||
const { getDisplayByNumber } = useContacts();
|
||||
const { getDisplayByNumber } = useContactActions();
|
||||
|
||||
const classes = useStyles();
|
||||
|
||||
|
||||
@@ -4,12 +4,13 @@ import { Box, Button } from '@material-ui/core';
|
||||
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';
|
||||
import { useContactActions } from '../../../contacts/hooks/useContactActions';
|
||||
import { Contact } from '../../../../../../typings/contact';
|
||||
import { MessageEvents } from '../../../../../../typings/messages';
|
||||
import { PHONE_NUMBER_REGEX } from '../../../../../../typings/phone';
|
||||
import { useSnackbar } from '../../../../ui/hooks/useSnackbar';
|
||||
import { TextField } from '../../../../ui/components/Input';
|
||||
import { useContactsValue } from '../../../contacts/hooks/state';
|
||||
|
||||
const NewMessageGroupForm = ({ phoneNumber }: { phoneNumber?: string }) => {
|
||||
const Nui = useNuiRequest();
|
||||
@@ -18,7 +19,8 @@ const NewMessageGroupForm = ({ phoneNumber }: { phoneNumber?: string }) => {
|
||||
const { addAlert } = useSnackbar();
|
||||
const [participants, setParticipants] = useState([]);
|
||||
const [label, setLabel] = useState('');
|
||||
const { getContactByNumber, contacts } = useContacts();
|
||||
const { getContactByNumber } = useContactActions();
|
||||
const contacts = useContactsValue();
|
||||
|
||||
useEffect(() => {
|
||||
if (phoneNumber) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import ArrowBackIcon from '@material-ui/icons/ArrowBack';
|
||||
import useStyles from './modal.styles';
|
||||
import NewMessageGroupForm from '../form/NewMessageGroupForm';
|
||||
import { useHistory, useParams } from 'react-router-dom';
|
||||
import { LoadingSpinner } from '../../../../ui/components/LoadingSpinner';
|
||||
|
||||
const MessageGroupModal = () => {
|
||||
const classes = useStyles();
|
||||
@@ -16,10 +17,12 @@ const MessageGroupModal = () => {
|
||||
return (
|
||||
<Slide direction="left" in>
|
||||
<Paper className={classes.modalRoot}>
|
||||
<Button onClick={handleClose}>
|
||||
<ArrowBackIcon fontSize="large" />
|
||||
</Button>
|
||||
<NewMessageGroupForm phoneNumber={params.phoneNumber} />
|
||||
<React.Suspense fallback={<LoadingSpinner />}>
|
||||
<Button onClick={handleClose}>
|
||||
<ArrowBackIcon fontSize="large" />
|
||||
</Button>
|
||||
<NewMessageGroupForm phoneNumber={params.phoneNumber} />
|
||||
</React.Suspense>
|
||||
</Paper>
|
||||
</Slide>
|
||||
);
|
||||
|
||||
@@ -21,7 +21,7 @@ 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';
|
||||
import { useContacts } from '../../../contacts/hooks/useContacts';
|
||||
import { useContactActions } from '../../../contacts/hooks/useContactActions';
|
||||
import { useSimcard } from '../../../../os/simcard/hooks/useSimcard';
|
||||
import { MessageEvents } from '../../../../../../typings/messages';
|
||||
|
||||
@@ -56,7 +56,7 @@ export const MessageModal = () => {
|
||||
const { t } = useTranslation();
|
||||
const { groupId } = useParams<{ groupId: string }>();
|
||||
const { messages, setMessages, activeMessageGroup, setActiveMessageGroup } = useMessages();
|
||||
const { getContactByNumber, getDisplayByNumber } = useContacts();
|
||||
const { getContactByNumber, getDisplayByNumber } = useContactActions();
|
||||
|
||||
const [isLoaded, setLoaded] = useState(false);
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import React from 'react';
|
||||
import { Avatar, Box, Typography } from '@material-ui/core';
|
||||
import { makeStyles } from '@material-ui/core/styles';
|
||||
import { useContacts } from '../../../apps/contacts/hooks/useContacts';
|
||||
import { useContactActions } from '../../../apps/contacts/hooks/useContactActions';
|
||||
import { useCall } from '../hooks/useCall';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
@@ -17,7 +17,7 @@ const CallContactContainer = () => {
|
||||
const { call } = useCall();
|
||||
const classes = useStyles();
|
||||
|
||||
const { getDisplayByNumber, getPictureByNumber } = useContacts();
|
||||
const { getDisplayByNumber, getPictureByNumber } = useContactActions();
|
||||
|
||||
const getDisplayOrNumber = () =>
|
||||
call.isTransmitter ? getDisplayByNumber(call?.receiver) : getDisplayByNumber(call?.transmitter);
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
export const useDebounce = <T = any>(value: T, delay = 100) => {
|
||||
const [debouncedValue, setDebouncedValue] = useState(value);
|
||||
|
||||
useEffect(() => {
|
||||
const handler = setTimeout(() => {
|
||||
setDebouncedValue(value);
|
||||
}, delay);
|
||||
return () => {
|
||||
clearTimeout(handler);
|
||||
};
|
||||
}, [value, delay]);
|
||||
|
||||
return debouncedValue;
|
||||
};
|
||||
@@ -0,0 +1,8 @@
|
||||
import React from 'react';
|
||||
import { Box, CircularProgress } from '@material-ui/core';
|
||||
|
||||
export const LoadingSpinner: React.FC = () => (
|
||||
<Box display="flex" justifyContent="center" alignItems="center" height="100%">
|
||||
<CircularProgress />
|
||||
</Box>
|
||||
);
|
||||
@@ -0,0 +1,3 @@
|
||||
// Quickly determine whether we are in browser
|
||||
export const isEnvBrowser = (): boolean =>
|
||||
process.env.NODE_ENV === 'development' && !(window as any).invokeNative;
|
||||
Reference in new issue
Block a user