diff --git a/src/App.js b/src/App.js index c173bb6..ab97d27 100644 --- a/src/App.js +++ b/src/App.js @@ -7,6 +7,7 @@ import TwitterCard from './components/TwitterCard' import NpmCard from './components/NpmCard' import JsOrgCard from './components/JsOrgCard' import HomebrewCard from './components/HomebrewCard' +import PypiCard from './components/PypiCard' import './App.css' const GlobalStyle = createGlobalStyle` @@ -47,6 +48,7 @@ export default function App() { + ) : null} diff --git a/src/components/Card.js b/src/components/Card.js index a677b77..cd8af0c 100644 --- a/src/components/Card.js +++ b/src/components/Card.js @@ -86,7 +86,7 @@ export function ExistenceAvailability({ const response = useFetch(target, null, { metadata: true }) if (response.status !== 404 && response.status !== 200) { - throw new Error(`Homebrew: ${response.statusText}`) + throw new Error(`${name}: ${response.status}`) } const availability = response.status === 404 @@ -106,8 +106,6 @@ export function ExistenceAvailability({ export function Alternatives({ nameList, children }) { const [show, setShow] = useState(false) - console.log(children) - function onClick() { setShow(true) } diff --git a/src/components/PypiCard.js b/src/components/PypiCard.js new file mode 100644 index 0000000..943964c --- /dev/null +++ b/src/components/PypiCard.js @@ -0,0 +1,17 @@ +import React from 'react' +import { Card, CardTitle, DedicatedAvailability } from './Card' +import { FaPython } from 'react-icons/fa' + +export default function PypiCard({ name }) { + return ( + + PyPI + } + /> + + ) +} diff --git a/src/services/pypi.js b/src/services/pypi.js new file mode 100644 index 0000000..3fb5666 --- /dev/null +++ b/src/services/pypi.js @@ -0,0 +1,23 @@ +const fetch = require('isomorphic-unfetch') + +async function getAvailability(name) { + const response = await fetch( + `https://pypi.org/pypi/${encodeURIComponent(name)}/json` + ) + return response.status !== 200 +} + +module.exports = async (req, res) => { + const name = req.query.name + + if (!name) { + return res.status(400).json({ error: 'no query given' }) + } + + try { + const availability = await getAvailability(name) + res.json({ availability }) + } catch (err) { + res.status(400).json({ error: err.message }) + } +}