import React, { Component } from 'react' import { Input, Segment, Form, Header, Card, Button, Select, Icon } from 'semantic-ui-react' import DatePicker from 'react-datepicker'; import moment from 'moment'; import MediaQuery from 'react-responsive'; import 'react-datepicker/dist/react-datepicker.css'; import util from '../util/util' import CustomCard from '../Card/Card' import './Home.css' export default class HomeComponent extends Component { handleURLChange = (e, { value }) => this.url = value handlePasswordChange = (e, { value }) => this.password = value handleCustomExpirationChange = expire => this.setState({ expiration: expire }) handleCustomIDChange = (e, { value }) => { this.customID = value util.lookupEntry(value, () => this.setState({ showCustomIDError: true }), () => this.setState({ showCustomIDError: false })) } onSettingsChange = (e, { value }) => this.setState({ usedSettings: value }) state = { links: [], usedSettings: [], showCustomIDError: false, expiration: null } componentDidMount() { this.urlInput.focus() } handleURLSubmit = () => { if (!this.state.showCustomIDError) { util.createEntry({ URL: this.url, ID: this.customID, Expiration: this.state.usedSettings.includes("expire") && this.state.expiration ? this.state.expiration.toISOString() : undefined, Password: this.state.usedSettings.includes("protected") && this.password ? this.password : undefined }, r => this.setState({ links: [...this.state.links, { shortenedURL: r.URL, originalURL: this.url, expiration: this.state.usedSettings.includes("expire") && this.state.expiration ? this.state.expiration.toISOString() : undefined, deletionURL: r.DeletionURL }] })) } } render() { const options = [ { text: 'Custom URL', value: 'custom' }, { text: 'Expiration', value: 'expire' }, { text: 'Password', value: 'protected' } ] const { links, usedSettings, showCustomIDError, expiration } = this.state return (
Simplify your links
this.urlInput = input} onChange={this.handleURLChange} placeholder='Paste a link to shorten it' action> {usedSettings.includes("custom") && } {usedSettings.includes("expire") && } minDate={moment()} /> } {usedSettings.includes("protected") && }
{links.map((link, i) => )}
) } }