48 changed files with 418 additions and 235 deletions

No files matched your search

+8 -12
View File
@@ -5,6 +5,7 @@ import { Route } from 'react-router-dom';
import { CallModal } from './os/call/components/CallModal';
import { HomeApp } from './apps/home/components/Home';
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';
@@ -32,8 +33,7 @@ import WindowSnackbar from './ui/components/WindowSnackbar';
import { usePhone } from './os/phone/hooks/usePhone';
import { useTranslation } from 'react-i18next';
import { useSnackbar } from './ui/hooks/useSnackbar';
import { PhoneEvents } from '../../typings/phone';
import dayjs from 'dayjs';
import { isDefaultWallpaper } from './apps/settings/utils/isDefaultWallpaper';
function Phone() {
const { t, i18n } = useTranslation();
@@ -63,6 +63,7 @@ function Phone() {
}, []);
useNuiService();
useKeyboardService();
usePhoneService();
useSimcardService();
useContactsService();
@@ -104,8 +105,8 @@ function Phone() {
id="phone"
className="PhoneScreen"
style={{
backgroundImage: settings.customWallpaper
? `url(${settings.customWallpaper})`
backgroundImage: !isDefaultWallpaper(settings.wallpaper.value)
? `url(${settings.wallpaper.value})`
: `url(media/backgrounds/${settings.wallpaper.value})`,
}}
>
@@ -151,20 +152,15 @@ function Phone() {
export default Phone;
InjectDebugData<any>([
InjectDebugData([
{
app: 'PHONE',
method: PhoneEvents.SET_VISIBILITY,
method: 'setVisibility',
data: true,
},
{
app: 'PHONE',
method: PhoneEvents.SET_PHONE_READY,
method: 'setPhoneReady',
data: true,
},
{
app: 'PHONE',
method: PhoneEvents.SET_TIME,
data: dayjs().format('hh:mm'),
},
]);
@@ -7,6 +7,7 @@ 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);
@@ -7,8 +7,9 @@ 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 { IPhoto, PhotoEvents } from '../../../../../../typings/photo';
import { PhotoEvents } from '../../../../../../typings/photo';
export const GalleryModal = () => {
const classes = useStyles();
@@ -18,9 +19,10 @@ export const GalleryModal = () => {
const [shareOpen, setShareOpen] = useState(null);
const meta: IPhoto = useMemo(() => ({ id: parseInt(query.id), image: query.image as string }), [
query,
]);
const meta: ICameraPhoto = useMemo(
() => ({ id: query.id as string, image: query.image as string }),
[query],
);
const _handleClose = () => {
history.push(referal);
@@ -5,11 +5,11 @@ import MessageIcon from '@material-ui/icons/Message';
import { setClipboard } from '../../../../os/phone/hooks/useClipboard';
import useStyles from './modal.styles';
import { ICameraPhoto } from '../../hooks/usePhotos';
import { useHistory } from 'react-router-dom';
import { IPhoto } from '../../../../../../typings/photo';
interface IShareModalProps {
meta: IPhoto;
meta: ICameraPhoto;
referal: string;
onClose(): void;
}
+2 -3
View File
@@ -1,9 +1,8 @@
import { atom } from 'recoil';
import { IPhoto } from '../../../../../typings/photo';
export const photoState = {
photos: atom<IPhoto[]>({
photos: atom({
key: 'galleryPhotos',
default: [],
default: null,
}),
};
+7 -2
View File
@@ -1,6 +1,11 @@
import { useRecoilValue } from 'recoil';
import { photoState } from './state';
export const usePhotos = () => {
return useRecoilValue(photoState.photos);
export interface ICameraPhoto {
id: string;
image: string;
}
export const usePhotos = (): ICameraPhoto[] | null => {
return useRecoilValue<ICameraPhoto[] | null>(photoState.photos);
};
+11 -4
View File
@@ -1,17 +1,24 @@
import { atom } from 'recoil';
import { Contact } from '../../../../../typings/contact';
export const contactsState = {
contacts: atom<Contact[]>({
contacts: atom({
key: 'contactsList',
default: [],
}),
showModal: atom<boolean>({
showModal: atom({
key: 'showModal',
default: false,
}),
filterContacts: atom<string>({
filterContacts: atom({
key: 'filterContacts',
default: '',
}),
showContactsModal: atom({
key: 'showContactModal',
default: false,
}),
contactDetail: atom({
key: 'contactDetail',
default: null,
}),
};
@@ -3,7 +3,7 @@ import { contactsState } from './state';
interface FilterdContactsProps {
filteredContacts: string;
setFilteredContacts: (searchTerm: string) => void;
setFilteredContacts: (contact: any) => void;
}
export const useFilteredContacts = (): FilterdContactsProps => {
@@ -8,7 +8,7 @@ import { ListItem } from '../../../../ui/components/ListItem';
import Nui from '../../../../os/nui-events/utils/Nui';
import { useSimcard } from '../../../../os/simcard/hooks/useSimcard';
import { useContacts } from '../../../contacts/hooks/useContacts';
import { CallEvents, CallHistoryItem } from '../../../../../../typings/call';
import { CallEvents, ICall } from '../../../../../../typings/call';
import { useTranslation } from 'react-i18next';
import { Box, IconButton, ListItemIcon, ListItemText } from '@material-ui/core';
import { useHistory } from 'react-router-dom';
@@ -55,7 +55,7 @@ export const DialerHistory = ({ calls }) => {
return (
<List disablePadding>
{calls.map((call: CallHistoryItem) =>
{calls.map((call: ICall) =>
call.transmitter === myNumber ? (
<ListItem key={call.id} divider>
<ListItemIcon>
+1 -2
View File
@@ -1,8 +1,7 @@
import { atom } from 'recoil';
import { CallHistoryItem } from '../../../../../typings/call';
export const dialState = {
history: atom<CallHistoryItem[]>({
history: atom({
key: 'dialHistory',
default: [],
}),
@@ -1,6 +1,7 @@
import { useRecoilValue } from 'recoil';
import { ICall } from '../../../../../typings/call';
import { dialState } from './state';
export const useDialHistory = () => {
return useRecoilValue(dialState.history);
return useRecoilValue<ICall[]>(dialState.history);
};
@@ -1,5 +1,5 @@
import React, { useState } from 'react';
import { makeStyles, Button, TextField } from '@material-ui/core';
import { makeStyles, Button, TextField, Typography } from '@material-ui/core';
import Nui from '../../../../os/nui-events/utils/Nui';
import { MarketplaceEvents } from '../../../../../../typings/marketplace';
import { useSnackbar } from '../../../../ui/hooks/useSnackbar';
+1 -2
View File
@@ -1,8 +1,7 @@
import { atom } from 'recoil';
import { MarketplaceListing } from '../../../../../typings/marketplace';
export const selloutState = {
listing: atom<MarketplaceListing[]>({
listing: atom({
key: 'listing',
default: [],
}),
@@ -15,6 +15,8 @@ const useStyles = makeStyles({
export function MatchBottomNavigation({ activePage, handleChange }) {
const classes = useStyles();
console.log(activePage);
return (
<BottomNavigation value={activePage} onChange={handleChange} className={classes.root}>
<BottomNavigationAction component={Link} to="/match" icon={<HomeIcon />} />
+5 -6
View File
@@ -1,8 +1,7 @@
import { atom } from 'recoil';
import { FormattedMatch, FormattedProfile } from '../../../../../typings/match';
export const matchState = {
profiles: atom<FormattedProfile[]>({
profiles: atom({
key: 'profiles',
default: null,
}),
@@ -10,19 +9,19 @@ export const matchState = {
key: 'errorLoadingProfiles',
default: false,
}),
matches: atom<FormattedMatch[]>({
matches: atom({
key: 'matches',
default: null,
}),
errorLoadingMatches: atom<boolean>({
errorLoadingMatches: atom({
key: 'errorLoadingMatches',
default: false,
}),
myProfile: atom<FormattedProfile | null>({
myProfile: atom({
key: 'myProfile',
default: null,
}),
noProfileExists: atom<boolean>({
noProfileExists: atom({
key: 'noProfileExists',
default: false,
}),
@@ -1,6 +1,7 @@
import React, { useEffect, useState } from 'react';
import { Box, List } from '@material-ui/core';
import { MessageGroup } from '../../../../../../typings/messages';
import { MessageEvents, MessageGroup } from '../../../../../../typings/messages';
import Nui from '../../../../os/nui-events/utils/Nui';
import useMessages from '../../hooks/useMessages';
import MessageGroupItem from './MessageGroupItem';
import useStyles from './list.styles';
+9 -10
View File
@@ -1,33 +1,32 @@
import { atom } from 'recoil';
import { CreateMessageGroupResult, Message, MessageGroup } from '../../../../../typings/messages';
export const messageState = {
messageGroups: atom<MessageGroup[]>({
messageGroups: atom({
key: 'messageGroups',
default: [],
default: null,
}),
messages: atom<Message[]>({
messages: atom({
key: 'messages',
default: null,
}),
activeMessageGroup: atom<MessageGroup>({
activeMessageGroup: atom({
key: 'activeMessageGroup',
default: null,
}),
showNewMessageGroup: atom<boolean>({
showNewMessageGroup: atom({
key: 'showNewMessageGroup',
default: false,
}),
createMessageGroupResult: atom<CreateMessageGroupResult>({
createMessageGroupResult: atom({
key: 'createMessageGroupResult',
default: null,
}),
imageModal: atom<boolean>({
imageModal: atom({
key: 'useImageModal',
default: false,
}),
unreadMessagesCount: atom<number>({
unreadMessagesCount: atom({
key: 'unreadMessagesCount',
default: 0,
}),
})
};
@@ -1,3 +1,4 @@
import { useCallback } from 'react';
import { useTranslation } from 'react-i18next';
import { matchPath, useHistory } from 'react-router-dom';
import { useApp } from '../../../os/apps/hooks/useApps';
+2 -2
View File
@@ -14,7 +14,7 @@ interface IUseMessages {
activeMessageGroup: MessageGroup | null;
}
export default function useMessages(): IUseMessages {
export default (): IUseMessages => {
const [messages, setMessages] = useRecoilState<Message[] | null>(messageState.messages);
const messageGroups = useRecoilValue<MessageGroup[] | null>(messageState.messageGroups);
const [activeMessageGroup, _setActiveMessageGroup] = useRecoilState<MessageGroup | null>(
@@ -54,4 +54,4 @@ export default function useMessages(): IUseMessages {
activeMessageGroup,
setActiveMessageGroup,
};
}
};
@@ -11,7 +11,6 @@ import {
Typography,
Switch,
} from '@material-ui/core';
import CreateIcon from '@material-ui/icons/Create';
interface ISettingItem {
options?: any;
@@ -107,15 +106,3 @@ export const SettingItemIconAction = ({
</ListItem>
</>
);
export const SettingItemModal = ({ icon, label, secondary, onClick }) => (
<ListItem divider>
<ListItemIcon>{icon}</ListItemIcon>
<ListItemText primary={label} secondary={secondary} />
<ListItemSecondaryAction>
<IconButton onClick={onClick}>
<CreateIcon />
</IconButton>
</ListItemSecondaryAction>
</ListItem>
);
@@ -12,7 +12,6 @@ import {
SettingItemIconAction,
SettingItemSlider,
SettingSwitch,
SettingItemModal,
} from './SettingItem';
import { useTranslation } from 'react-i18next';
import VisibilityOffIcon from '@material-ui/icons/VisibilityOff';
@@ -73,9 +72,9 @@ export const SettingsApp = () => {
};
const wallpapers = config.wallpapers.map(
MapSettingItem(settings.wallpaper, (val: SettingOption) =>
handleSettingChange('wallpaper', val),
),
MapSettingItem(settings.wallpaper, (val: SettingOption) => {
handleSettingChange('wallpaper', val);
}),
);
const frames = config.frames.map(
MapSettingItem(settings.frame, (val: SettingOption) => handleSettingChange('frame', val)),
@@ -128,6 +127,13 @@ export const SettingsApp = () => {
},
];
const customWallpaper: IContextMenuOption = {
selected: false,
onClick: () => setCustomWallpaperModal(true),
key: 'CUSTOM_WALLPAPER',
label: t('APPS_SETTINGS_OPTIONS_CUSTOM_WALLPAPER'),
};
const handleCopyPhoneNumber = () => {
setClipboard(simcard.number);
addAlert({
@@ -209,17 +215,10 @@ export const SettingsApp = () => {
<SettingItem
label={t('APPS_SETTINGS_OPTION_WALLPAPER')}
value={settings.wallpaper.label}
options={wallpapers}
options={[...wallpapers, customWallpaper]}
onClick={openMenu}
icon={<Wallpaper />}
/>
{/* CUSTOM BACKGROUND */}
<SettingItemModal
icon={<Wallpaper />}
label={t('APPS_SETTINGS_OPTIONS_CUSTOM_WALLPAPER')}
secondary={settings.customWallpaper}
onClick={() => setCustomWallpaperModal(true)}
/>
<SettingItem
label={t('APPS_SETTINGS_OPTION_FRAME')}
value={settings.frame.label}
@@ -1,86 +1,52 @@
import React, { useState } from 'react';
import Modal from '../../../ui/components/Modal';
import { useCustomWallpaperModal, useSettings } from '../hooks/useSettings';
import { Box, Button, TextField } from '@material-ui/core';
import { PictureThumbnail } from '../../../ui/components/PictureThumbnail';
import { TextField } from '@material-ui/core';
import { useTranslation } from 'react-i18next';
import { makeStyles } from '@material-ui/core/styles';
import { StatusButton } from '../../../ui/components/StatusButton';
const useStyles = makeStyles({
input: {
marginTop: 10,
marginBottom: 10,
},
inputProps: {
fontSize: 18,
},
});
import DialogForm from '../../../ui/components/DialogForm';
import { useSnackbar } from '../../../ui/hooks/useSnackbar';
export default function WallpaperModal() {
const { customWallpaperModal, setCustomWallpaperModal } = useCustomWallpaperModal();
const [settings, setSettings] = useSettings();
const { t } = useTranslation();
const [value, setValue] = useState(settings.customWallpaper ? settings.customWallpaper : '');
const classes = useStyles();
const [value, setValue] = useState('');
const { addAlert } = useSnackbar();
const isImage = (url) => {
const isImageAndUrl = (url) => {
return /(http(s?):)([/|.|\w|\s|-])*\.(?:jpg|png|jpeg|gif)/g.test(url);
};
const handleCloseModal = () => {
setCustomWallpaperModal(false);
};
const handleSettingChange = (key: string | number, value: unknown) => {
setSettings({ ...settings, [key]: value });
};
const handleNewWallpaper = () => {
handleSettingChange('customWallpaper', value);
};
const handleRemoveWallpaper = () => {
handleSettingChange('customWallpaper', '');
if (isImageAndUrl(value)) {
handleSettingChange('wallpaper', {
label: t('APPS_SETTINGS_OPTIONS_CUSTOM_WALLPAPER'),
value,
});
setCustomWallpaperModal(false);
} else {
addAlert({ message: t('SETTINGS.OPTIONS.CUSTOM_WALLPAPER.DIALOG_ERROR'), type: 'error' });
}
};
return (
<Modal visible={customWallpaperModal} handleClose={handleCloseModal}>
<Box
display="flex"
justifyContent="center"
alignItems="center"
textAlign="center"
flexDirection="column"
>
{settings.customWallpaper && (
<PictureThumbnail src={settings.customWallpaper} alt="chipisbest" />
)}
<TextField
value={value}
variant="outlined"
className={classes.input}
onChange={(e) => setValue(e.currentTarget.value)}
inputProps={{
className: classes.inputProps,
}}
placeholder="Image URL"
/>
<Button
color="primary"
variant="contained"
disabled={!isImage(value)}
onClick={handleNewWallpaper}
style={{ marginBottom: 10 }}
>
{t('APPS_SETTINGS_SET_CUSTOM_WALLPAPER')}
</Button>
{settings.customWallpaper && (
<StatusButton color="error" variant="contained" onClick={handleRemoveWallpaper}>
{t('GENERIC_DELETE')}
</StatusButton>
)}
</Box>
</Modal>
<DialogForm
open={customWallpaperModal}
handleClose={() => setCustomWallpaperModal(false)}
onSubmit={handleNewWallpaper}
title={t('SETTINGS.OPTIONS.CUSTOM_WALLPAPER.DIALOG_TITLE')}
content={t('SETTINGS.OPTIONS.CUSTOM_WALLPAPER.DIALOG_CONTENT')}
>
<TextField
value={value}
error={!isImageAndUrl(value) && true}
onChange={(e) => setValue(e.currentTarget.value)}
placeholder={t('SETTINGS.OPTIONS.CUSTOM_WALLPAPER.DIALOG_PLACEHOLDER')}
fullWidth
/>
</DialogForm>
);
}
+1 -3
View File
@@ -23,7 +23,6 @@ const settingsSchema: Schema = {
properties: {
language: { $ref: '/SettingOption' },
wallpaper: { $ref: '/SettingOption' },
customWallpaper: { type: 'string' },
frame: { $ref: '/SettingOption' },
theme: { $ref: '/SettingOption' },
zoom: { $ref: '/SettingOption' },
@@ -64,7 +63,6 @@ export function isSettingsSchemaValid(): boolean {
export interface IPhoneSettings {
language: SettingOption;
wallpaper: SettingOption;
customWallpaper: string;
frame: SettingOption;
theme: SettingOption;
zoom: SettingOption;
@@ -106,7 +104,7 @@ const localStorageEffect = (key) => ({ setSelf, onSet }) => {
});
};
export const settingsState = atom<IPhoneSettings>({
export const settingsState = atom({
key: 'settings',
default: config.defaultSettings,
effects_UNSTABLE: [localStorageEffect(NPWD_STORAGE_KEY)],
@@ -0,0 +1,8 @@
import config from '../../../config/default.json';
export const isDefaultWallpaper = (value: string) => {
const wallpapers = config.wallpapers;
for (const wallpaper of wallpapers) {
if (wallpaper.value === value) return true;
}
};
+4
View File
@@ -191,6 +191,10 @@
{
"label": "Default Light",
"value": "default-light"
},
{
"label": "Kiddo Dark",
"value": "kiddo-dark"
}
],
"debug": {
+16 -1
View File
@@ -34,5 +34,20 @@
}
},
"divider": "rgba(255, 255, 255, 0.12)"
},
"kiddo-dark": {
"palette": {
"type": "dark",
"primary": {
"main": "#EBFEF3"
},
"secondary": {
"main": "#5E0035"
},
"background": {
"default": "#033A18",
"paper": "#011308"
}
}
}
}
}
+7 -2
View File
@@ -11,7 +11,13 @@
"OPTIONS": {
"LANGUAGE": "Language",
"RESET_SETTINGS": "Reset Settings",
"RESET_SETTINGS_DESC": "This will clear your locally stored data"
"RESET_SETTINGS_DESC": "This will clear your locally stored data",
"CUSTOM_WALLPAPER": {
"DIALOG_TITLE": "Custom Wallpaper",
"DIALOG_CONTENT": "Set a custom wallpaper by entering the URL of the image below!",
"DIALOG_PLACEHOLDER": "Image URL",
"DIALOG_ERROR": "Invalid image or link"
}
},
"MESSAGES": {
"INVALID_SETTINGS": "Invalid stored settings! Please reset in the Settings App.",
@@ -195,7 +201,6 @@
"APPS_SETTINGS_OPTION_NOTIFICATION": "Notification",
"APPS_SETTINGS_OPTION_NOTIFICATIONVOL": "Notification Volume",
"APPS_SETTING_STREAMER_MODE_DESC": "Hide images before they are shown",
"APPS_SETTINGS_SET_CUSTOM_WALLPAPER": "Set new wallpaper",
"APPS_MARKETPLACE_CREATE_LISTING_SUCCESS": "Successfully created a new listing",
"APPS_MARKETPLACE_CREATE_LISTING_FAILED": "Failed to create a new listing",
+8 -1
View File
@@ -1,7 +1,13 @@
import React from 'react';
import { blue, common, grey, purple } from '@material-ui/core/colors';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faAd, faPlaneArrival, faPhoneAlt, faStickyNote } from '@fortawesome/free-solid-svg-icons';
import {
faAd,
faPlaneArrival,
faPhoneAlt,
faWonSign,
faStickyNote,
} from '@fortawesome/free-solid-svg-icons';
import { faTwitter } from '@fortawesome/free-brands-svg-icons';
import ContactsIcon from '@material-ui/icons/Contacts';
@@ -14,6 +20,7 @@ import { DialerApp } from '../../../apps/dialer/components/DialerApp';
import { ContactsApp } from '../../../apps/contacts/components/ContactsApp';
import { CalculatorApp } from '../../../apps/calculator/components/CalculatorApp';
import { SettingsApp } from '../../../apps/settings/components/SettingsApp';
import { BankApp } from '../../../apps/bank/components/BankApp';
import { MessagesApp } from '../../../apps/messages/components/MessagesApp';
import { MatchApp } from '../../../apps/match/components/MatchApp';
import { TwitterApp } from '../../../apps/twitter/components/TwitterApp';
@@ -2,10 +2,10 @@ import React from 'react';
import { Box, makeStyles } from '@material-ui/core';
import { CallControls } from './CallControls';
// interface ICallNotificationProps {
// onAccept(): void;
// onReject(): void;
// }
interface ICallNotificationProps {
onAccept(): void;
onReject(): void;
}
const useStyles = makeStyles((theme) => ({
root: {
+2 -3
View File
@@ -1,12 +1,11 @@
import { atom } from 'recoil';
import { ActiveCall } from '../../../../../typings/call';
export const callerState = {
currentCall: atom<ActiveCall>({
currentCall: atom({
key: 'currentCall',
default: null,
}),
callModal: atom<boolean>({
callModal: atom({
key: 'callingModal',
default: false,
}),
+2 -2
View File
@@ -1,11 +1,11 @@
import { useRecoilState } from 'recoil';
import { ActiveCall } from '../../../../../typings/call';
import { CallProps } from '../../../../../typings/call';
import Nui from '../../nui-events/utils/Nui';
import { callerState } from './state';
import { CallEvents } from '../../../../../typings/call';
interface CallHook {
call: ActiveCall;
call: CallProps;
setCall: (details: any) => void;
acceptCall(): void;
rejectCall(): void;
@@ -1,7 +1,7 @@
import React from 'react';
import { useTranslation } from 'react-i18next';
import { useHistory } from 'react-router-dom';
import { ActiveCall } from '../../../../../typings/call';
import { CallProps } from '../../../../../typings/call';
import { useApp } from '../../apps/hooks/useApps';
import { useNotifications } from '../../notifications/hooks/useNotifications';
import { useRingtoneSound } from '../../sound/hooks/useRingtoneSound';
@@ -27,7 +27,7 @@ export const useCallNotifications = () => {
notificationIcon,
};
const setNotification = (call: ActiveCall) => {
const setNotification = (call: CallProps) => {
stop();
if (!call || !call.active) {
removeId(NOTIFICATION_ID);
+4 -4
View File
@@ -2,7 +2,7 @@ import { useEffect, useState } from 'react';
import { useNuiEvent } from '../../nui-events/hooks/useNuiEvent';
import { useSetRecoilState } from 'recoil';
import { useCall } from './useCall';
import { CallEvents, ActiveCall } from '../../../../../typings/call';
import { CallEvents, CallProps } from '../../../../../typings/call';
import InjectDebugData from '../../debug/InjectDebugData';
import { useCallModal } from './useCallModal';
import { useHistory, useLocation } from 'react-router-dom';
@@ -10,7 +10,7 @@ import { callerState } from './state';
import { useCallNotifications } from './useCallNotifications';
import { useDuration } from './useDuration';
InjectDebugData<ActiveCall | boolean>([
InjectDebugData<CallProps | boolean>([
/* {
app: 'CALL',
method: 'setCaller',
@@ -56,11 +56,11 @@ export const useCallService = () => {
}
}, [history, modal, pathname, modalHasBeenOpenedThisCall]);
const _setCall = (_call: ActiveCall) => {
const _setCall = (_call: CallProps) => {
resetDuration();
setCall(_call);
setNotification(_call);
};
useNuiEvent<ActiveCall>('CALL', CallEvents.SET_CALLER, _setCall, call);
useNuiEvent<CallProps>('CALL', CallEvents.SET_CALLER, _setCall, call);
useNuiEvent<boolean>('CALL', CallEvents.SET_CALL_MODAL, setModal);
};
@@ -0,0 +1,109 @@
import { useCallback, useEffect, useRef } from 'react';
import { useHistory } from 'react-router-dom';
import { atom, useSetRecoilState, useRecoilValue } from 'recoil';
import { usePhone } from '../../phone/hooks/usePhone';
const keyboardState = {
ArrowRight: atom({
key: 'ArrowRight',
default: null,
}),
ArrowLeft: atom({
key: 'ArrowLeft',
default: null,
}),
ArrowUp: atom({
key: 'ArrowUp',
default: null,
}),
ArrowDown: atom({
key: 'ArrowDown',
default: null,
}),
Backspace: atom({
key: 'Backspace',
default: null,
}),
Enter: atom({
key: 'Enter',
default: null,
}),
Escape: atom({
key: 'Escape',
default: null,
}),
};
const validKeys = [
'ArrowRight',
'ArrowLeft',
'ArrowUp',
'ArrowDown',
'Backspace',
'Enter',
'Escape',
];
const isKeyValid = (key) => validKeys.indexOf(key) !== -1;
export const useKeyboardService = () => {
const history = useHistory();
const { closePhone } = usePhone();
const getters = {
ArrowRight: useRecoilValue(keyboardState.ArrowRight),
ArrowLeft: useRecoilValue(keyboardState.ArrowLeft),
ArrowUp: useRecoilValue(keyboardState.ArrowUp),
ArrowDown: useRecoilValue(keyboardState.ArrowDown),
Backspace: useRecoilValue(keyboardState.Backspace),
Enter: useRecoilValue(keyboardState.Enter),
Escape: useRecoilValue(keyboardState.Escape),
};
const handlers = useRef(new Map());
const setEscape = useSetRecoilState<any>(keyboardState.Escape);
const setBackspace = useSetRecoilState(keyboardState.Backspace);
useEffect(
function registerCustomKeys() {
Object.keys(getters).forEach((g) => {
handlers.current.set(g, getters[g]);
});
},
[getters],
);
useEffect(
function handleNUIKeyboardMessage() {
function onKeyUp(event) {
const { key } = event;
const callback = handlers.current.get(key);
if (isKeyValid(key) && callback && callback.call) {
return callback(event);
}
}
window.addEventListener('keyup', onKeyUp);
return () => window.removeEventListener('keyup', onKeyUp);
},
[getters],
);
const backspaceHandler = useCallback(
(event) => {
if (['input', 'textarea'].includes(event.target.nodeName.toLowerCase())) {
// Dont anything if we are typing something :)
return;
}
history.goBack();
},
[history],
);
useEffect(
function registerDefaultHandlers() {
handlers.current.set('Escape', () => closePhone());
handlers.current.set('Backspace', backspaceHandler);
},
[setEscape, setBackspace, history, backspaceHandler, closePhone],
);
};
+1 -3
View File
@@ -26,7 +26,7 @@ function getParams(event, data): [RequestInfo, RequestInit] {
];
}
const NuiUtils = {
export default {
async send(event: any, data = {}) {
return fetch(...getParams(event, data));
},
@@ -34,5 +34,3 @@ const NuiUtils = {
return abortableFetch(...getParams(event, data));
},
};
export default NuiUtils;
+12
View File
@@ -0,0 +1,12 @@
import { atom } from 'recoil';
export const phoneSettings = {
theme: atom({
key: 'settingTheme',
default: 'default-dark',
}),
zoom: atom({
key: 'settingZoom',
default: '100%',
}),
};
+5 -6
View File
@@ -1,20 +1,19 @@
import { atom } from 'recoil';
import { IServerConfig } from '../../../../../typings/config';
export const phoneState = {
visibility: atom<boolean>({
visibility: atom({
key: 'phoneVisibility',
default: false,
}),
phoneConfig: atom<IServerConfig>({
phoneConfig: atom({
key: 'phoneConfig',
default: null,
default: undefined,
}),
phoneReady: atom<boolean>({
phoneReady: atom({
key: 'phoneReady',
default: false,
}),
phoneTime: atom<string>({
phoneTime: atom({
key: 'phoneTime',
default: null,
}),
+4 -5
View File
@@ -1,15 +1,14 @@
import { useSetRecoilState } from 'recoil';
import { phoneState } from './state';
import { useNuiEvent } from '../../nui-events/hooks/useNuiEvent';
import { PhoneEvents } from '../../../../../typings/phone';
export const usePhoneService = () => {
const setVisibility = useSetRecoilState(phoneState.visibility);
const setPhoneConfig = useSetRecoilState(phoneState.phoneConfig);
const setPhoneReady = useSetRecoilState(phoneState.phoneReady);
const setPhoneTime = useSetRecoilState(phoneState.phoneTime);
useNuiEvent('PHONE', PhoneEvents.SET_VISIBILITY, setVisibility);
useNuiEvent('PHONE', PhoneEvents.SET_PHONE_READY, setPhoneReady);
useNuiEvent('PHONE', PhoneEvents.SET_CONFIG, setPhoneConfig);
useNuiEvent('PHONE', PhoneEvents.SET_TIME, setPhoneTime);
useNuiEvent('PHONE', 'setVisibility', setVisibility);
useNuiEvent('PHONE', 'setPhoneReady', setPhoneReady);
useNuiEvent('PHONE', 'phoneConfig', setPhoneConfig);
useNuiEvent('PHONE', 'setTime', setPhoneTime);
};
@@ -3,7 +3,6 @@ import { useSetRecoilState } from 'recoil';
import { simcardState } from './state';
import { useSimcard } from './useSimcard';
import InjectDebugData from '../../debug/InjectDebugData';
import { PhoneEvents } from '../../../../../typings/phone';
InjectDebugData([
{
@@ -15,6 +14,6 @@ InjectDebugData([
export const useSimcardService = () => {
const setNumber = useSetRecoilState(simcardState.number);
useNuiEvent('SIMCARD', PhoneEvents.SET_NUMBER, setNumber);
useNuiEvent('SIMCARD', 'setNumber', setNumber);
return useSimcard();
};
+69
View File
@@ -0,0 +1,69 @@
import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import { Button, DialogContent, DialogContentText, DialogTitle, Paper } from '@material-ui/core';
import DialogActions from '@material-ui/core/DialogActions';
const useStyles = makeStyles({
root: {
paddingLeft: '10px',
zIndex: 10,
width: '90%',
display: 'flex',
flexFlow: 'column nowrap',
position: 'absolute',
top: '80px',
},
displayBlock: {
/*Sets modal to center*/
display: 'flex',
flexFlow: 'column nowrap',
justifyContent: 'center',
alignItems: 'center',
position: 'relative',
},
displayNone: {
display: 'none',
},
});
interface DialogFormProps {
children: React.ReactNode;
open: boolean;
handleClose: any; // No idea what those types are
onSubmit: any;
title: string;
content: string;
}
export default function DialogForm({
children,
open,
handleClose,
onSubmit,
title,
content,
}: DialogFormProps) {
const classes = useStyles();
const showHideClassName = open ? classes.displayBlock : classes.displayNone;
return (
<div className={showHideClassName}>
<Paper className={classes.root}>
<DialogTitle id="form-dialog-title">{title}</DialogTitle>
<DialogContent>
<DialogContentText>{content}</DialogContentText>
{children}
</DialogContent>
<DialogActions>
<Button color="primary" onClick={handleClose}>
Cancel
</Button>
<Button color="primary" onClick={onSubmit}>
Confirm
</Button>
</DialogActions>
</Paper>
</div>
);
}
+7 -4
View File
@@ -2,11 +2,13 @@ import React from 'react';
import Paper from '@material-ui/core/Paper';
import Snackbar from '@material-ui/core/Snackbar';
import Fade from '@material-ui/core/Fade';
import { ThemeProvider } from '@material-ui/core';
import { createMuiTheme, ThemeProvider } from '@material-ui/core';
import { makeStyles } from '@material-ui/core/styles';
import { usePhone } from '../../os/phone/hooks/usePhone';
import { usePhoneTheme } from '../../os/phone/hooks/usePhoneTheme';
import { useRecoilState } from 'recoil';
import { settingsState } from '../../apps/settings/hooks/useSettings';
import themeConfig from '../../config/default.json';
const useStyles = makeStyles({
paper: {
@@ -23,14 +25,15 @@ function Notification({ children, handleClose, open }) {
const classes = useStyles();
const { config } = usePhone();
const currentTheme = usePhoneTheme();
const [settings] = useRecoilState(settingsState);
if (!config) return null;
const { horizontal, vertical } = config.notificationPosition;
const currentTheme = () => createMuiTheme(themeConfig.themes[settings.theme.value]);
return (
<ThemeProvider theme={currentTheme}>
<ThemeProvider theme={currentTheme()}>
<Snackbar
className={classes.snackBar}
anchorOrigin={{ horizontal, vertical }}
+19 -22
View File
@@ -1,5 +1,5 @@
import { CallEvents } from '../../typings/call';
import { CallHistoryItem } from '../../typings/call';
import { ICall } from '../../typings/call';
import { phoneCallStartAnim, phoneCallEndAnim } from './functions';
const exp = (global as any).exports;
@@ -34,26 +34,23 @@ on(`__cfx_nui:${CallEvents.ACCEPT_CALL}`, (data: any, cb: Function) => {
cb();
});
onNet(
CallEvents.WAS_ACCEPTED,
(channelId: number, currentCall: CallHistoryItem, isTransmitter: boolean) => {
exp['mumble-voip'].SetCallChannel(channelId);
phoneCallStartAnim(); // Trigger call animation only if the call was accepted.
SendNuiMessage(
JSON.stringify({
app: 'CALL',
method: CallEvents.SET_CALLER,
data: {
active: true,
transmitter: currentCall.transmitter,
receiver: currentCall.receiver,
isTransmitter: isTransmitter,
accepted: true,
},
}),
);
},
);
onNet(CallEvents.WAS_ACCEPTED, (channelId: number, currentCall: ICall, isTransmitter: boolean) => {
exp['mumble-voip'].SetCallChannel(channelId);
phoneCallStartAnim(); // Trigger call animation only if the call was accepted.
SendNuiMessage(
JSON.stringify({
app: 'CALL',
method: CallEvents.SET_CALLER,
data: {
active: true,
transmitter: currentCall.transmitter,
receiver: currentCall.receiver,
isTransmitter: isTransmitter,
accepted: true,
},
}),
);
});
RegisterNuiCallbackType(CallEvents.REJECTED); // Fires when cancelling and rejecting a call.
on(`__cfx_nui:${CallEvents.REJECTED}`, (data: any, cb: Function) => {
@@ -118,7 +115,7 @@ function openCallModal(show: boolean) {
);
}
onNet(CallEvents.SEND_HISTORY, (calls: CallHistoryItem[]) => {
onNet(CallEvents.SEND_HISTORY, (calls: ICall) => {
SendNuiMessage(
JSON.stringify({
app: 'DIALER',
+8 -8
View File
@@ -25,8 +25,8 @@ function fetchOnInitialize() {
emitNet(ContactEvents.GET_CONTACTS);
emitNet(MessageEvents.FETCH_MESSAGE_GROUPS);
emitNet(TwitterEvents.GET_OR_CREATE_PROFILE);
sendMessage('PHONE', PhoneEvents.SET_PHONE_READY, isPhoneReady);
sendMessage('PHONE', PhoneEvents.SET_CONFIG, config);
sendMessage('PHONE', 'setPhoneReady', isPhoneReady);
sendMessage('PHONE', 'phoneConfig', config);
}
RegisterKeyMapping('phone', 'Open Phone', 'keyboard', 'f1');
@@ -55,14 +55,14 @@ const showPhone = async (): Promise<void> => {
await phoneOpenAnim(); // Animation starts before the phone is open
emitNet('phone:getCredentials');
SetCursorLocation(0.9, 0.922); //Experimental
sendMessage('PHONE', PhoneEvents.SET_VISIBILITY, true);
sendMessage('PHONE', PhoneEvents.SET_TIME, time);
sendMessage('PHONE', 'setVisibility', true);
sendMessage('PHONE', 'setTime', time);
SetNuiFocus(true, true);
};
const hidePhone = async (): Promise<void> => {
isPhoneOpen = false;
sendMessage('PHONE', PhoneEvents.SET_VISIBILITY, false);
sendMessage('PHONE', 'setVisibility', false);
await phoneCloseAnim();
SetNuiFocus(false, false);
};
@@ -115,15 +115,15 @@ onNet(PhoneEvents.PLAYER_IS_READY, fetchOnInitialize);
AddEventHandler('onResourceStop', function (resource: string) {
if (resource === GetCurrentResourceName()) {
sendMessage('PHONE', PhoneEvents.SET_VISIBILITY, false);
sendMessage('PHONE', 'setVisibility', false);
SetNuiFocus(false, false);
removePhoneProp(); //Deletes the phone incase it was attached.
ClearPedTasks(PlayerPedId()); //Leave here until launch as it'll fix any stuck animations.
}
});
onNet(PhoneEvents.SEND_CREDENTIALS, (number: string) => {
sendMessage('SIMCARD', PhoneEvents.SET_NUMBER, number);
onNet('phone:sendCredentials', (number: string) => {
sendMessage('SIMCARD', 'setNumber', number);
});
// DO NOT CHANGE THIS EITHER, PLEASE - CHIP
+2 -3
View File
@@ -1,7 +1,6 @@
import { PhotoEvents } from '../../typings/photo';
import { Delay } from '../utils/fivem';
import { sendMessage, sendCameraEvent } from '../utils/messages';
import { PhoneEvents } from '../../typings/phone';
const SCREENSHOT_BASIC_TOKEN = GetConvar('SCREENSHOT_BASIC_TOKEN', 'none');
const exp = (global as any).exports;
@@ -10,12 +9,12 @@ let inCameraMode = false;
function closePhoneTemp() {
SetNuiFocus(false, false);
sendMessage('PHONE', PhoneEvents.SET_VISIBILITY, false);
sendMessage('PHONE', 'setVisibility', false);
}
function openPhoneTemp() {
SetNuiFocus(true, true);
sendMessage('PHONE', PhoneEvents.SET_VISIBILITY, true);
sendMessage('PHONE', 'setVisibility', true);
}
function CellFrontCamActivate(activate: boolean) {
+6 -6
View File
@@ -1,7 +1,7 @@
import { CallEvents } from '../../typings/call';
import { getIdentifierByPhoneNumber, getPlayer, getSource } from './functions';
import { getPlayerFromIdentifier } from './functions';
import { CallHistoryItem } from '../../typings/call';
import { ICall } from '../../typings/call';
import { pool } from './db';
import { v4 as uuidv4 } from 'uuid';
@@ -9,25 +9,25 @@ import { mainLogger } from './sv_logger';
const callLogger = mainLogger.child({ module: 'calls' });
async function saveCall(call: CallHistoryItem) {
async function saveCall(call: ICall) {
const query =
'INSERT INTO npwd_calls (identifier, transmitter, receiver, start) VALUES (?, ?, ?, ?)';
await pool.query(query, [call.identifier, call.transmitter, call.receiver, call.start]);
}
async function updateCall(call: CallHistoryItem, isAccepted: boolean, end: number) {
async function updateCall(call: ICall, isAccepted: boolean, end: number) {
const query = 'UPDATE npwd_calls SET is_accepted=?, end=? WHERE identifier = ?';
await pool.query(query, [isAccepted, end, call.identifier]);
}
async function fetchCalls(phoneNumber: string): Promise<CallHistoryItem[]> {
async function fetchCalls(phoneNumber: string): Promise<ICall[]> {
const query = 'SELECT * FROM npwd_calls WHERE receiver = ? OR transmitter = ? ORDER BY id DESC';
const [result] = await pool.query(query, [phoneNumber, phoneNumber]);
const calls = <CallHistoryItem[]>result;
const calls = <ICall[]>result;
return calls;
}
let calls: Map<string, CallHistoryItem> = new Map();
let calls: Map<string, ICall> = new Map();
onNet(CallEvents.INITIALIZE_CALL, async (phoneNumber: string) => {
const _source = getSource();
+1 -2
View File
@@ -1,7 +1,6 @@
import { pool } from './db';
import { getIdentifier, getSource } from './functions';
import { mainLogger } from './sv_logger';
import { PhoneEvents } from '../../typings/phone';
interface Credentials {
phone_number: string;
@@ -20,7 +19,7 @@ onNet('phone:getCredentials', async () => {
try {
const identifier = getIdentifier(_source);
const number = await getCredentials(identifier);
emitNet(PhoneEvents.SEND_CREDENTIALS, _source, number);
emitNet('phone:sendCredentials', _source, number);
} catch (e) {
mainLogger.error(`Failed to get a number, ${e.message}`, {
source: _source,
+9 -2
View File
@@ -1,4 +1,4 @@
export interface ActiveCall {
export interface CallProps {
active: boolean;
accepted: boolean;
isTransmitter: boolean;
@@ -6,7 +6,7 @@ export interface ActiveCall {
receiver: string;
}
export interface CallHistoryItem {
export interface ICall {
id?: number;
identifier: string;
transmitter: string;
@@ -18,6 +18,13 @@ export interface CallHistoryItem {
accepted: boolean;
}
export interface ICallDuration {
ms: number;
s: number;
m: number;
h: number;
}
export enum CallEvents {
INITIALIZE_CALL = 'npwd:beginCall',
START_CALL = 'npwd:startCall',
-6
View File
@@ -11,11 +11,5 @@ export enum PhoneEvents {
OPEN_PHONE = 'npwd:open',
CLOSE_PHONE = 'npwd:close',
SET_ALERT = 'npwd:setAlert',
SET_VISIBILITY = 'npwd:setVisibility',
SET_NOTIFICATION = 'npwd:setNotification',
SET_NUMBER = 'npwd:setNumber',
SET_PHONE_READY = 'npwd:phoneReady',
SET_CONFIG = 'npwd:setPhoneConfig',
SET_TIME = 'npwd:setGameTime',
SEND_CREDENTIALS = 'npwd:sendCredentials',
}