aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/components
diff options
context:
space:
mode:
authorRyan Mehri <[email protected]>2020-05-10 17:37:36 -0600
committerGitHub <[email protected]>2020-05-10 17:37:36 -0600
commitd20bfdc3f1a78a10dce2662b41d76eba6fab0aad (patch)
tree465b89c4028572ad9a213b746f50823fb28954a8 /frontend/src/components
parentMerge pull request #11 from jackyzha0/pass_and_expiry (diff)
parentlinked backend and frontend (diff)
downloadctrl-v-d20bfdc3f1a78a10dce2662b41d76eba6fab0aad.tar.xz
ctrl-v-d20bfdc3f1a78a10dce2662b41d76eba6fab0aad.zip
Merge pull request #13 from jackyzha0/link-fe-be
linked backend and frontend
Diffstat (limited to 'frontend/src/components')
-rw-r--r--frontend/src/components/Inputs.js1
-rw-r--r--frontend/src/components/PasteArea.js54
2 files changed, 51 insertions, 4 deletions
diff --git a/frontend/src/components/Inputs.js b/frontend/src/components/Inputs.js
index aa68a70..110d5bd 100644
--- a/frontend/src/components/Inputs.js
+++ b/frontend/src/components/Inputs.js
@@ -52,6 +52,7 @@ class PasteInput extends React.Component {
placeholder="Paste your text here"
value={this.props.content}
id={this.props.id}
+ required
onChange={this.props.onChange}
className="lt-shadow" />
<CharLimit
diff --git a/frontend/src/components/PasteArea.js b/frontend/src/components/PasteArea.js
index 4232c7f..bd08fc1 100644
--- a/frontend/src/components/PasteArea.js
+++ b/frontend/src/components/PasteArea.js
@@ -1,6 +1,7 @@
import React from 'react';
import { TitleInput, PasteInput } from './Inputs'
import OptionsContainer from './Options'
+import axios from 'axios';
class PasteArea extends React.Component {
constructor(props) {
@@ -33,11 +34,56 @@ class PasteArea extends React.Component {
});
}
+ parseExpiry(e) {
+ var cur = new Date();
+ var inSeconds = 0
+ switch (e) {
+ case '5 years':
+ inSeconds = 600 * 6 * 24 * 7 * 4 * 12 * 5
+ break;
+ case '1 year':
+ inSeconds = 600 * 6 * 24 * 7 * 4 * 12
+ break;
+ case '1 month':
+ inSeconds = 600 * 6 * 24 * 7 * 4
+ break;
+ case '1 day':
+ inSeconds = 600 * 6 * 24
+ break;
+ case '1 hour':
+ inSeconds = 600 * 6
+ break;
+ case '10 min':
+ inSeconds = 600
+ break;
+ case '1 week':
+ default:
+ inSeconds = 600 * 6 * 24 * 7
+ break;
+ }
+ return new Date(cur.getTime() + inSeconds * 1000).toISOString();
+ }
+
handleSubmit(event) {
- console.log(`title: ${this.state.title}`)
- console.log(`content: ${this.state.content}`)
- console.log(`pass: ${this.state.pass}`)
- console.log(`expiry: ${this.state.expiry}`)
+ var bodyFormData = new FormData();
+ bodyFormData.set('title', this.state.title);
+ bodyFormData.set('content', this.state.content);
+ bodyFormData.set('password', this.state.pass);
+ bodyFormData.set('expiry', this.parseExpiry(this.state.expiry));
+
+ axios({
+ method: 'post',
+ url: 'http://localhost:8080/api',
+ data: bodyFormData,
+ headers: { 'Content-Type': 'multipart/form-data' },
+ }).then(function (response) {
+ //handle success
+ console.log(response);
+ }).catch(function (response) {
+ //handle error
+ console.log(response);
+ });
+
event.preventDefault();
}