import React, { Suspense, useState } from 'react' import styled from 'styled-components' import { Fallback } from './Availability' import { mobile } from '../util/css' class ErrorBoundary extends React.Component { constructor(props) { super(props) this.state = { hasError: false } } static getDerivedStateFromError(error) { return { hasError: true, message: error.message } } componentDidCatch(error, info) {} render() { if (this.state.hasError) { return

{this.state.message}

} return this.props.children } } const BoundedSuspense = ({ children }) => ( }>{children} ) export function Card({ title, nameList, alternativeList = [], children }) { const [revealAlternatives, setRevealAlternatives] = useState(false) function onClick() { setRevealAlternatives(true) } return ( {title} <> {nameList.map((name) => ( {children(name)} ))} {revealAlternatives && alternativeList.map((name) => ( {children(name)} ))} {alternativeList.length > 0 && !revealAlternatives ? ( show alternatives ) : null} ) } const CardWrapper = styled.div` margin-bottom: 20px; padding: 40px; border-radius: 2px; ${mobile} { padding: 20px; box-shadow: 0px 2px 10px rgba(0, 0, 0, 0.1); border-radius: 0; } ` const CardTitle = styled.div` font-size: 0.8rem; font-weight: bold; margin-bottom: 15px; ` const ShowAlternativesButton = styled.div` display: inline-block; margin-top: 10px; padding: 5px 0; border: none; border-bottom: 1px dashed black; cursor: pointer; font-family: monospace; font-size: 1rem; `