aboutsummaryrefslogtreecommitdiff
path: root/src/components/UploadImage/UploadImage.tsx
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2020-07-05 17:28:08 +0300
committereug-vs <eug-vs@keemail.me>2020-07-05 17:32:31 +0300
commit8b5df9285b3917c63b7904b434354e3d4b58858d (patch)
tree31efd6b9c55796cc7d9afd0f96cb4299cbd30220 /src/components/UploadImage/UploadImage.tsx
parenta5c57253ceb0923aefd8dedcb7bd912cb1fa3d2e (diff)
downloadwhich-ui-8b5df9285b3917c63b7904b434354e3d4b58858d.tar.gz
fix: resolve instagram url correctly
Diffstat (limited to 'src/components/UploadImage/UploadImage.tsx')
-rw-r--r--src/components/UploadImage/UploadImage.tsx21
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">