Notice.tsx53 lines, 1.5 KB
| 1 | import type { ReactNode } from 'react' |
| 2 | import { Link } from 'react-router' |
| 3 | import { ApiError } from '../../lib/api' |
| 4 | |
| 5 | // Notice is what a screen says instead of a list: empty, failed, gone. |
| 6 | export function Notice(props: { title: string; children?: ReactNode }) { |
| 7 | return ( |
| 8 | <div className="px-6 py-16 text-center"> |
| 9 | <p className="font-medium">{props.title}</p> |
| 10 | <div className="mt-1 text-sm text-mute">{props.children}</div> |
| 11 | </div> |
| 12 | ) |
| 13 | } |
| 14 | |
| 15 | export function Failed(props: { error: Error; retry: () => void }) { |
| 16 | const offline = !(props.error instanceof ApiError) |
| 17 | return ( |
| 18 | <Notice title={offline ? "Can't reach Murmur" : "That didn't load"}> |
| 19 | <p className="first-letter:uppercase"> |
| 20 | {offline ? 'Check your connection.' : props.error.message} |
| 21 | </p> |
| 22 | <button className="btn-quiet mt-4" onClick={props.retry}> |
| 23 | Try again |
| 24 | </button> |
| 25 | </Notice> |
| 26 | ) |
| 27 | } |
| 28 | |
| 29 | export function NotFound() { |
| 30 | return ( |
| 31 | <Notice title="Nothing here"> |
| 32 | <Link to="/" className="text-accent-ink underline"> |
| 33 | Back home |
| 34 | </Link> |
| 35 | </Notice> |
| 36 | ) |
| 37 | } |
| 38 | |
| 39 | export function Skeletons() { |
| 40 | return ( |
| 41 | <ul aria-label="Loading" className="motion-safe:animate-pulse"> |
| 42 | {[0, 1, 2, 3].map((i) => ( |
| 43 | <li key={i} className="flex gap-3 border-b border-line p-4"> |
| 44 | <div className="size-9 rounded-full bg-hover" /> |
| 45 | <div className="flex-1 space-y-2 py-1"> |
| 46 | <div className="h-3 w-1/4 rounded bg-hover" /> |
| 47 | <div className="h-3 w-3/4 rounded bg-hover" /> |
| 48 | </div> |
| 49 | </li> |
| 50 | ))} |
| 51 | </ul> |
| 52 | ) |
| 53 | } |