aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/components/PasteInfo.js
blob: 1ef69cc685f643aef070b449a80816068a8ce0c4 (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import React from 'react';
import styled from 'styled-components'
import { Theme } from './Inputs'
import {Button} from "./Common/Button";
import {useRouter} from "next/router";
import {ErrMsg} from "./Err";

const Bold = styled.span`
    font-weight: 700
`

const StyledDiv = styled.div`
    display: inline-block;
    margin: 2em 0;
`

const ShiftedButton = styled(Button)`
    margin-top: 1.6em !important;
`

const SpacedText = styled.span`
    margin-right: 1em;
`

const Flex = styled.div`
    float: right;
    display: flex;
    flex-direction: row;
`

const PasteInfo = ({hash, lang, theme, expiry, toggleRenderCallback, isRenderMode, onChange, err}) => {
    const router = useRouter()
    const redirRaw = () => {
        const redirUrl = `/raw/${hash}`
        router.push(redirUrl);
    }

    const renderable = () => {
        const buttonTxt = isRenderMode ? 'text' : 'render'
        if (lang === 'latex' || lang === 'markdown') {
            return (
                <ShiftedButton
                    secondary
                    type="button"
                    onClick={toggleRenderCallback}>
                    {buttonTxt}
                </ShiftedButton>
            );
        }
    }

    return (
        <div>
            <Flex>
                <ShiftedButton
                    secondary
                    type="button"
                    onClick={redirRaw}>
                    view raw
                </ShiftedButton>
                {renderable()}
                <Theme
                    value={theme}
                    onChange={onChange}
                    id="themeInput" />
            </Flex>
            <StyledDiv>
                {err ?
                  <ErrMsg active> {err} </ErrMsg> :
                  <>
                    <SpacedText>
                      <Bold>language:&nbsp;</Bold>{lang}
                    </SpacedText>
                    <SpacedText>
                      <Bold>expires:&nbsp;</Bold>{expiry}
                    </SpacedText>
                  </>
                }
            </StyledDiv>
        </div>
    );
}

export default PasteInfo