mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 22:16:40 +00:00
update custom wallpaper | DialogForm UI
This commit is contained in:
1 parent
4c73f66ab5
commit
64beb6b69b
3 files changed
+99
-38
No files matched your search
@@ -1,11 +1,11 @@
|
|||||||
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 { Box, Button, TextField, Typography } from '@material-ui/core';
|
||||||
import { PictureThumbnail } from '../../../ui/components/PictureThumbnail';
|
import { PictureThumbnail } from '../../../ui/components/PictureThumbnail';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { makeStyles } from '@material-ui/core/styles';
|
import { makeStyles } from '@material-ui/core/styles';
|
||||||
import { StatusButton } from '../../../ui/components/StatusButton';
|
import DialogForm from '../../../ui/components/DialogForm';
|
||||||
|
import { useSnackbar } from '../../../ui/hooks/useSnackbar';
|
||||||
|
|
||||||
const useStyles = makeStyles({
|
const useStyles = makeStyles({
|
||||||
input: {
|
input: {
|
||||||
@@ -21,59 +21,43 @@ 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('wallpaper', { label: 'Custom Wallpaper', value });
|
if (isImageAndUrl(value)) {
|
||||||
|
handleSettingChange('wallpaper', {
|
||||||
|
label: t('APPS_SETTINGS_OPTIONS_CUSTOM_WALLPAPER'),
|
||||||
|
value,
|
||||||
|
});
|
||||||
setCustomWallpaperModal(false);
|
setCustomWallpaperModal(false);
|
||||||
|
} else {
|
||||||
|
addAlert({ message: t('APPS_SETTINGS_INVALID_WALLPAPER'), 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="Custom wallpaper"
|
||||||
textAlign="center"
|
content="Set a custom wallpaper by entering the URL of the image below!"
|
||||||
flexDirection="column"
|
|
||||||
>
|
>
|
||||||
{settings.customWallpaper && (
|
|
||||||
<PictureThumbnail src={settings.customWallpaper} alt="chipisbest" />
|
|
||||||
)}
|
|
||||||
<TextField
|
<TextField
|
||||||
value={value}
|
value={value}
|
||||||
variant="outlined"
|
|
||||||
size="small"
|
|
||||||
className={classes.input}
|
|
||||||
onChange={(e) => setValue(e.currentTarget.value)}
|
onChange={(e) => setValue(e.currentTarget.value)}
|
||||||
inputProps={{
|
|
||||||
className: classes.inputProps,
|
|
||||||
}}
|
|
||||||
placeholder="Image URL"
|
placeholder="Image URL"
|
||||||
|
fullWidth
|
||||||
/>
|
/>
|
||||||
<Button
|
</DialogForm>
|
||||||
color="primary"
|
|
||||||
variant="contained"
|
|
||||||
disabled={!isImage(value)}
|
|
||||||
onClick={handleNewWallpaper}
|
|
||||||
style={{ marginBottom: 10 }}
|
|
||||||
>
|
|
||||||
{t('APPS_SETTINGS_SET_CUSTOM_WALLPAPER')}
|
|
||||||
</Button>
|
|
||||||
</Box>
|
|
||||||
</Modal>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -192,6 +192,7 @@
|
|||||||
"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_SETTINGS_SET_CUSTOM_WALLPAPER": "Set new wallpaper",
|
||||||
|
"APPS_SETTINGS_INVALID_WALLPAPER": "Not a valid image or link!",
|
||||||
|
|
||||||
"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",
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { makeStyles } from '@material-ui/core/styles';
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
DialogContent,
|
||||||
|
DialogContentText,
|
||||||
|
DialogTitle,
|
||||||
|
Paper,
|
||||||
|
TextField,
|
||||||
|
} 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 DialogForm {
|
||||||
|
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,
|
||||||
|
}: DialogForm) {
|
||||||
|
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>
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in new issue
Block a user