aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/components/modals/PasteModal.js
blob: 7b28abb8023fcd8a4f431d85f298e4e5c8810ab2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import React from 'react';
import Modal from 'react-modal';
import { LeftPad, ModalHeader, RightPad } from './shared'
import { useHistory } from 'react-router-dom';
import { PasteURLInput } from '../Inputs'
import { useClipboard } from 'use-clipboard-copy';

const modalStyles = {
    content: {
        top: '50%',
        left: '50%',
        transform: 'translate(-50%, -50%)',
        width: '500px',
        height: '250px',
        border: '1px solid #11111188'
    }
};

const PasteModal = (props) => {
    const history = useHistory();
    const fullURL = `${window.location.origin}/${props.hash}`;
    const clipboard = useClipboard({ copiedTimeout: 3000 });
    Modal.setAppElement('body');

    const redir = (e) => {
        e.preventDefault();
        const redirUrl = `/${props.hash}`
        history.push(redirUrl);
    }

    return (
        <Modal
            isOpen={props.hash !== ''}
            style={modalStyles}
            contentLabel="paste created"
        >
            <form onSubmit={redir}>
                <LeftPad>
                    <ModalHeader><span role="img" aria-label="success">📎&nbsp;</span>paste created</ModalHeader>
                </LeftPad>
                    <RightPad>
                        <PasteURLInput 
                            id="paste_modal"
                            fullURL={fullURL} />
                        <input 
                            hidden
                            type="text"
                            value={fullURL} 
                            readOnly
                            ref={clipboard.target} />
                    </RightPad>
                <LeftPad>
                    <button 
                        className="lt-button lt-shadow lt-hover"
                        type="submit">
                            view
                    </button>
                    <button 
                        className="lt-button lt-shadow lt-hover"
                        type="button" 
                        onClick={clipboard.copy}>
                            {clipboard.copied ? 'copied' : 'copy url'}
                    </button>
                </LeftPad>
            </form>
        </Modal>
    );
}

export default PasteModal