This repository has been archived by the owner on Dec 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: begin adding pagination to catalogue
- Loading branch information
1 parent
4224150
commit d563b42
Showing
3 changed files
with
71 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters