Loading and error states for blocks home route
This commit is contained in:
parent
47e078a502
commit
061388938c
12
apps/explorer/src/app/components/status-message/index.tsx
Normal file
12
apps/explorer/src/app/components/status-message/index.tsx
Normal 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>;
|
||||
};
|
@ -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>
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user