diff --git a/app/src/components/flights/Flights.tsx b/app/src/components/flights/Flights.tsx index 2ceee39..b4561b2 100644 --- a/app/src/components/flights/Flights.tsx +++ b/app/src/components/flights/Flights.tsx @@ -1,12 +1,12 @@ -import { Box, Container } from "@noahspan/noahspan-components"; +import { Box, Container, Grid, Spinner } from "@noahspan/noahspan-components"; import LogbookCard from "../logbookCard/LogbookCard"; import { useEffect, useState } from "react"; import { useLogs } from "../../hooks/logs/UseLogs"; import { ILogbookEntry } from "../logbook/ILogbookEntry"; const Flights = () => { - const [flights, setFlights] = useState([]) - const { logs } = useLogs(); + const [flights, setFlights] = useState([]); + const { logs, isLoading } = useLogs(); useEffect(() => { const flights: ILogbookEntry[] | undefined = logs?.filter((log: ILogbookEntry) => { @@ -23,7 +23,23 @@ const Flights = () => { return ( - + + {isLoading && + <> + + + + + Loading... + + + } + {!isLoading && + + + + } + ) diff --git a/app/src/hooks/logs/UseLogs.tsx b/app/src/hooks/logs/UseLogs.tsx index 65ebc84..80515d1 100644 --- a/app/src/hooks/logs/UseLogs.tsx +++ b/app/src/hooks/logs/UseLogs.tsx @@ -7,6 +7,7 @@ import { ILogbookEntry } from "../../components/logbook/ILogbookEntry"; export const useLogs = () => { const [logs, setLogs] = useState(); + const [isLoading, setIsLoading] = useState(false); const httpClient: AxiosInstance = useHttpClient(); const { getAccessToken } = useAccessToken(); const isAuthenticated = useIsAuthenticated(); @@ -14,6 +15,8 @@ export const useLogs = () => { useEffect(() => { const getLogs = async () => { try { + setIsLoading(true); + const config = isAuthenticated ? { headers: { Authorization: await getAccessToken() } } : {}; @@ -28,6 +31,8 @@ export const useLogs = () => { setLogs(logs) } catch (error) { return error; + } finally { + setIsLoading(false); } } @@ -35,6 +40,7 @@ export const useLogs = () => { }, []) return { - logs + logs, + isLoading } } \ No newline at end of file