From e0993dc238acb3145e2a0bd6ea87e4ab23f73b14 Mon Sep 17 00:00:00 2001 From: canove Date: Sat, 8 Aug 2020 06:54:04 -0300 Subject: [PATCH] improvement: use handleScroll instead lib to infinite scroll --- frontend/package.json | 1 - frontend/src/components/Tickets/index.js | 137 +++++++++++++---------- frontend/yarn.lock | 9 +- 3 files changed, 81 insertions(+), 66 deletions(-) diff --git a/frontend/package.json b/frontend/package.json index 40c7533..459c388 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -19,7 +19,6 @@ "react": "^16.13.1", "react-dom": "^16.13.1", "react-infinite-scroll-reverse": "^1.0.3", - "react-infinite-scroller": "^1.2.4", "react-linkify": "^1.0.0-alpha", "react-modal-image": "^2.5.0", "react-router-dom": "^5.2.0", diff --git a/frontend/src/components/Tickets/index.js b/frontend/src/components/Tickets/index.js index 05d2159..ed7d7a7 100644 --- a/frontend/src/components/Tickets/index.js +++ b/frontend/src/components/Tickets/index.js @@ -3,7 +3,6 @@ import { useHistory, useParams } from "react-router-dom"; import openSocket from "socket.io-client"; import { format } from "date-fns"; import { toast } from "react-toastify"; -import InfiniteScroll from "react-infinite-scroller"; import { makeStyles } from "@material-ui/core/styles"; import Paper from "@material-ui/core/Paper"; @@ -27,7 +26,7 @@ import TabPanel from "../TabPanel"; import api from "../../services/api"; const useStyles = makeStyles(theme => ({ - contactsWrapper: { + ticketsWrapper: { position: "relative", display: "flex", height: "100%", @@ -330,6 +329,15 @@ const Tickets = () => { setTab("search"); }; + const handleScroll = e => { + if (count === tickets.length || loading) return; + const { scrollTop, scrollHeight, clientHeight } = e.currentTarget; + + if (scrollHeight - (scrollTop + 100) < clientHeight) { + loadMore(); + } + }; + const handleChangeTab = (event, newValue) => { setTab(newValue); }; @@ -357,38 +365,8 @@ const Tickets = () => { return ticketsFound; }; - const CustomInfiniteScroll = ({ children, loadingKey }) => { - return ( - !loading && loadMore()} - hasMore={count > tickets.length} - useWindow={false} - initialLoad={false} - threshold={100} - loader={} - > - {children} - - ); - }; - - const CustomTicketList = ({ ...rest }) => { - return ( - - ); - }; - return ( - + setNewTicketModalOpen(false)} @@ -433,8 +411,13 @@ const Tickets = () => { /> - - + +
Atendendo @@ -464,19 +447,27 @@ const Tickets = () => {
- {loading ? ( - - ) : ( - - )} + + {loading && }
- +
Aguardando @@ -484,7 +475,13 @@ const Tickets = () => {
- {
- - - - - + + + + + - - - - + + + - + + {loading && }