gatsby-pingbot/src/pages/add.js

82 lines
1.6 KiB
JavaScript
Raw Normal View History

2021-08-04 19:17:51 +00:00
import React from "react"
2021-08-06 18:17:07 +00:00
import AniLink from "gatsby-plugin-transition-link/AniLink"
2021-08-04 19:17:51 +00:00
import { NotificationManager, NotificationContainer } from 'react-notifications'
import 'react-notifications/lib/notifications.css'
import Seo from "../components/seo"
import axios from "../axios"
2021-08-07 10:33:58 +00:00
import "../css/base.sass"
import "../css/url.sass"
2021-08-04 19:17:51 +00:00
const AddURLPage = () => {
const [url, setURL] = React.useState('')
const changeURLHandler = event => {
const value = event.target.value
setURL(value)
}
const addURL = async () => {
setURL('')
if (url === '') {
return NotificationManager.error('Empty')
}
try {
const res = await axios.post('/url', {
url: url,
})
const data = res.data
NotificationManager.success(data.url, 'Added')
} catch (err) {
let e = ''
if (err.response && err.response.data.message) {
e = err.response.data.message
} else {
e = err.toString()
}
NotificationManager.error(e)
}
}
return (
<>
<Seo
title="Add URL"
/>
<NotificationContainer />
<div className="field">
<input
type="url"
name="url"
inputMode="url"
className="input"
placeholder="URL"
value={url}
onChange={changeURLHandler} />
</div>
<button
className="yellow-button"
onClick={() => addURL()}
>Add URL</button>
<br />
2021-08-06 18:17:07 +00:00
<AniLink cover to="/">
2021-08-04 19:17:51 +00:00
<button className="blue-buton">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