2024-02-10 20:33:24 -05:00
|
|
|
import { useUser } from "@auth0/nextjs-auth0/client";
|
|
|
|
import Layout from "../components/layout";
|
2024-02-13 01:47:26 -05:00
|
|
|
import { Typography, Box, CircularProgress } from '@mui/material';
|
2024-02-10 20:33:24 -05:00
|
|
|
import Artist from "../components/artist";
|
2024-02-11 02:20:39 -05:00
|
|
|
import { useEffect, useState } from "react";
|
2024-02-10 20:33:24 -05:00
|
|
|
|
|
|
|
const Home = () => {
|
2024-02-11 02:20:39 -05:00
|
|
|
const [sellersData, setSellersData] = useState([]);
|
2024-02-11 20:44:27 -05:00
|
|
|
const [loading, setLoading] = useState(true); // State for loading indicator
|
2024-02-11 02:20:39 -05:00
|
|
|
useEffect(() => {
|
|
|
|
const getData = async () => {
|
2024-02-13 01:47:26 -05:00
|
|
|
const response = await fetch('/api/discovery/sellers');
|
|
|
|
const data = await response.json();
|
2024-02-11 02:20:39 -05:00
|
|
|
setSellersData(data);
|
2024-02-11 20:44:27 -05:00
|
|
|
setLoading(false);
|
2024-02-10 20:33:24 -05:00
|
|
|
}
|
2024-02-11 02:20:39 -05:00
|
|
|
getData();
|
|
|
|
}, []);
|
|
|
|
const { user, isLoading } = useUser();
|
2024-02-10 20:33:24 -05:00
|
|
|
return (
|
|
|
|
<Layout user={user} loading={isLoading}>
|
2024-02-11 20:44:27 -05:00
|
|
|
{loading ? ( // Render loading indicator if loading is true
|
|
|
|
<Box sx={{textAlign:"center", paddingTop:20}}>
|
|
|
|
<Typography variant="h4" sx={{textAlign:"center"}}>
|
|
|
|
Loading...
|
|
|
|
</Typography>
|
|
|
|
<CircularProgress sx={{paddingTop:5}} />
|
|
|
|
</Box>
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
{sellersData.map((item) => (
|
2024-02-11 21:19:40 -05:00
|
|
|
<Artist user={user} artistId={item.id} />
|
2024-02-11 20:44:27 -05:00
|
|
|
))}
|
|
|
|
</>
|
|
|
|
)}
|
2024-02-10 20:33:24 -05:00
|
|
|
</Layout>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
// fast/cached SSR page
|
2024-02-13 01:47:26 -05:00
|
|
|
export default Home;
|