-
-
Save kasperaamodt/c01d8b85f4566d5ae1ddf0d5a76ffaeb to your computer and use it in GitHub Desktop.
Infinite scroll
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
import { useArchiveInfiniteScroll } from "@frontity/hooks"; | |
import { connect, styled } from "frontity"; | |
import React from "react"; | |
import Loading from "../pages/loading"; | |
import ListPage from "./list-page"; | |
const List = () => { | |
const { | |
pages, | |
isLimit, | |
isFetching, | |
isError, | |
fetchNext | |
} = useArchiveInfiniteScroll({ limit: 3 }); | |
return ( | |
<> | |
<Header> | |
<h1>Media</h1> | |
</Header> | |
{pages.map(({ key, link, isLast, Wrapper }) => ( | |
<Wrapper key={key}> | |
<ListPage link={link} /> | |
{!isLast && <></>} | |
</Wrapper> | |
))} | |
<ButtonContainer> | |
{isFetching && <Loading />} | |
{isLimit && <Button className="wp-block-button__link" onClick={fetchNext}>Load more</Button>} | |
{isError && ( | |
<Button className="wp-block-button__link" onClick={fetchNext}>Something went wrong, try again</Button> | |
)} | |
</ButtonContainer> | |
</> | |
); | |
}; | |
export default connect(List); | |
const ButtonContainer = styled.div` | |
display: flex; | |
justify-content: center; | |
align-items: center; | |
width: 100%; | |
max-width: 1200px; | |
margin: 20px auto; | |
`; | |
const Button = styled.button` | |
`; | |
const Header = styled.div` | |
width: 100%; | |
margin: 40px 0; | |
text-align: center; | |
h1 { | |
font-size: 78px; | |
font-weight: 400; | |
} | |
@media (max-width: 600px) { | |
h1 { | |
font-size: 48px; | |
} | |
} | |
`; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment