Loading and error states for blocks home route

This commit is contained in:
sam-keen 2022-03-14 17:06:58 +00:00
parent 47e078a502
commit 061388938c
2 changed files with 22 additions and 3 deletions

View File

@ -0,0 +1,12 @@
import classnames from 'classnames';
import React from 'react';
interface StatusMessageProps {
children: React.ReactNode;
className?: string;
}
export const StatusMessage = ({ children, className }: StatusMessageProps) => {
const classes = classnames('font-alpha', 'text-h4', 'mb-28', className);
return <h3 className={classes}>{children}</h3>;
};

View File

@ -2,12 +2,13 @@ import { DATA_SOURCES } from '../../../config';
import useFetch from '../../../hooks/use-fetch';
import { TendermintBlockchainResponse } from '../tendermint-blockchain-response';
import { RouteTitle } from '../../../components/route-title';
import { StatusMessage } from '../../../components/status-message';
import { BlocksData, BlocksRefetch } from '../../../components/blocks';
import { JumpToBlock } from '../../../components/jump-to-block';
const Blocks = () => {
const {
state: { data },
state: { data, error, loading },
refetch,
} = useFetch<TendermintBlockchainResponse>(
`${DATA_SOURCES.tendermintUrl}/blockchain`
@ -16,8 +17,14 @@ const Blocks = () => {
return (
<section>
<RouteTitle>Blocks</RouteTitle>
{loading && <StatusMessage>Loading...</StatusMessage>}
{error && <StatusMessage>Error: {error}</StatusMessage>}
{data && (
<>
<BlocksRefetch refetch={refetch} />
<BlocksData data={data} className="mb-28" />
</>
)}
<JumpToBlock />
</section>
);