From 90ed9df902527ba3203bfd2dd6b452576c299b37 Mon Sep 17 00:00:00 2001 From: R A Van Epps Date: Mon, 26 Apr 2021 11:10:15 -0600 Subject: [PATCH 1/6] Fix jsdoc desc --- components/organisms/Header/Header.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/organisms/Header/Header.js b/components/organisms/Header/Header.js index 9c7aabfad..4aae51782 100644 --- a/components/organisms/Header/Header.js +++ b/components/organisms/Header/Header.js @@ -9,7 +9,7 @@ import styles from './Header.module.css' // TODO: Create Storybook for this component. /** - * Render the ImageGallery component. + * Render the Header component. * * @author WebDevStudios * @return {Element} The Header component. From 54f66ad5443e96bb6070e85c9cb4b26d52ca6cda Mon Sep 17 00:00:00 2001 From: R A Van Epps Date: Mon, 26 Apr 2021 11:16:10 -0600 Subject: [PATCH 2/6] Create Archive component --- components/organisms/Archive/Archive.js | 80 +++++++++++++++++++++++++ components/organisms/Archive/index.js | 1 + 2 files changed, 81 insertions(+) create mode 100644 components/organisms/Archive/Archive.js create mode 100644 components/organisms/Archive/index.js diff --git a/components/organisms/Archive/Archive.js b/components/organisms/Archive/Archive.js new file mode 100644 index 000000000..97e89692a --- /dev/null +++ b/components/organisms/Archive/Archive.js @@ -0,0 +1,80 @@ +import Button from '@/components/atoms/Button' +import Container from '@/components/atoms/Container' +import Layout from '@/components/common/Layout' +import Card from '@/components/molecules/Card' +import getPagePropTypes from '@/functions/getPagePropTypes' +import getArchivePosts from '@/functions/next-api/wordpress/archive/getArchivePosts' +import {useRef, useState} from 'react' + +/** + * Render the Archive component. + * + * @author WebDevStudios + * @param {object} props The component attributes as props. + * @param {object} props.post Post data from WordPress. + * @param {Array} props.posts Array of post data from WordPress. + * @param {object} props.pagination Archive pagination data from WordPress. + * @param {string} props.postType WP post type. + * @param + * @return {Element} The Archive component. + */ +export default function Archive({post, posts, pagination, postType}) { + // Track all posts, including initial posts and additionally loaded pages. + const [allPosts, setAllPosts] = useState(posts) + + // Track "load more" button state. + const [loadingMore, setLoadingMore] = useState(false) + + // Track current pagination object. + const paginationRef = useRef(pagination) + + /** + * Load more posts for archive. + */ + async function loadPosts() { + setLoadingMore(true) + + const newPosts = await getArchivePosts( + postType, + paginationRef.current?.endCursor + ) + + setAllPosts([...allPosts, ...(newPosts?.posts ?? [])]) + + // Update pagination ref. + paginationRef.current = newPosts?.pagination + + setLoadingMore(false) + } + + return ( + + + {!allPosts || !allPosts.length ? ( +

No posts found.

+ ) : ( +
+ {allPosts.map((post, index) => ( + + ))} +
+ )} +