From 257d70c9c1f27d3eb500063347a044f22217a2ca Mon Sep 17 00:00:00 2001 From: luxumbra Date: Thu, 2 Nov 2023 13:28:09 +0000 Subject: [PATCH] wip on fixing isues --- .../src/icons/CalendarAddIcon.tsx | 2 +- .../web/components/Dashboard/Calendar.tsx | 282 ++++++++++-------- packages/web/lib/hooks/useCalendar.ts | 99 +++--- packages/web/pages/_app.tsx | 18 +- packages/web/pages/api/events.ts | 37 ++- 5 files changed, 254 insertions(+), 184 deletions(-) diff --git a/packages/design-system/src/icons/CalendarAddIcon.tsx b/packages/design-system/src/icons/CalendarAddIcon.tsx index cf1999ce1..8579867ea 100644 --- a/packages/design-system/src/icons/CalendarAddIcon.tsx +++ b/packages/design-system/src/icons/CalendarAddIcon.tsx @@ -4,7 +4,7 @@ import * as React from 'react'; export const CalendarAddIcon = createIcon({ displayName: 'CalendarAddIcon', path: ( - + { const [calendar, setCalendar] = useState([]); const [loadingMore, setLoadingMore] = useState(false); - const showHowMany = 4; + const showHowMany = 3; const { fetching, error, @@ -65,10 +65,18 @@ export const Calendar: React.FC = () => { limit, setLimit, } = useCalendar(showHowMany); - + const lastItemRef = useRef(null); const handleShowMoreItems = async () => { try { + if (loadingMore || limit >= totalEvents) return; setLoadingMore(true); + setTimeout(() => { + lastItemRef.current?.scrollIntoView({ + behavior: 'smooth', + block: 'start', + inline: 'nearest', + }); + }, 0); setTimeout(() => { setLimit(limit + showHowMany); setLoadingMore(false); @@ -80,7 +88,6 @@ export const Calendar: React.FC = () => { function renderLoadMoreButton() { if (limit < totalEvents) { - /* When there are more items to show */ return ( {loadingMore ? : 'Load More'} @@ -88,7 +95,6 @@ export const Calendar: React.FC = () => { ); } - /* When there are no more items to show */ return ( @@ -103,9 +109,7 @@ export const Calendar: React.FC = () => { const limitedEvents = eventsGroupedByDay.slice(0, limit); setCalendar(limitedEvents); } - - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [limit, fetching]); + }, [limit, fetching, eventsGroupedByDay]); if (error) { return ( @@ -146,9 +150,6 @@ export const Calendar: React.FC = () => { > Calendar - {/* - {timeZone.users} {`(UTC${usersOffsetString}) ${DateTime.local().zoneName}`} - */}