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 { constructor(props) { super(props); this.urlParams = new URLSearchParams(window.location.search); this.state = { links: [], usedSettings: this.urlParams.get('customUrl') ? ['custom'] : [], customID: this.urlParams.get('customUrl') ? this.urlParams.get('customUrl') : '', showCustomIDError: false, expiration: null, displayURL: window.location.origin } } handleURLChange = (e, { value }) => this.url = value handlePasswordChange = (e, { value }) => this.password = value handleCustomExpirationChange = expire => this.setState({ expiration: expire }) handleCustomIDChange = (e, { value }) => { this.setState({ customID: value }) util.lookupEntry(value, () => this.setState({ showCustomIDError: true }), () => this.setState({ showCustomIDError: false })) } onSettingsChange = (e, { value }) => { this.setState({ usedSettings: value }) } componentDidMount() { this.urlInput.focus() util.getDisplayURL() .then(displayURL => this.setState({ displayURL })); } handleURLSubmit = () => { if (!this.state.showCustomIDError) { util.createEntry({ URL: this.url, ID: this.state.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: this.state.displayURL + "/" + this.state.customID, 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 (
{this.urlParams.get("customUrl") ? (
I don't have a link named "{this.urlParams.get("customUrl")}" in my database, would you like to create one?
) :
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) => )}
) } }