diff options
Diffstat (limited to 'src/components/UploadImage/UploadImage.tsx')
-rw-r--r-- | src/components/UploadImage/UploadImage.tsx | 21 |
1 files changed, 7 insertions, 14 deletions
diff --git a/src/components/UploadImage/UploadImage.tsx b/src/components/UploadImage/UploadImage.tsx index 836b2a0..5b2f38e 100644 --- a/src/components/UploadImage/UploadImage.tsx +++ b/src/components/UploadImage/UploadImage.tsx @@ -6,9 +6,7 @@ import { DialogActions, DialogContent, DialogContentText, - DialogTitle, - FormControlLabel, - Switch + DialogTitle } from '@material-ui/core'; interface PropTypes { @@ -19,15 +17,18 @@ interface PropTypes { const UploadImage: React.FC<PropTypes> = ({ setIsOpen, isOpen, callback }) => { const [url, setUrl] = useState<string>(''); - const [isInstagramLink, setIsInstagramLink] = useState<boolean>(false); - const handleClose = () => { setIsOpen(false); }; const handleSubmit = () => { - const result = isInstagramLink ? `${url.slice(0, url.length - 29)}/media/?size=l` : url; + let result = url; + if (url.startsWith('https://www.instagram.com/')) { + const lastSlashIndex = url.lastIndexOf('/'); + const baseUrl = url.slice(0, lastSlashIndex); + result = `${baseUrl}/media/?size=l`; + } callback(result || ''); handleClose(); }; @@ -36,10 +37,6 @@ const UploadImage: React.FC<PropTypes> = ({ setIsOpen, isOpen, callback }) => { setUrl(event.target.value); }; - const handleSwitch = () => { - setIsInstagramLink(!isInstagramLink); - }; - return ( <div> <Dialog open={isOpen} onClose={handleClose}> @@ -58,10 +55,6 @@ const UploadImage: React.FC<PropTypes> = ({ setIsOpen, isOpen, callback }) => { autoComplete="off" onChange={handleChange} /> - <FormControlLabel - control={<Switch color="primary" onClick={handleSwitch} checked={isInstagramLink} size="small" />} - label="It's an Instagram link" - /> </DialogContent> <DialogActions> <Button onClick={handleClose} color="primary"> |