aboutsummaryrefslogtreecommitdiff
path: root/src/components/AttachLink/Modal.tsx
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2020-08-13 20:50:31 +0300
committereug-vs <eug-vs@keemail.me>2020-08-13 20:50:31 +0300
commit4109cd1b2fca7e4934f0aba1c3a7fabab62270bb (patch)
tree4b01a1900f4afe90d415e168cd08d5c26bd5721f /src/components/AttachLink/Modal.tsx
parentf62b506a05e4024d15a68a7441f320bae557df06 (diff)
downloadwhich-ui-4109cd1b2fca7e4934f0aba1c3a7fabab62270bb.tar.gz
feat: create AttachLink component
Diffstat (limited to 'src/components/AttachLink/Modal.tsx')
-rw-r--r--src/components/AttachLink/Modal.tsx76
1 files changed, 76 insertions, 0 deletions
diff --git a/src/components/AttachLink/Modal.tsx b/src/components/AttachLink/Modal.tsx
new file mode 100644
index 0000000..fa58fc4
--- /dev/null
+++ b/src/components/AttachLink/Modal.tsx
@@ -0,0 +1,76 @@
+import React, { useState } from 'react';
+import {
+ Button,
+ TextField,
+ Dialog,
+ DialogActions,
+ DialogContent,
+ DialogContentText,
+ DialogTitle
+} from '@material-ui/core';
+
+interface PropTypes {
+ isOpen: boolean;
+ setIsOpen: (value: boolean) => void;
+ callback: (url: string) => void;
+}
+
+const Modal: React.FC<PropTypes> = ({ setIsOpen, isOpen, callback }) => {
+ const [url, setUrl] = useState<string>('');
+
+ const handleClose = () => {
+ setIsOpen(false);
+ };
+
+ const handleSubmit = () => {
+ let result = url;
+ if (url.startsWith('https://www.instagram.com/')) {
+ const match = url.match('/p/(.*)/');
+ const id = match && match[1];
+ result = `https://www.instagram.com/p/${id}/media/?size=l`;
+ } else if (url.startsWith('https://drive.google.com/')) {
+ const match = url.match('/d/(.*)/');
+ const fileId = match && match[1];
+ result = `https://drive.google.com/uc?export=view&id=${fileId}`;
+ }
+ callback(result || '');
+ handleClose();
+ };
+
+ const handleChange = (event:React.ChangeEvent<HTMLInputElement>) => {
+ setUrl(event.target.value);
+ };
+
+ return (
+ <div>
+ <Dialog open={isOpen} onClose={handleClose}>
+ <DialogTitle>Upload via link</DialogTitle>
+ <DialogContent>
+ <DialogContentText>
+ Provide a valid URL to your image:
+ </DialogContentText>
+ <TextField
+ autoFocus
+ margin="dense"
+ id="name"
+ label="Image URL"
+ type="text"
+ fullWidth
+ autoComplete="off"
+ onChange={handleChange}
+ />
+ </DialogContent>
+ <DialogActions>
+ <Button onClick={handleClose} color="primary">
+ Cancel
+ </Button>
+ <Button onClick={handleSubmit} color="primary" disabled={!url.length}>
+ Submit
+ </Button>
+ </DialogActions>
+ </Dialog>
+ </div>
+ );
+};
+
+export default Modal;