Commit 492fb50f authored by Jon Moore's avatar Jon Moore
Browse files

Update BlogListing.js

parent 738f687d
Pipeline #39497 passed with stage
in 3 minutes and 42 seconds
...@@ -12,13 +12,18 @@ import BlogCard from './BlogCard'; ...@@ -12,13 +12,18 @@ import BlogCard from './BlogCard';
const fetchEntries = async versionStatus => { const fetchEntries = async versionStatus => {
const triggerSearch = async versionStatus => { const triggerSearch = async versionStatus => {
try { try {
//DELIVERY API QUERY START//
let query = new Query( let query = new Query(
Op.equalTo('sys.contentTypeId', 'blogPost'), Op.equalTo('sys.contentTypeId', 'blogPost'),
Op.equalTo('sys.versionStatus', versionStatus) Op.equalTo('sys.versionStatus', versionStatus)
); );
query.pageSize = 3; query.pageSize = 3;
query.fields = ['title', 'summary', 'image', 'sys']; query.fields = ['title', 'summary', 'image', 'sys'];
//DELIVERY API QUERY END//
//DELIVERY API SEARCH START//
return await cachedSearch.search(query, 1); return await cachedSearch.search(query, 1);
//DELIVERY API SEARCH END//
} catch (error) { } catch (error) {
throw new Error(error); throw new Error(error);
} }
...@@ -29,6 +34,7 @@ const fetchEntries = async versionStatus => { ...@@ -29,6 +34,7 @@ const fetchEntries = async versionStatus => {
const BlogListing = ({ className }) => { const BlogListing = ({ className }) => {
const [results, setResults] = useState(); const [results, setResults] = useState();
//GET VERSION STATUS
const versionStatus = useSelector(selectVersionStatus); const versionStatus = useSelector(selectVersionStatus);
//const versionStatus = 'latest'; //const versionStatus = 'latest';
useEffect(() => { useEffect(() => {
...@@ -39,6 +45,7 @@ const BlogListing = ({ className }) => { ...@@ -39,6 +45,7 @@ const BlogListing = ({ className }) => {
let resultsInfo = null; let resultsInfo = null;
//DELIVERY API PAGING INFO START//
if (results && results.totalCount > 0) { if (results && results.totalCount > 0) {
const start = results.pageIndex * results.pageSize + 1; const start = results.pageIndex * results.pageSize + 1;
let end = results.pageSize; let end = results.pageSize;
...@@ -46,6 +53,7 @@ const BlogListing = ({ className }) => { ...@@ -46,6 +53,7 @@ const BlogListing = ({ className }) => {
resultsInfo = `Displaying ${start}-${end} of ${results.totalCount} results`; resultsInfo = `Displaying ${start}-${end} of ${results.totalCount} results`;
} }
//DELIVERY API PAGING INFO END//
return ( return (
<BlogListingStyled className={className}> <BlogListingStyled className={className}>
...@@ -56,6 +64,7 @@ const BlogListing = ({ className }) => { ...@@ -56,6 +64,7 @@ const BlogListing = ({ className }) => {
/> />
)} )}
{/* DELIVERY API RENDER ENTRIES START */}
{results && {results &&
results.items && results.items &&
results.items.map((entry, idx) => { results.items.map((entry, idx) => {
...@@ -70,6 +79,7 @@ const BlogListing = ({ className }) => { ...@@ -70,6 +79,7 @@ const BlogListing = ({ className }) => {
); );
})} })}
{!results || (results.length < 1 && <p>No results found.</p>)} {!results || (results.length < 1 && <p>No results found.</p>)}
{/* DELIVERY API RENDER ENTRIES END */}
</BlogListingStyled> </BlogListingStyled>
); );
}; };
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment