2021-08-19 21:13:03 +00:00
|
|
|
import React from 'react'
|
|
|
|
import AniLink from 'gatsby-plugin-transition-link/AniLink'
|
|
|
|
import { ToastContainer, toast } from 'react-toastify'
|
2021-08-04 19:17:51 +00:00
|
|
|
|
2021-08-19 21:13:03 +00:00
|
|
|
import Seo from '../components/seo'
|
|
|
|
import axios from '../axios'
|
2021-08-04 19:17:51 +00:00
|
|
|
|
2021-08-19 21:13:03 +00:00
|
|
|
import '../css/url.sass'
|
|
|
|
import '../css/notifications.sass'
|
2021-08-04 19:17:51 +00:00
|
|
|
|
|
|
|
const AddURLPage = () => {
|
2021-08-19 21:13:03 +00:00
|
|
|
const [url, setURL] = React.useState('')
|
2021-08-04 19:17:51 +00:00
|
|
|
|
2021-08-07 11:32:58 +00:00
|
|
|
const handleKeypress = e => {
|
|
|
|
if (e.charCode === 13 || e.keyCode === 13) {
|
|
|
|
addURL()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-04 19:17:51 +00:00
|
|
|
const changeURLHandler = event => {
|
|
|
|
const value = event.target.value
|
|
|
|
setURL(value)
|
|
|
|
}
|
|
|
|
|
|
|
|
const addURL = async () => {
|
2021-08-19 21:13:03 +00:00
|
|
|
setURL('')
|
2021-08-04 19:17:51 +00:00
|
|
|
|
2021-08-19 21:13:03 +00:00
|
|
|
if (url === '') {
|
2021-08-27 17:45:51 +00:00
|
|
|
return toast.warn('Empty input')
|
2021-08-04 19:17:51 +00:00
|
|
|
}
|
|
|
|
|
2021-08-27 17:45:51 +00:00
|
|
|
toast.promise(
|
|
|
|
axios.post('', {
|
2021-08-04 19:17:51 +00:00
|
|
|
url: url,
|
2021-08-10 14:50:08 +00:00
|
|
|
cluster: 1
|
2021-08-27 17:45:51 +00:00
|
|
|
}),
|
|
|
|
{
|
|
|
|
pending: 'Sending request',
|
2021-08-27 17:52:56 +00:00
|
|
|
success: {
|
2021-08-30 19:53:33 +00:00
|
|
|
delay: 500,
|
2021-08-27 18:14:20 +00:00
|
|
|
render({ data: { data } }) {
|
2021-09-17 19:38:34 +00:00
|
|
|
return data.message
|
2021-08-27 17:52:56 +00:00
|
|
|
}
|
2021-08-27 17:45:51 +00:00
|
|
|
},
|
2021-08-27 17:52:56 +00:00
|
|
|
error: {
|
2021-08-30 19:53:33 +00:00
|
|
|
delay: 500,
|
2021-08-27 17:52:56 +00:00
|
|
|
render(err) {
|
2021-08-27 18:05:12 +00:00
|
|
|
if (err.data.response && err.data.response.data.message) {
|
2021-09-17 19:38:34 +00:00
|
|
|
return err.data.response.data.message
|
2021-08-27 17:52:56 +00:00
|
|
|
} else {
|
2021-09-17 19:38:34 +00:00
|
|
|
return err.data.toString()
|
2021-08-27 17:52:56 +00:00
|
|
|
}
|
2021-08-27 17:45:51 +00:00
|
|
|
}
|
|
|
|
}
|
2021-08-04 19:17:51 +00:00
|
|
|
}
|
2021-08-27 17:45:51 +00:00
|
|
|
)
|
2021-08-04 19:17:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Seo
|
|
|
|
title="Add URL"
|
|
|
|
/>
|
|
|
|
|
2021-08-30 19:53:33 +00:00
|
|
|
<ToastContainer
|
2021-08-27 17:45:51 +00:00
|
|
|
theme="dark"
|
|
|
|
/>
|
2021-08-04 19:17:51 +00:00
|
|
|
|
|
|
|
<div className="field">
|
|
|
|
<input
|
|
|
|
type="url"
|
|
|
|
name="url"
|
|
|
|
inputMode="url"
|
|
|
|
className="input"
|
|
|
|
placeholder="URL"
|
|
|
|
value={url}
|
2021-08-07 11:32:58 +00:00
|
|
|
onChange={changeURLHandler}
|
|
|
|
onKeyPress={handleKeypress} />
|
2021-08-04 19:17:51 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<button
|
|
|
|
className="yellow-button"
|
|
|
|
onClick={() => addURL()}
|
|
|
|
>Add URL</button>
|
|
|
|
|
|
|
|
<br />
|
|
|
|
|
2021-08-06 18:17:07 +00:00
|
|
|
<AniLink cover to="/">
|
2021-08-15 20:45:38 +00:00
|
|
|
<button className="blue-button">Go to home page</button>
|
2021-08-06 18:17:07 +00:00
|
|
|
</AniLink>
|
2021-08-04 19:17:51 +00:00
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default AddURLPage
|