diff --git a/phone/src/apps/settings/components/WallpaperModal.tsx b/phone/src/apps/settings/components/WallpaperModal.tsx
index 3dbff98..7f8c591 100644
--- a/phone/src/apps/settings/components/WallpaperModal.tsx
+++ b/phone/src/apps/settings/components/WallpaperModal.tsx
@@ -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 (
-
-
- {settings.customWallpaper && (
-
- )}
- setValue(e.currentTarget.value)}
- inputProps={{
- className: classes.inputProps,
- }}
- placeholder="Image URL"
- />
-
-
-
+ setCustomWallpaperModal(false)}
+ onSubmit={handleNewWallpaper}
+ title="Custom wallpaper"
+ content="Set a custom wallpaper by entering the URL of the image below!"
+ >
+ setValue(e.currentTarget.value)}
+ placeholder="Image URL"
+ fullWidth
+ />
+
);
}
diff --git a/phone/src/locale/en.json b/phone/src/locale/en.json
index f724357..1d67f89 100644
--- a/phone/src/locale/en.json
+++ b/phone/src/locale/en.json
@@ -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",
diff --git a/phone/src/ui/components/DialogForm.tsx b/phone/src/ui/components/DialogForm.tsx
new file mode 100644
index 0000000..6e4cee0
--- /dev/null
+++ b/phone/src/ui/components/DialogForm.tsx
@@ -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 (
+
+
+ {title}
+
+ {content}
+ {children}
+
+
+
+
+
+
+
+ );
+}