Skip to content
This repository has been archived by the owner on Dec 8, 2023. It is now read-only.

Commit

Permalink
feat: begin adding pagination to catalogue
Browse files Browse the repository at this point in the history
  • Loading branch information
aswanson-nr committed Jul 26, 2022
1 parent 4224150 commit d563b42
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/components/GuidedInstallTileMostPopular.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const GuidedInstallTileMostPopular = () => {
min-width: 250px;
}
background: #1a3c34;
background: var(--button-background-color);
h2,
p {
Expand Down
62 changes: 62 additions & 0 deletions src/components/QuickstartGrid.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import React, { useEffect, useState } from 'react';
import PropTypes from 'prop-types';
import { css } from '@emotion/react';
import { Button, Surface } from '@newrelic/gatsby-theme-newrelic';
import QuickstartTile from '@components/QuickstartTile';
import { quickstart } from '../types';

const QuickstartGrid = ({ quickstarts }) => {
const [displayed, showMore] = usePagination(quickstarts, 11);

return (
<>
{displayed.map((q) => (
<QuickstartTile key={q.id} {...q} />
))}
{quickstarts.length > displayed.length && (
<Surface
base={Surface.BASE.PRIMARY}
interactive
css={css`
border: 1px solid #e4e5e6;
box-shadow: none;
display: flex;
`}
>
<Button
variant={Button.VARIANT.NORMAL}
css={css`
border-radius: 8px;
font-size: 1rem;
width: 100%;
`}
onClick={showMore}
>
Show more
</Button>
</Surface>
)}
</>
);
};

const usePagination = (quickstarts, size) => {
const [numDisplayed, setNumDisplayed] = useState(size);
const [qs, setQs] = useState(quickstarts.slice(0, size));

useEffect(() => {
setQs(quickstarts.slice(0, numDisplayed));
}, [numDisplayed, quickstarts]);

const showMore = () => {
setNumDisplayed(numDisplayed + size + 1);
};

return [qs, showMore];
};

QuickstartGrid.propTypes = {
quickstarts: PropTypes.arrayOf(quickstart),
};

export default QuickstartGrid;
17 changes: 8 additions & 9 deletions src/pages/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import QuickstartTile from '@components/QuickstartTile';
import SuperTiles from '@components/SuperTiles';
import CategoryList from '@components/indexComponents/CategoryList';
import CategoryDropdown from '@components/indexComponents/CategoryDropdown';
import QuickstartGrid from '@components/QuickstartGrid';

const COLUMN_BREAKPOINT = '1131px';
// used to set the height of the Spinner to reduce layout shift on page load
Expand All @@ -56,7 +57,7 @@ const QuickstartsPage = ({ data, location }) => {
const [loadComplete, setLoadComplete] = useState(false);

useEffect(() => {
setLoadComplete(true);
setLoadComplete(true);
}, []);

const handleScroll = () => {
Expand Down Expand Up @@ -188,7 +189,7 @@ const QuickstartsPage = ({ data, location }) => {
padding: 1.5rem;
`}
>
<CategoryDropdown
<CategoryDropdown
category={category}
categoriesWithCount={categoriesWithCount}
handleParam={handleParam}
Expand Down Expand Up @@ -228,7 +229,7 @@ const QuickstartsPage = ({ data, location }) => {
`}
>
{!loadComplete && <Spinner />}
{ loadComplete &&
{loadComplete && (
<Slider
{...indexSettings}
css={css`
Expand All @@ -244,7 +245,7 @@ const QuickstartsPage = ({ data, location }) => {
/>
))}
</Slider>
}
)}
</div>
</>
)}
Expand Down Expand Up @@ -278,7 +279,7 @@ const QuickstartsPage = ({ data, location }) => {
`}
>
{!loadComplete && <Spinner />}
{ loadComplete &&
{loadComplete && (
<Slider {...indexSettings}>
{featuredQuickstarts.map((pack) => (
<QuickstartTile
Expand All @@ -288,7 +289,7 @@ const QuickstartsPage = ({ data, location }) => {
/>
))}
</Slider>
}
)}
</div>
</>
)}
Expand Down Expand Up @@ -355,9 +356,7 @@ const QuickstartsPage = ({ data, location }) => {
`}
>
{Boolean(search) && <SuperTiles />}
{filteredQuickstarts.map((pack) => (
<QuickstartTile key={pack.id} featured={false} {...pack} />
))}
<QuickstartGrid quickstarts={filteredQuickstarts} />
</div>
</div>
</div>
Expand Down

0 comments on commit d563b42

Please sign in to comment.