@ -10,21 +10,31 @@ import CustomCard from '../Card/Card'
import './Home.css'
import './Home.css'
export default class HomeComponent extends Component {
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
}
}
handleURLChange = ( e , { value } ) => this . url = value
handleURLChange = ( e , { value } ) => this . url = value
handlePasswordChange = ( e , { value } ) => this . password = value
handlePasswordChange = ( e , { value } ) => this . password = value
handleCustomExpirationChange = expire => this . setState ( { expiration : expire } )
handleCustomExpirationChange = expire => this . setState ( { expiration : expire } )
handleCustomIDChange = ( e , { value } ) => {
handleCustomIDChange = ( e , { value } ) => {
this . customID = value
this . setState ( { customID : value } )
util . lookupEntry ( value , ( ) => this . setState ( { showCustomIDError : true } ) , ( ) => this . setState ( { showCustomIDError : false } ) )
util . lookupEntry ( value , ( ) => this . setState ( { showCustomIDError : true } ) , ( ) => this . setState ( { showCustomIDError : false } ) )
}
}
onSettingsChange = ( e , { value } ) => this . setState ( { usedSettings : value } )
onSettingsChange = ( e , { value } ) => {
this . setState ( { usedSettings : value } )
state = {
links : [ ] ,
usedSettings : [ ] ,
showCustomIDError : false ,
expiration : null
}
}
componentDidMount ( ) {
componentDidMount ( ) {
this . urlInput . focus ( )
this . urlInput . focus ( )
}
}
@ -32,7 +42,7 @@ export default class HomeComponent extends Component {
if ( ! this . state . showCustomIDError ) {
if ( ! this . state . showCustomIDError ) {
util . createEntry ( {
util . createEntry ( {
URL : this . url ,
URL : this . url ,
ID : this . customID ,
ID : this . state . customID ,
Expiration : this . state . usedSettings . includes ( "expire" ) && this . state . expiration ? this . state . expiration . toISOString ( ) : undefined ,
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
Password : this . state . usedSettings . includes ( "protected" ) && this . password ? this . password : undefined
} , r => this . setState ( {
} , r => this . setState ( {
@ -56,13 +66,18 @@ export default class HomeComponent extends Component {
return (
return (
< div >
< div >
< Segment raised >
< Segment raised >
< Header size = 'huge' > Simplify your links < / H e a d e r >
{ this . urlParams . get ( "customUrl" ) && (
< Header size = 'medium' > I don ' t have a link named < em > "{this.urlParams.get(" customUrl ")}" < / e m > i n m y d a t a b a s e , w o u l d
you like to create one ? < / H e a d e r >
) ||
< Header size = 'huge' > Simplify your links < / H e a d e r >
}
< Form onSubmit = { this . handleURLSubmit } autoComplete = "off" >
< Form onSubmit = { this . handleURLSubmit } autoComplete = "off" >
< Form . Field >
< Form . Field >
< Input required size = 'large' type = 'url' ref = { input => this . urlInput = input } onChange = { this . handleURLChange } placeholder = 'Paste a link to shorten it' action >
< Input required size = 'large' type = 'url' ref = { input => this . urlInput = input } onChange = { this . handleURLChange } placeholder = 'Paste a link to shorten it' action >
< input / >
< input / >
< MediaQuery query = "(min-width: 768px)" >
< MediaQuery query = "(min-width: 768px)" >
< Select options = { options } placeholder = 'Settings' onChange = { this . onSettingsChange } multiple / >
< Select options = { options } placeholder = 'Settings' value = { this . state . usedSettings } onChange = { this . onSettingsChange } multiple / >
< / M e d i a Q u e r y >
< / M e d i a Q u e r y >
< Button type = 'submit' > Shorten < Icon name = "arrow right" / > < / B u t t o n >
< Button type = 'submit' > Shorten < Icon name = "arrow right" / > < / B u t t o n >
< / I n p u t >
< / I n p u t >
@ -74,7 +89,7 @@ export default class HomeComponent extends Component {
< / M e d i a Q u e r y >
< / M e d i a Q u e r y >
< Form . Group style = { { marginBottom : "1rem" } } >
< Form . Group style = { { marginBottom : "1rem" } } >
{ usedSettings . includes ( "custom" ) && < Form . Field error = { showCustomIDError } width = { 16 } >
{ usedSettings . includes ( "custom" ) && < Form . Field error = { showCustomIDError } width = { 16 } >
< Input label = { window . location . origin + "/" } onChange = { this . handleCustomIDChange } placeholder = 'my-shortened-url' / >
< Input label = { window . location . origin + "/" } onChange = { this . handleCustomIDChange } placeholder = 'my-shortened-url' value = { this . state . customID } / >
< / F o r m . F i e l d > }
< / F o r m . F i e l d > }
< / F o r m . G r o u p >
< / F o r m . G r o u p >
< Form . Group widths = "equal" >
< Form . Group widths = "equal" >
@ -100,4 +115,4 @@ export default class HomeComponent extends Component {
< / d i v >
< / d i v >
)
)
}
}
}
}