-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from giovanifranz/master
feat: infiniteScroll => mobile / paginação => Desktop
- Loading branch information
Showing
9 changed files
with
62 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
type EmptyObject = Record<string, never>; |
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,32 @@ | ||
import { useEffect, useRef } from "react"; | ||
import { usePage } from "../../hooks"; | ||
import { Loading } from "./styles"; | ||
|
||
function InfiniteScroll() { | ||
const { setPage } = usePage(); | ||
const loaderRef = useRef(null); | ||
|
||
useEffect(() => { | ||
const options = { | ||
root: null, | ||
rootMargin: "100px", | ||
threshold: 1.0, | ||
}; | ||
|
||
const observer = new IntersectionObserver((entities) => { | ||
const target = entities[0]; | ||
|
||
if (target.isIntersecting) { | ||
setPage((page) => page + 1); | ||
} | ||
}, options); | ||
|
||
if (loaderRef.current) { | ||
observer.observe(loaderRef.current); | ||
} | ||
}, []); | ||
|
||
return <Loading ref={loaderRef}>Carregando mais episodios...</Loading>; | ||
} | ||
|
||
export { InfiniteScroll }; |
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,6 @@ | ||
import styled from "styled-components"; | ||
|
||
export const Loading = styled.p` | ||
text-align: center; | ||
margin: 2rem 0; | ||
`; |
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
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export * from "./usePage"; | ||
export * from "./useWindowsWidth"; | ||
export * from "./useWindowsIsDesktop"; |
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
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
2fd9556
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: