Skip to content

Commit

Permalink
fixed total count and removed unused useEffect
Browse files Browse the repository at this point in the history
  • Loading branch information
kkatusic committed Jul 30, 2024
1 parent 6a64614 commit aa89980
Showing 1 changed file with 35 additions and 39 deletions.
74 changes: 35 additions & 39 deletions src/components/views/projects/ProjectsIndex.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ const ProjectsIndex = (props: IProjectsView) => {
const count = res.data?.allProjects?.totalCount;
setTotalCount(count);

setFilteredProjects(prevProjects => [...prevProjects, ...data]);
setFilteredProjects(prevProjects => [
...prevProjects,
data.allProjects?.projects,
]);

return {
data: data,
Expand Down Expand Up @@ -158,16 +161,6 @@ const ProjectsIndex = (props: IProjectsView) => {
initialPageParam: 0,
});

// Reset query if contect variables change occurs
// TODO: This is causing a bug where the page is refreshed when you come back
// useEffect(() => {
// console.log('SOMETHING CHANGED');
// queryClient.resetQueries({
// queryKey: ['projects'],
// exact: true,
// });
// }, [contextVariables, queryClient]);

// Function that triggers when you scroll down - infinite loading
const loadMore = useCallback(() => {
fetchNextPage();
Expand Down Expand Up @@ -330,34 +323,37 @@ const ProjectsIndex = (props: IProjectsView) => {
{totalCount > filteredProjects?.length && (
<div ref={lastElementRef} />
)}
{!isFetching && !isFetchingNextPage && (
<>
<StyledButton
onClick={loadMore}
label={
isFetchingNextPage
? ''
: formatMessage({
id: 'component.button.load_more',
})
}
icon={
isFetchingNextPage && (
<LoadingDotIcon>
<div className='dot-flashing' />
</LoadingDotIcon>
)
}
/>
<StyledButton
onClick={handleCreateButton}
label={formatMessage({
id: 'component.button.create_project',
})}
$transparent
/>
</>
)}
{!isFetching &&
!isFetchingNextPage &&
totalCount < filteredProjects?.length && (
<>
<StyledButton
onClick={loadMore}
label={
isFetchingNextPage
? ''
: formatMessage({
id: 'component.button.load_more',
})
}
icon={
isFetchingNextPage && (
<LoadingDotIcon>
<div className='dot-flashing' />
</LoadingDotIcon>
)
}
/>
{totalCount} - {filteredProjects?.length}
<StyledButton
onClick={handleCreateButton}
label={formatMessage({
id: 'component.button.create_project',
})}
$transparent
/>
</>
)}
</Wrapper>
</>
);
Expand Down

0 comments on commit aa89980

Please sign in to comment.