Skip to content

Commit

Permalink
feat: Added spinner when loading table
Browse files Browse the repository at this point in the history
  • Loading branch information
miguel-merlin committed Mar 28, 2024
1 parent 3ba975e commit cad423e
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/pages/HomePage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Container, HStack, Text } from '@chakra-ui/react'
import { Center, Container, HStack, Spinner, Text } from '@chakra-ui/react'
import TableDashboard from '../components/TableDashboard'
import Sidebar from '../components/Sidebar'
import { getAllUsers } from '../api/lib/users'
Expand All @@ -8,21 +8,25 @@ import React, { useEffect, useState } from 'react'
function HomePage (): JSX.Element {
const [members, setMembers] = React.useState<User[]>([])
const [error, setError] = useState<string | null>(null)
const [isLoading, setIsLoading] = useState<boolean>(true)

useEffect(() => {
void getAllUsers().then((response) => {
setMembers(response.data as User[])
setIsLoading(false)
}).catch((error) => {
console.error(error)
setError('Failed to load Blueprint members. Please try again later.')
setIsLoading(false)
})
}, [])

return (
<HStack height="100vh" spacing="0">
<Sidebar />
<Container>
{error ? (<Text color="red.500">{error}</Text>) : (<TableDashboard members={members} />)}
{error && <Text color="red.500">{error}</Text>}
{isLoading ? <Center> <Spinner size="xl"/> </Center> : <TableDashboard members={members} />}
</Container>
</HStack>
)
Expand Down

0 comments on commit cad423e

Please sign in to comment.