forked from bukinoshita/secret
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
197 lines (167 loc) · 4.46 KB
/
index.js
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
'use strict'
import React, { Component } from 'react'
import Router from 'next/router'
import Link from 'next/link'
import Page from './../layouts/page'
import Button from './../components/button'
import Input from './../components/input'
import { colors, typography, phone } from './../theme'
import api from './../services/api'
class Home extends Component {
constructor() {
super()
this.onInputChange = this.onInputChange.bind(this)
this.onSubmit = this.onSubmit.bind(this)
this.addPassphrase = this.addPassphrase.bind(this)
this.state = {
message: '',
hasPassphrase: false,
passphrase: '',
requesting: false
}
}
onInputChange(event) {
const { target } = event
const { name, value } = target
this.setState({ [name]: value })
}
onSubmit(event) {
event.preventDefault()
this.setState({ requesting: true })
const { message, passphrase } = this.state
if (message.length >= 1) {
return api
.post('/secret', { message, passphrase })
.then(({ uid }) => {
this.setState({ requesting: false })
Router.push(`/secret?uid=${uid}`)
})
.catch(err => {
this.setState({ requesting: false })
console.log(err)
})
}
this.setState({ requesting: false })
}
addPassphrase() {
this.setState({ hasPassphrase: true })
}
render() {
const { message, hasPassphrase, passphrase, requesting } = this.state
const passphraseInput = hasPassphrase ? (
<Input
type="text"
placeholder="Your passphrase"
name="passphrase"
value={passphrase}
onChange={this.onInputChange}
autoFocus={true}
/>
) : (
<span onClick={this.addPassphrase}>
+ add passphrase
<style jsx>{`
span {
display: table;
color: ${colors.gray};
text-align: left;
font-size: ${typography.f12};
font-weight: ${typography.semibold};
margin-top: 5px;
cursor: pointer;
transition: all 0.2s;
}
span:hover {
color: ${colors.white};
}
`}</style>
</span>
)
return (
<Page>
<h3>
Use{' '}
<Link href="/canary">
<span>Canary</span>
</Link>{' '}
if you want a more secure secret.
<Link href="/about#canary">
<label>Learn more</label>
</Link>
</h3>
<form onSubmit={this.onSubmit}>
<Input
placeholder="Your secret..."
name="message"
value={message}
onChange={this.onInputChange}
autoFocus={true}
multiline={true}
/>
{passphraseInput}
<Button type="submit" disabled={requesting}>
Create
</Button>
</form>
<style jsx>{`
form {
max-width: 500px;
width: 100%;
margin-left: auto;
margin-right: auto;
text-align: center;
}
h3 {
text-align: center;
color: ${colors.white};
display: block;
font-size: ${typography.f14};
text-transform: lowercase;
margin-bottom: 30px;
font-weight: ${typography.regular};
}
span {
color: ${colors.pink};
cursor: pointer;
font-weight: ${typography.bold};
position: relative;
}
span:after {
content: '';
height: 1px;
background-color: ${colors.pink};
position: absolute;
pointer-events: none;
bottom: -4px;
left: 0;
right: 0;
opacity: 0;
transform: scale(0, 1);
transition: all 200ms;
}
span:hover:after {
opacity: 1;
transform: scale(1, 1);
}
label {
margin-left: 5px;
font-size: ${typography.f12};
font-weight: ${typography.bold};
cursor: pointer;
color: ${colors.gray};
transition: all 200ms;
}
label:hover {
color: ${colors.white};
}
@media ${phone} {
form {
max-width: 100%;
}
}
`}</style>
</Page>
)
}
}
export default Home