update custom wallpaper | DialogForm UI

This commit is contained in:
Christopher committed 2021-04-01 20:53:33 +02:00
1 parent 4c73f66ab5
commit 64beb6b69b
3 files changed
+106 -45

No files matched your search

@@ -1,11 +1,11 @@
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 { Box, Button, TextField, Typography } from '@material-ui/core';
import { PictureThumbnail } from '../../../ui/components/PictureThumbnail';
import { useTranslation } from 'react-i18next';
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({
input: {
@@ -21,59 +21,43 @@ 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('wallpaper', { label: 'Custom Wallpaper', value });
setCustomWallpaperModal(false);
if (isImageAndUrl(value)) {
handleSettingChange('wallpaper', {
label: t('APPS_SETTINGS_OPTIONS_CUSTOM_WALLPAPER'),
value,
});
setCustomWallpaperModal(false);
} else {
addAlert({ message: t('APPS_SETTINGS_INVALID_WALLPAPER'), 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"
size="small"
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>
</Box>
</Modal>
<DialogForm
open={customWallpaperModal}
handleClose={() => setCustomWallpaperModal(false)}
onSubmit={handleNewWallpaper}
title="Custom wallpaper"
content="Set a custom wallpaper by entering the URL of the image below!"
>
<TextField
value={value}
onChange={(e) => setValue(e.currentTarget.value)}
placeholder="Image URL"
fullWidth
/>
</DialogForm>
);
}
+1
View File
@@ -192,6 +192,7 @@
"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_SETTINGS_INVALID_WALLPAPER": "Not a valid image or link!",
"APPS_MARKETPLACE_CREATE_LISTING_SUCCESS": "Successfully created a new listing",
"APPS_MARKETPLACE_CREATE_LISTING_FAILED": "Failed to create a new listing",
+76
View File
@@ -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>
);
}