refactor: add loading and empty state in monitor list

This commit is contained in:
moonrailgun 2023-11-02 00:19:00 +08:00
parent 39b4ff9ec5
commit 4529dbca75

View File

@ -5,12 +5,14 @@ import { AppRouterOutput, trpc } from '../../api/trpc';
import { useCurrentWorkspaceId } from '../../store/user';
import { NoWorkspaceTip } from '../NoWorkspaceTip';
import { MonitorHealthBar } from './MonitorHealthBar';
import { Loading } from '../Loading';
import { Empty } from 'antd';
type MonitorType = AppRouterOutput['monitor']['all'][number];
export const MonitorList: React.FC = React.memo(() => {
const workspaceId = useCurrentWorkspaceId();
const { data: monitors = [] } = trpc.monitor.all.useQuery({
const { data: monitors = [], isLoading } = trpc.monitor.all.useQuery({
workspaceId,
});
const initMonitorId = useMemo(() => {
@ -35,8 +37,14 @@ export const MonitorList: React.FC = React.memo(() => {
return <NoWorkspaceTip />;
}
if (isLoading) {
return <Loading />;
}
return (
<div className="p-2">
{monitors.length === 0 && <Empty description="Here is no monitor yet." />}
{monitors.map((monitor) => (
<MonitorListItem
key={monitor.id}