|
|
@ -1,10 +1,15 @@ |
|
|
import React, { Component } from 'react' |
|
|
import React, { Component } from 'react' |
|
|
import { Input, Segment, Form, Header, Card, Button, Select, Icon } from 'semantic-ui-react' |
|
|
import { Input, Segment, Form, Header, Card, Button, Select, Icon } from 'semantic-ui-react' |
|
|
|
|
|
import DatePicker from 'react-datepicker'; |
|
|
|
|
|
import moment from 'moment'; |
|
|
|
|
|
import 'react-datepicker/dist/react-datepicker.css'; |
|
|
|
|
|
|
|
|
import CustomCard from '../Card/Card' |
|
|
import CustomCard from '../Card/Card' |
|
|
|
|
|
import './Home.css' |
|
|
|
|
|
|
|
|
export default class HomeComponent extends Component { |
|
|
export default class HomeComponent extends Component { |
|
|
handleURLChange = (e, { value }) => this.url = value |
|
|
handleURLChange = (e, { value }) => this.url = value |
|
|
|
|
|
handleCustomExpirationChange = expire => this.setState({ expiration: expire }) |
|
|
handleCustomIDChange = (e, { value }) => { |
|
|
handleCustomIDChange = (e, { value }) => { |
|
|
this.customID = value |
|
|
this.customID = value |
|
|
fetch("/api/v1/protected/lookup", { |
|
|
fetch("/api/v1/protected/lookup", { |
|
|
@ -31,7 +36,8 @@ export default class HomeComponent extends Component { |
|
|
{ text: 'Expiration', value: 'expire' } |
|
|
{ text: 'Expiration', value: 'expire' } |
|
|
], |
|
|
], |
|
|
setOptions: [], |
|
|
setOptions: [], |
|
|
showCustomIDError: false |
|
|
showCustomIDError: false, |
|
|
|
|
|
expiration: moment() |
|
|
} |
|
|
} |
|
|
componentDidMount() { |
|
|
componentDidMount() { |
|
|
this.urlInput.focus() |
|
|
this.urlInput.focus() |
|
|
@ -42,7 +48,8 @@ export default class HomeComponent extends Component { |
|
|
method: 'POST', |
|
|
method: 'POST', |
|
|
body: JSON.stringify({ |
|
|
body: JSON.stringify({ |
|
|
URL: this.url, |
|
|
URL: this.url, |
|
|
ID: this.customID |
|
|
ID: this.customID, |
|
|
|
|
|
Expiration: this.state.setOptions.indexOf("expire") > -1 ? this.state.expiration.toISOString() : undefined |
|
|
}), |
|
|
}), |
|
|
headers: { |
|
|
headers: { |
|
|
'Authorization': window.localStorage.getItem('token'), |
|
|
'Authorization': window.localStorage.getItem('token'), |
|
|
@ -52,14 +59,15 @@ export default class HomeComponent extends Component { |
|
|
.then(r => this.setState({ |
|
|
.then(r => this.setState({ |
|
|
links: [...this.state.links, [ |
|
|
links: [...this.state.links, [ |
|
|
r.URL, |
|
|
r.URL, |
|
|
this.url |
|
|
this.url, |
|
|
|
|
|
this.state.setOptions.indexOf("expire") > -1 ? this.state.expiration : undefined |
|
|
]] |
|
|
]] |
|
|
})) |
|
|
})) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
render() { |
|
|
render() { |
|
|
const { links, options, setOptions, showCustomIDError } = this.state |
|
|
const { links, options, setOptions, showCustomIDError, expiration } = this.state |
|
|
return ( |
|
|
return ( |
|
|
<div> |
|
|
<div> |
|
|
<Segment raised> |
|
|
<Segment raised> |
|
|
@ -73,15 +81,20 @@ export default class HomeComponent extends Component { |
|
|
</Input> |
|
|
</Input> |
|
|
</Form.Field> |
|
|
</Form.Field> |
|
|
<Form.Group widths='equal'> |
|
|
<Form.Group widths='equal'> |
|
|
{setOptions.indexOf("custom") > -1 && <Form.Field error={showCustomIDError}><Input label={window.location.origin + "/"} onChange={this.handleCustomIDChange} placeholder='my-shortened-url' /> |
|
|
{setOptions.indexOf("custom") > -1 && <Form.Field error={showCustomIDError}> |
|
|
</Form.Field> |
|
|
<Input label={window.location.origin + "/"} onChange={this.handleCustomIDChange} placeholder='my-shortened-url' /> |
|
|
} |
|
|
</Form.Field>} |
|
|
|
|
|
{setOptions.indexOf("expire") > -1 && <Form.Field> |
|
|
|
|
|
<DatePicker showTimeSelect |
|
|
|
|
|
timeFormat="HH:mm" |
|
|
|
|
|
timeIntervals={15} |
|
|
|
|
|
dateFormat="LLL" onChange={this.handleCustomExpirationChange} selected={expiration} customInput={<Input label="Expiration" />} minDate={moment()} /> |
|
|
|
|
|
</Form.Field>} |
|
|
</Form.Group> |
|
|
</Form.Group> |
|
|
|
|
|
|
|
|
</Form> |
|
|
</Form> |
|
|
</Segment> |
|
|
</Segment> |
|
|
<Card.Group itemsPerRow="2"> |
|
|
<Card.Group itemsPerRow="2"> |
|
|
{links.map((link, i) => <CustomCard key={i} header={new URL(link[1]).hostname} metaHeader={link[1]} description={link[0]} />)} |
|
|
{links.map((link, i) => <CustomCard key={i} header={new URL(link[1]).hostname} expireDate={link[2]} metaHeader={link[1]} description={link[0]} />)} |
|
|
</Card.Group> |
|
|
</Card.Group> |
|
|
</div > |
|
|
</div > |
|
|
) |
|
|
) |
|
|
|