2019-07-31 13:11:00 +09:00
|
|
|
import React from 'react'
|
|
|
|
import styled from 'styled-components'
|
|
|
|
import useFetch from 'fetch-suspense'
|
|
|
|
import { BarLoader } from 'react-spinners'
|
|
|
|
|
2019-07-31 18:54:28 +09:00
|
|
|
import { ExternalLink } from './Links'
|
|
|
|
|
2019-07-31 13:11:00 +09:00
|
|
|
function AvailabilityCell({
|
|
|
|
name,
|
|
|
|
availability,
|
2019-07-31 13:40:16 +09:00
|
|
|
link,
|
2019-07-31 13:11:00 +09:00
|
|
|
prefix = '',
|
|
|
|
suffix = '',
|
|
|
|
icon,
|
|
|
|
}) {
|
|
|
|
return (
|
|
|
|
<ItemContainer>
|
|
|
|
{icon}
|
|
|
|
<Item>
|
2019-07-31 18:54:28 +09:00
|
|
|
<ExternalLink href={link}>
|
2019-07-31 13:11:00 +09:00
|
|
|
{prefix}
|
|
|
|
{availability ? (
|
|
|
|
<span style={{ color: 'green' }}>{name}</span>
|
|
|
|
) : (
|
|
|
|
<span style={{ color: 'red' }}>{name}</span>
|
|
|
|
)}
|
|
|
|
{suffix}
|
2019-07-31 18:54:28 +09:00
|
|
|
</ExternalLink>
|
2019-07-31 13:11:00 +09:00
|
|
|
</Item>
|
|
|
|
</ItemContainer>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export const Fallback = () => (
|
|
|
|
<ItemContainer>
|
|
|
|
<BarLoader />
|
|
|
|
</ItemContainer>
|
|
|
|
)
|
|
|
|
|
|
|
|
export function DedicatedAvailability({
|
|
|
|
name,
|
2019-07-31 13:40:16 +09:00
|
|
|
service,
|
|
|
|
link,
|
2019-07-31 13:11:00 +09:00
|
|
|
prefix = '',
|
|
|
|
suffix = '',
|
|
|
|
icon,
|
|
|
|
}) {
|
2019-07-31 13:40:16 +09:00
|
|
|
const response = useFetch(`/availability/${service}/${name}`)
|
2019-07-31 13:11:00 +09:00
|
|
|
if (response.error) {
|
2019-07-31 13:40:16 +09:00
|
|
|
throw new Error(`${service}: ${response.error}`)
|
2019-07-31 13:11:00 +09:00
|
|
|
}
|
|
|
|
return (
|
|
|
|
<AvailabilityCell
|
|
|
|
availability={response.availability}
|
|
|
|
name={name}
|
2019-07-31 13:40:16 +09:00
|
|
|
link={link}
|
2019-07-31 13:11:00 +09:00
|
|
|
prefix={prefix}
|
|
|
|
suffix={suffix}
|
|
|
|
icon={icon}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function ExistentialAvailability({
|
|
|
|
name,
|
|
|
|
target,
|
2019-07-31 13:57:37 +09:00
|
|
|
link,
|
2019-07-31 13:11:00 +09:00
|
|
|
prefix = '',
|
|
|
|
suffix = '',
|
|
|
|
icon,
|
|
|
|
}) {
|
|
|
|
const response = useFetch(target, null, { metadata: true })
|
|
|
|
if (response.status !== 404 && response.status !== 200) {
|
|
|
|
throw new Error(`${name}: ${response.status}`)
|
|
|
|
}
|
|
|
|
const availability = response.status === 404
|
|
|
|
return (
|
|
|
|
<AvailabilityCell
|
|
|
|
name={name}
|
|
|
|
availability={availability}
|
2019-07-31 13:57:37 +09:00
|
|
|
link={link}
|
2019-07-31 13:11:00 +09:00
|
|
|
prefix={prefix}
|
|
|
|
suffix={suffix}
|
|
|
|
icon={icon}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
const ItemContainer = styled.div`
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
align-items: flex-start;
|
|
|
|
margin-top: 8px;
|
|
|
|
word-break: break-all;
|
|
|
|
`
|
|
|
|
|
|
|
|
const Item = styled.span`
|
|
|
|
margin-left: 6px;
|
|
|
|
font-family: monospace;
|
|
|
|
font-size: 1rem;
|
|
|
|
|
|
|
|
a {
|
|
|
|
text-decoration: none;
|
|
|
|
color: inherit;
|
|
|
|
}
|
|
|
|
`
|