Improve loading displays

This commit is contained in:
april 2024-01-03 17:03:42 -06:00
parent c857a18619
commit 2dd6edd156
2 changed files with 45 additions and 24 deletions

View File

@ -1,5 +1,5 @@
import { client } from "@/util/api"; import { client } from "@/util/api";
import { List, Stack, Text } from "@mantine/core"; import { Center, Container, List, Loader, Stack, Text } from "@mantine/core";
import { useParams } from "@remix-run/react"; import { useParams } from "@remix-run/react";
import { useQuery } from "@tanstack/react-query"; import { useQuery } from "@tanstack/react-query";
@ -13,27 +13,31 @@ export default function Flight() {
}); });
return ( return (
<Stack h="calc(100vh - 95px)" m="0" p="0"> <Container py="xl">
{flight.isError ? ( <Stack h="calc(100vh - 95px)" m="0" p="0">
<Text c="red">Error fetching flight</Text> {flight.isError ? (
) : flight.isPending ? ( <Text c="red">Error fetching flight</Text>
<Text>Loading...</Text> ) : flight.isPending ? (
) : ( <Center h="100%">
<List> <Loader />
{Object.entries(flight.data).map(([key, value]) => </Center>
value && value.length !== 0 ? ( ) : (
<List.Item key={key}> <List>
<Text span> {Object.entries(flight.data).map(([key, value]) =>
<Text span fw={700}> value && value.length !== 0 ? (
{key} <List.Item key={key}>
<Text span>
<Text span fw={700}>
{key}
</Text>
: <Text span>{value}</Text>
</Text> </Text>
: <Text span>{value}</Text> </List.Item>
</Text> ) : null
</List.Item> )}
) : null </List>
)} )}
</List> </Stack>
)} </Container>
</Stack>
); );
} }

View File

@ -1,6 +1,15 @@
import { client } from "@/util/api"; import { client } from "@/util/api";
import { FlightConciseSchema } from "@/util/types"; import { FlightConciseSchema } from "@/util/types";
import { NavLink, Text, Button, ScrollArea, Stack } from "@mantine/core"; import {
NavLink,
Text,
Button,
ScrollArea,
Stack,
Loader,
Center,
Container,
} from "@mantine/core";
import { Link, useLocation, useNavigate } from "@remix-run/react"; import { Link, useLocation, useNavigate } from "@remix-run/react";
import { IconPlus } from "@tabler/icons-react"; import { IconPlus } from "@tabler/icons-react";
import { useQuery } from "@tanstack/react-query"; import { useQuery } from "@tanstack/react-query";
@ -26,7 +35,7 @@ export function FlightsList() {
> >
Add Add
</Button> </Button>
<ScrollArea> <ScrollArea h="calc(100vh - 95px - 50px)">
{flights.data ? ( {flights.data ? (
flights.data.map((flight: FlightConciseSchema, index: number) => ( flights.data.map((flight: FlightConciseSchema, index: number) => (
<NavLink <NavLink
@ -37,6 +46,10 @@ export function FlightsList() {
active={page === flight.id} active={page === flight.id}
/> />
)) ))
) : flights.isLoading ? (
<Center h="calc(100vh - 95px - 50px)">
<Loader />
</Center>
) : ( ) : (
<Text p="sm">No Flights</Text> <Text p="sm">No Flights</Text>
)} )}
@ -69,6 +82,10 @@ export function MobileFlightsList() {
active={page === flight.id} active={page === flight.id}
/> />
)) ))
) : flights.isLoading ? (
<Center h="calc(100vh - 95px - 70px)">
<Loader />
</Center>
) : ( ) : (
<Text p="sm">No Flights</Text> <Text p="sm">No Flights</Text>
)} )}