11 changed files with 165 additions and 132 deletions

No files matched your search

+3 -2
View File
@@ -33,6 +33,7 @@ import WindowSnackbar from './ui/components/WindowSnackbar';
import { usePhone } from './os/phone/hooks/usePhone'; import { usePhone } from './os/phone/hooks/usePhone';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { useSnackbar } from './ui/hooks/useSnackbar'; import { useSnackbar } from './ui/hooks/useSnackbar';
import { isDefaultWallpaper } from './apps/settings/utils/isDefaultWallpaper';
function Phone() { function Phone() {
const { t, i18n } = useTranslation(); const { t, i18n } = useTranslation();
@@ -104,8 +105,8 @@ function Phone() {
id="phone" id="phone"
className="PhoneScreen" className="PhoneScreen"
style={{ style={{
backgroundImage: settings.customWallpaper backgroundImage: !isDefaultWallpaper(settings.wallpaper.value)
? `url(${settings.customWallpaper})` ? `url(${settings.wallpaper.value})`
: `url(media/backgrounds/${settings.wallpaper.value})`, : `url(media/backgrounds/${settings.wallpaper.value})`,
}} }}
> >
@@ -52,6 +52,7 @@ export const DialerInput = () => {
className={classes.input} className={classes.input}
value={inputVal} value={inputVal}
onChange={(e) => set(e.target.value)} onChange={(e) => set(e.target.value)}
type="number"
/> />
<IconButton color="primary" className={classes.iconBtn} disabled={inputVal <= ''}> <IconButton color="primary" className={classes.iconBtn} disabled={inputVal <= ''}>
<PhoneIcon fontSize="large" onClick={() => handleCall(inputVal)} /> <PhoneIcon fontSize="large" onClick={() => handleCall(inputVal)} />
@@ -3,7 +3,9 @@ import qs from 'qs';
import Nui from '../../../../os/nui-events/utils/Nui'; import Nui from '../../../../os/nui-events/utils/Nui';
import Modal from '../../../../ui/components/Modal'; import Modal from '../../../../ui/components/Modal';
import PhotoLibraryIcon from '@material-ui/icons/PhotoLibrary'; import PhotoLibraryIcon from '@material-ui/icons/PhotoLibrary';
import { Box, Typography, Button } from '@material-ui/core'; import { Box, Typography, TextField, Button } from '@material-ui/core';
import FileCopyIcon from '@material-ui/icons/FileCopy';
import useStyles from './modal.styles';
import { useHistory, useLocation } from 'react-router-dom'; import { useHistory, useLocation } from 'react-router-dom';
import { ContextMenu } from '../../../../ui/components/ContextMenu'; import { ContextMenu } from '../../../../ui/components/ContextMenu';
import { deleteQueryFromLocation } from '../../../../common/utils/deleteQueryFromLocation'; import { deleteQueryFromLocation } from '../../../../common/utils/deleteQueryFromLocation';
@@ -18,8 +20,12 @@ interface IProps {
} }
export const MessageImageModal = ({ isOpen, messageGroupId, onClose, image }: IProps) => { export const MessageImageModal = ({ isOpen, messageGroupId, onClose, image }: IProps) => {
const classes = useStyles();
const history = useHistory(); const history = useHistory();
const { pathname, search } = useLocation(); const { pathname, search } = useLocation();
const [message, setMessage] = useState('');
const [pasteVisible, setPasteVisible] = useState(false);
const [queryParamImagePreview, setQueryParamImagePreview] = useState(null); const [queryParamImagePreview, setQueryParamImagePreview] = useState(null);
const removeQueryParamImage = useCallback(() => { const removeQueryParamImage = useCallback(() => {
@@ -49,10 +55,21 @@ export const MessageImageModal = ({ isOpen, messageGroupId, onClose, image }: IP
useEffect(() => { useEffect(() => {
if (!image) return; if (!image) return;
setQueryParamImagePreview(image); setQueryParamImagePreview(image);
}, [image]); }, [image, sendFromQueryParam]);
const sendFromClipboard = (event) => {
if (event.key === 'Enter') {
sendImageMessage(message);
}
};
const menuOptions = useMemo( const menuOptions = useMemo(
() => [ () => [
{
label: 'Paste from clipboard',
icon: <FileCopyIcon />,
onClick: () => setPasteVisible(true),
},
{ {
label: 'Camera / Gallery', label: 'Camera / Gallery',
icon: <PhotoLibraryIcon />, icon: <PhotoLibraryIcon />,
@@ -73,7 +90,7 @@ export const MessageImageModal = ({ isOpen, messageGroupId, onClose, image }: IP
<Modal visible={queryParamImagePreview} handleClose={removeQueryParamImage}> <Modal visible={queryParamImagePreview} handleClose={removeQueryParamImage}>
<Box py={1}> <Box py={1}>
<Typography paragraph>Do you want to share this image?</Typography> <Typography paragraph>Do you want to share this image?</Typography>
<PictureResponsive src={queryParamImagePreview} alt="Share gallery image preview" /> <PictureResponsive src={queryParamImagePreview} alt={'Share gallery image preview'} />
<Button <Button
fullWidth fullWidth
variant="contained" variant="contained"
@@ -84,6 +101,21 @@ export const MessageImageModal = ({ isOpen, messageGroupId, onClose, image }: IP
</Button> </Button>
</Box> </Box>
</Modal> </Modal>
<Modal visible={pasteVisible} handleClose={() => setPasteVisible(false)}>
<Box p={1}>
<TextField
placeholder="A link to your image or gif"
onChange={(e) => setMessage(e.target.value)}
value={message}
fullWidth
inputProps={{
className: classes.messagesInput,
}}
inputRef={(input) => input && input.focus()}
onKeyPress={sendFromClipboard}
/>
</Box>
</Modal>
</> </>
); );
}; };
@@ -10,10 +10,7 @@ import {
Tooltip, Tooltip,
Typography, Typography,
Switch, Switch,
TextField,
} from '@material-ui/core'; } from '@material-ui/core';
import CreateIcon from '@material-ui/icons/Create';
import { PictureThumbnail } from '../../../ui/components/PictureThumbnail';
interface ISettingItem { interface ISettingItem {
options?: any; options?: any;
@@ -109,15 +106,3 @@ export const SettingItemIconAction = ({
</ListItem> </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>
);
@@ -1,4 +1,4 @@
import React, { useState } from 'react'; import React from 'react';
import { AppWrapper } from '../../../ui/components'; import { AppWrapper } from '../../../ui/components';
import { AppTitle } from '../../../ui/components/AppTitle'; import { AppTitle } from '../../../ui/components/AppTitle';
import { AppContent } from '../../../ui/components/AppContent'; import { AppContent } from '../../../ui/components/AppContent';
@@ -12,7 +12,6 @@ import {
SettingItemIconAction, SettingItemIconAction,
SettingItemSlider, SettingItemSlider,
SettingSwitch, SettingSwitch,
SettingItemModal,
} from './SettingItem'; } from './SettingItem';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import VisibilityOffIcon from '@material-ui/icons/VisibilityOff'; import VisibilityOffIcon from '@material-ui/icons/VisibilityOff';
@@ -73,9 +72,9 @@ export const SettingsApp = () => {
}; };
const wallpapers = config.wallpapers.map( const wallpapers = config.wallpapers.map(
MapSettingItem(settings.wallpaper, (val: SettingOption) => MapSettingItem(settings.wallpaper, (val: SettingOption) => {
handleSettingChange('wallpaper', val), handleSettingChange('wallpaper', val);
), }),
); );
const frames = config.frames.map( const frames = config.frames.map(
MapSettingItem(settings.frame, (val: SettingOption) => handleSettingChange('frame', val)), 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 = () => { const handleCopyPhoneNumber = () => {
setClipboard(simcard.number); setClipboard(simcard.number);
addAlert({ addAlert({
@@ -209,17 +215,10 @@ export const SettingsApp = () => {
<SettingItem <SettingItem
label={t('APPS_SETTINGS_OPTION_WALLPAPER')} label={t('APPS_SETTINGS_OPTION_WALLPAPER')}
value={settings.wallpaper.label} value={settings.wallpaper.label}
options={wallpapers} options={[...wallpapers, customWallpaper]}
onClick={openMenu} onClick={openMenu}
icon={<Wallpaper />} icon={<Wallpaper />}
/> />
{/* CUSTOM BACKGROUND */}
<SettingItemModal
icon={<Wallpaper />}
label={t('APPS_SETTINGS_OPTIONS_CUSTOM_WALLPAPER')}
secondary={settings.customWallpaper}
onClick={() => setCustomWallpaperModal(true)}
/>
<SettingItem <SettingItem
label={t('APPS_SETTINGS_OPTION_FRAME')} label={t('APPS_SETTINGS_OPTION_FRAME')}
value={settings.frame.label} value={settings.frame.label}
@@ -1,86 +1,52 @@
import React, { useState } from 'react'; import React, { useState } from 'react';
import Modal from '../../../ui/components/Modal';
import { useCustomWallpaperModal, useSettings } from '../hooks/useSettings'; import { useCustomWallpaperModal, useSettings } from '../hooks/useSettings';
import { Box, Button, TextField } from '@material-ui/core'; import { TextField } from '@material-ui/core';
import { PictureThumbnail } from '../../../ui/components/PictureThumbnail';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { makeStyles } from '@material-ui/core/styles'; import DialogForm from '../../../ui/components/DialogForm';
import { StatusButton } from '../../../ui/components/StatusButton'; import { useSnackbar } from '../../../ui/hooks/useSnackbar';
const useStyles = makeStyles({
input: {
marginTop: 10,
marginBottom: 10,
},
inputProps: {
fontSize: 18,
},
});
export default function WallpaperModal() { export default function WallpaperModal() {
const { customWallpaperModal, setCustomWallpaperModal } = useCustomWallpaperModal(); const { customWallpaperModal, setCustomWallpaperModal } = useCustomWallpaperModal();
const [settings, setSettings] = useSettings(); const [settings, setSettings] = useSettings();
const { t } = useTranslation(); const { t } = useTranslation();
const [value, setValue] = useState(settings.customWallpaper ? settings.customWallpaper : ''); const [value, setValue] = useState('');
const classes = useStyles(); const { addAlert } = useSnackbar();
const isImage = (url) => { const isImageAndUrl = (url) => {
return /(http(s?):)([/|.|\w|\s|-])*\.(?:jpg|png|jpeg|gif)/g.test(url); return /(http(s?):)([/|.|\w|\s|-])*\.(?:jpg|png|jpeg|gif)/g.test(url);
}; };
const handleCloseModal = () => {
setCustomWallpaperModal(false);
};
const handleSettingChange = (key: string | number, value: unknown) => { const handleSettingChange = (key: string | number, value: unknown) => {
setSettings({ ...settings, [key]: value }); setSettings({ ...settings, [key]: value });
}; };
const handleNewWallpaper = () => { const handleNewWallpaper = () => {
handleSettingChange('customWallpaper', value); if (isImageAndUrl(value)) {
}; handleSettingChange('wallpaper', {
label: t('APPS_SETTINGS_OPTIONS_CUSTOM_WALLPAPER'),
const handleRemoveWallpaper = () => { value,
handleSettingChange('customWallpaper', ''); });
setCustomWallpaperModal(false);
} else {
addAlert({ message: t('SETTINGS.OPTIONS.CUSTOM_WALLPAPER.DIALOG_ERROR'), type: 'error' });
}
}; };
return ( return (
<Modal visible={customWallpaperModal} handleClose={handleCloseModal}> <DialogForm
<Box open={customWallpaperModal}
display="flex" handleClose={() => setCustomWallpaperModal(false)}
justifyContent="center" onSubmit={handleNewWallpaper}
alignItems="center" title={t('SETTINGS.OPTIONS.CUSTOM_WALLPAPER.DIALOG_TITLE')}
textAlign="center" content={t('SETTINGS.OPTIONS.CUSTOM_WALLPAPER.DIALOG_CONTENT')}
flexDirection="column" >
> <TextField
{settings.customWallpaper && ( value={value}
<PictureThumbnail src={settings.customWallpaper} alt="chipisbest" /> error={!isImageAndUrl(value) && true}
)} onChange={(e) => setValue(e.currentTarget.value)}
<TextField placeholder={t('SETTINGS.OPTIONS.CUSTOM_WALLPAPER.DIALOG_PLACEHOLDER')}
value={value} fullWidth
variant="outlined" />
className={classes.input} </DialogForm>
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>
); );
} }
@@ -23,7 +23,6 @@ const settingsSchema: Schema = {
properties: { properties: {
language: { $ref: '/SettingOption' }, language: { $ref: '/SettingOption' },
wallpaper: { $ref: '/SettingOption' }, wallpaper: { $ref: '/SettingOption' },
customWallpaper: { type: 'string' },
frame: { $ref: '/SettingOption' }, frame: { $ref: '/SettingOption' },
theme: { $ref: '/SettingOption' }, theme: { $ref: '/SettingOption' },
zoom: { $ref: '/SettingOption' }, zoom: { $ref: '/SettingOption' },
@@ -64,7 +63,6 @@ export function isSettingsSchemaValid(): boolean {
export interface IPhoneSettings { export interface IPhoneSettings {
language: SettingOption; language: SettingOption;
wallpaper: SettingOption; wallpaper: SettingOption;
customWallpaper: string;
frame: SettingOption; frame: SettingOption;
theme: SettingOption; theme: SettingOption;
zoom: SettingOption; zoom: SettingOption;
@@ -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;
}
};
+7 -2
View File
@@ -11,7 +11,13 @@
"OPTIONS": { "OPTIONS": {
"LANGUAGE": "Language", "LANGUAGE": "Language",
"RESET_SETTINGS": "Reset Settings", "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": { "MESSAGES": {
"INVALID_SETTINGS": "Invalid stored settings! Please reset in the Settings App.", "INVALID_SETTINGS": "Invalid stored settings! Please reset in the Settings App.",
@@ -195,7 +201,6 @@
"APPS_SETTINGS_OPTION_NOTIFICATION": "Notification", "APPS_SETTINGS_OPTION_NOTIFICATION": "Notification",
"APPS_SETTINGS_OPTION_NOTIFICATIONVOL": "Notification Volume", "APPS_SETTINGS_OPTION_NOTIFICATIONVOL": "Notification Volume",
"APPS_SETTING_STREAMER_MODE_DESC": "Hide images before they are shown", "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_SUCCESS": "Successfully created a new listing",
"APPS_MARKETPLACE_CREATE_LISTING_FAILED": "Failed to create a new listing", "APPS_MARKETPLACE_CREATE_LISTING_FAILED": "Failed to create a new listing",
+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>
);
}
-31
View File
@@ -11,7 +11,6 @@ import { BankEvents } from '../../typings/bank';
import { PhotoEvents } from '../../typings/photo'; import { PhotoEvents } from '../../typings/photo';
import { CallEvents } from '../../typings/call'; import { CallEvents } from '../../typings/call';
import { MatchEvents } from '../../typings/match'; import { MatchEvents } from '../../typings/match';
import { Delay } from '../utils/fivem';
let isPhoneOpen = false; let isPhoneOpen = false;
let isPhoneReady = false; let isPhoneReady = false;
@@ -52,7 +51,6 @@ const getCurrentGameTime = () => {
const showPhone = async (): Promise<void> => { const showPhone = async (): Promise<void> => {
isPhoneOpen = true; isPhoneOpen = true;
disableControls();
const time = getCurrentGameTime(); const time = getCurrentGameTime();
await phoneOpenAnim(); // Animation starts before the phone is open await phoneOpenAnim(); // Animation starts before the phone is open
emitNet('phone:getCredentials'); emitNet('phone:getCredentials');
@@ -60,7 +58,6 @@ const showPhone = async (): Promise<void> => {
sendMessage('PHONE', 'setVisibility', true); sendMessage('PHONE', 'setVisibility', true);
sendMessage('PHONE', 'setTime', time); sendMessage('PHONE', 'setTime', time);
SetNuiFocus(true, true); SetNuiFocus(true, true);
SetNuiFocusKeepInput(true);
}; };
const hidePhone = async (): Promise<void> => { const hidePhone = async (): Promise<void> => {
@@ -68,7 +65,6 @@ const hidePhone = async (): Promise<void> => {
sendMessage('PHONE', 'setVisibility', false); sendMessage('PHONE', 'setVisibility', false);
await phoneCloseAnim(); await phoneCloseAnim();
SetNuiFocus(false, false); SetNuiFocus(false, false);
SetNuiFocusKeepInput(false);
}; };
/* * * * * * * * * * * * * /* * * * * * * * * * * * *
@@ -200,30 +196,3 @@ on(`__cfx_nui:${PhoneEvents.CLOSE_PHONE}`, async (data: any, cb: Function) => {
// const time = getCurrentGameTime() // const time = getCurrentGameTime()
// sendMessage('PHONE', 'setTime', time) // sendMessage('PHONE', 'setTime', time)
// }, 2000); // }, 2000);
function disableControls(): void {
let timeoutFinished = false;
const loopTick = setTick(
async (useTimeout = false): Promise<void> => {
if (!isPhoneOpen) {
clearTick(loopTick);
return;
}
if (isPhoneOpen) {
DisableControlAction(0, 1, true);
DisableControlAction(0, 2, true);
DisableControlAction(0, 16, true);
DisableControlAction(0, 17, true);
if (useTimeout) {
setTimeout(() => {
timeoutFinished = true;
}, 5000);
}
} else {
await Delay(30000);
}
},
);
}