diff options
| author | jackyzha0 <[email protected]> | 2020-05-10 16:33:00 -0700 |
|---|---|---|
| committer | jackyzha0 <[email protected]> | 2020-05-10 16:33:00 -0700 |
| commit | a635513d66fd4d2c605a0e64b4fa94828c64610e (patch) | |
| tree | 465b89c4028572ad9a213b746f50823fb28954a8 /frontend/src | |
| parent | Merge pull request #11 from jackyzha0/pass_and_expiry (diff) | |
| download | ctrl-v-a635513d66fd4d2c605a0e64b4fa94828c64610e.tar.xz ctrl-v-a635513d66fd4d2c605a0e64b4fa94828c64610e.zip | |
linked backend and frontend
Diffstat (limited to 'frontend/src')
| -rw-r--r-- | frontend/src/components/Inputs.js | 1 | ||||
| -rw-r--r-- | frontend/src/components/PasteArea.js | 54 |
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(); } |