Skip to content

Commit

Permalink
Add loading animation to store page loading
Browse files Browse the repository at this point in the history
  • Loading branch information
jb3 committed Aug 25, 2024
1 parent c149f08 commit abcd723
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion thallium-frontend/src/pages/StorePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import StoreItem from "../components/StoreItem";
import styled from "styled-components";
import { Link } from "react-router-dom";

import LoadingBar from "../components/LoadingBar";


const StoreGrid = styled.div`
display: grid;
grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
Expand All @@ -20,10 +23,15 @@ const StorePage = () => {
const voucherToken = useSelector((state: RootState) => state.authorization.voucherToken);
const [storeItems, setStoreItems] = useState<Template[] | null>(null);
const [permissionDenied, setPermissionDenied] = useState<boolean>(false);
const [loading, setLoading] = useState<boolean>(true);

useEffect(() => {
getTemplates(true).then(setStoreItems).catch((err: unknown) => {
getTemplates(true).then((items) => {
setStoreItems(items);
setLoading(false);
}).catch((err: unknown) => {
setStoreItems([]);
setLoading(false);
if (err instanceof APIMissingTokenError) {
setPermissionDenied(true);
}
Expand All @@ -33,6 +41,7 @@ const StorePage = () => {
return (
<>
<h1>Giveaway Store</h1>
{loading && <LoadingBar />}
<StoreGrid>
{storeItems?.map((item) => (
<StoreItem key={item.template_id} template={item} />
Expand Down

0 comments on commit abcd723

Please sign in to comment.