Skip to content

Commit

Permalink
add loader
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanBonsignori committed Mar 22, 2024
1 parent 27459d1 commit ccdccf2
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/components/pages/BlogList.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import React, { useEffect, useState } from 'react';
import { Link, Outlet, useNavigate } from 'react-router-dom';
import styled from 'styled-components';
import HashLoader from 'react-spinners/HashLoader';
import localBlogPosts from '../../assets/blogPosts';
import { getBlogs } from '../../utils/blogApi';
import breakpoints from '../../utils/breakpoints';
import { fadeIn } from '../../utils/keyframes';
import Headline from './shared/Headline';
import { baseColors } from '../Theme';

const BlogList = ({ darkMode, toggleTheme }) => {
const [loading, setLoading] = useState(false);
Expand All @@ -34,7 +36,6 @@ const BlogList = ({ darkMode, toggleTheme }) => {
const blogs = mergeLocalAndDBBlogs(data.blogs);

setBlogPosts(blogs);
setLoading(false);
};

useEffect(() => {
Expand Down Expand Up @@ -93,7 +94,11 @@ const BlogList = ({ darkMode, toggleTheme }) => {
<>
<Headline title='BLOG' darkMode={darkMode} toggleTheme={toggleTheme} />
{loading ? (
<>Loading...</>
<LoadingWrapper>
<HashLoader
color={darkMode ? baseColors.salmon : baseColors.neonBlue}
/>
</LoadingWrapper>
) : (
<BlogPostsWrapper>
<SortWrapper>
Expand Down Expand Up @@ -125,6 +130,12 @@ const BlogList = ({ darkMode, toggleTheme }) => {
);
};

const LoadingWrapper = styled.div`
display: flex;
justify-content: center;
align-items: center;
`;

const BlogPost = styled.div`
display: flex;
flex-direction: column;
Expand Down

0 comments on commit ccdccf2

Please sign in to comment.