Skip to content

Commit

Permalink
extract infinite scroll loader
Browse files Browse the repository at this point in the history
  • Loading branch information
meetulr committed Oct 27, 2024
1 parent f773005 commit e42b8fe
Show file tree
Hide file tree
Showing 14 changed files with 71 additions and 84 deletions.
24 changes: 0 additions & 24 deletions src/components/AddPeopleToTag/AddPeopleToTag.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -51,27 +51,3 @@
max-height: 350px; /* Set your desired max height */
overflow-y: auto; /* Enable vertical scrolling */
}

/* SimpleLoader.css */
.simple-loader {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 100%;
}

.spinner {
width: 40px;
height: 40px;
border: 4px solid rgba(0, 0, 0, 0.1);
border-top-color: #3498db;
border-radius: 50%;
animation: spin 0.6s linear infinite;
}

@keyframes spin {
to {
transform: rotate(360deg);
}
}
9 changes: 3 additions & 6 deletions src/components/AddPeopleToTag/AddPeopleToTag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { ADD_PEOPLE_TO_TAG } from 'GraphQl/Mutations/TagMutations';
import InfiniteScroll from 'react-infinite-scroll-component';
import { WarningAmberRounded } from '@mui/icons-material';
import { useTranslation } from 'react-i18next';
import InfiniteScrollLoader from 'components/InfiniteScrollLoader/InfiniteScrollLoader';

/**
* Props for the `AddPeopleToTag` component.
Expand Down Expand Up @@ -280,7 +281,7 @@ const AddPeopleToTag: React.FC<InterfaceAddPeopleToTagProps> = ({
id="scrollableDiv"
data-testid="scrollableDiv"
style={{
height: 300,
maxHeight: 300,
overflow: 'auto',
}}
>
Expand All @@ -291,11 +292,7 @@ const AddPeopleToTag: React.FC<InterfaceAddPeopleToTagProps> = ({
userTagsMembersToAssignToData?.getUserTag.usersToAssignTo
.pageInfo.hasNextPage ?? false
}
loader={
<div className="simpleLoader">
<div className="spinner" />
</div>
}
loader={<InfiniteScrollLoader />}
scrollableTarget="scrollableDiv"
>
<DataGrid
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* InfiniteScrollLoader.module.css */
.simpleLoader {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 100%;
}

.spinner {
width: 2rem;
height: 2rem;
margin: 1rem 0;
border: 4px solid transparent; /* Set all sides transparent */
border-top-color: var(--bs-gray-400); /* Color only the top border */
border-radius: 50%;
animation: spin 0.6s linear infinite;
}

@keyframes spin {
to {
transform: rotate(360deg);
}
}
14 changes: 14 additions & 0 deletions src/components/InfiniteScrollLoader/InfiniteScrollLoader.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import InfiniteScrollLoader from './InfiniteScrollLoader';

describe('Testing InfiniteScrollLoader component', () => {
test('Component should be rendered properly', () => {
render(<InfiniteScrollLoader />);

expect(screen.getByTestId('infiniteScrollLoader')).toBeInTheDocument();
expect(
screen.getByTestId('infiniteScrollLoaderSpinner'),
).toBeInTheDocument();
});
});
15 changes: 15 additions & 0 deletions src/components/InfiniteScrollLoader/InfiniteScrollLoader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react';
import styles from './InfiniteScrollLoader.module.css';

const InfiniteScrollLoader = (): JSX.Element => {
return (
<div data-testid="infiniteScrollLoader" className={styles.simpleLoader}>
<div
data-testid="infiniteScrollLoaderSpinner"
className={styles.spinner}
/>
</div>
);
};

export default InfiniteScrollLoader;
24 changes: 0 additions & 24 deletions src/components/TagActions/TagActions.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -148,27 +148,3 @@
color: rgb(77, 76, 76);
font-weight: 600;
}

/* SimpleLoader.css */
.simpleLoader {
display: flex;
justify-content: start;
align-items: center;
width: 100%;
height: 100%;
}

.spinner {
width: 40px;
height: 40px;
border: 4px solid var(--bs-gray);
border-top-color: var(--bs-gray);
border-radius: 50%;
animation: spin 0.6s linear infinite;
}

@keyframes spin {
to {
transform: rotate(360deg);
}
}
9 changes: 3 additions & 6 deletions src/components/TagActions/TagActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { TAGS_QUERY_PAGE_SIZE } from 'utils/organizationTagsUtils';
import InfiniteScroll from 'react-infinite-scroll-component';
import { WarningAmberRounded } from '@mui/icons-material';
import TagNode from './TagNode';
import InfiniteScrollLoader from 'components/InfiniteScrollLoader/InfiniteScrollLoader';

interface InterfaceUserTagsAncestorData {
_id: string;
Expand Down Expand Up @@ -359,7 +360,7 @@ const TagActions: React.FC<InterfaceTagActionsProps> = ({
id="scrollableDiv"
data-testid="scrollableDiv"
style={{
height: 300,
maxHeight: 300,
overflow: 'auto',
}}
className={`${styles.scrContainer}`}
Expand All @@ -371,11 +372,7 @@ const TagActions: React.FC<InterfaceTagActionsProps> = ({
orgUserTagsData?.organizations[0].userTags.pageInfo
.hasNextPage ?? false
}
loader={
<div className="simpleLoader">
<div className="spinner" />
</div>
}
loader={<InfiniteScrollLoader />}
scrollableTarget="scrollableDiv"
>
{userTagsList?.map((tag) => (
Expand Down
9 changes: 3 additions & 6 deletions src/components/TagActions/TagNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type { InterfaceOrganizationSubTagsQuery } from 'utils/organizationTagsUt
import { TAGS_QUERY_PAGE_SIZE } from 'utils/organizationTagsUtils';
import styles from './TagActions.module.css';
import InfiniteScroll from 'react-infinite-scroll-component';
import InfiniteScrollLoader from 'components/InfiniteScrollLoader/InfiniteScrollLoader';

interface InterfaceTagNodeProps {
tag: InterfaceTagData;
Expand Down Expand Up @@ -141,7 +142,7 @@ const TagNode: React.FC<InterfaceTagNodeProps> = ({
id={`subTagsScrollableDiv${tag._id}`}
data-testid={`subTagsScrollableDiv${tag._id}`}
style={{
height: 300,
maxHeight: 300,
overflow: 'auto',
}}
className={`${styles.scrContainer}`}
Expand All @@ -152,11 +153,7 @@ const TagNode: React.FC<InterfaceTagNodeProps> = ({
hasMore={
subTagsData?.getUserTag.childTags.pageInfo.hasNextPage ?? false
}
loader={
<div className="simpleLoader">
<div className="spinner" />
</div>
}
loader={<InfiniteScrollLoader />}
scrollableTarget={`subTagsScrollableDiv${tag._id}`}
>
{subTagsList.map((tag: InterfaceTagData) => (
Expand Down
2 changes: 1 addition & 1 deletion src/screens/ManageTag/ManageTag.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,6 @@
scrollbar-width: auto;
scrollbar-color: var(--bs-gray-400) var(--bs-white);

height: calc(100vh - 18rem);
max-height: calc(100vh - 18rem);
overflow: auto;
}
7 changes: 2 additions & 5 deletions src/screens/ManageTag/ManageTag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
import AddPeopleToTag from 'components/AddPeopleToTag/AddPeopleToTag';
import TagActions from 'components/TagActions/TagActions';
import InfiniteScroll from 'react-infinite-scroll-component';
import InfiniteScrollLoader from 'components/InfiniteScrollLoader/InfiniteScrollLoader';

/**
* Component that renders the Manage Tag screen when the app navigates to '/orgtags/:orgId/managetag/:tagId'.
Expand Down Expand Up @@ -461,11 +462,7 @@ function ManageTag(): JSX.Element {
userTagAssignedMembersData?.getUserTag.usersAssignedTo
.pageInfo.hasNextPage ?? false
}
loader={
<div className="simpleLoader">
<div className="spinner" />
</div>
}
loader={<InfiniteScrollLoader />}
scrollableTarget="manageTagScrollableDiv"
>
<DataGrid
Expand Down
2 changes: 1 addition & 1 deletion src/screens/OrganizationTags/OrganizationTags.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,6 @@
scrollbar-width: auto;
scrollbar-color: var(--bs-gray-400) var(--bs-white);

height: calc(100vh - 18rem);
max-height: calc(100vh - 18rem);
overflow: auto;
}
7 changes: 2 additions & 5 deletions src/screens/OrganizationTags/OrganizationTags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { Stack } from '@mui/material';
import { ORGANIZATION_USER_TAGS_LIST } from 'GraphQl/Queries/OrganizationQueries';
import { CREATE_USER_TAG } from 'GraphQl/Mutations/TagMutations';
import InfiniteScroll from 'react-infinite-scroll-component';
import InfiniteScrollLoader from 'components/InfiniteScrollLoader/InfiniteScrollLoader';

/**
* Component that renders the Organization Tags screen when the app navigates to '/orgtags/:orgId'.
Expand Down Expand Up @@ -341,11 +342,7 @@ function OrganizationTags(): JSX.Element {
orgUserTagsData?.organizations[0].userTags.pageInfo
.hasNextPage ?? false
}
loader={
<div className="simpleLoader">
<div className="spinner" />
</div>
}
loader={<InfiniteScrollLoader />}
scrollableTarget="orgUserTagsScrollableDiv"
>
<DataGrid
Expand Down
2 changes: 1 addition & 1 deletion src/screens/SubTags/SubTags.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,6 @@
scrollbar-width: auto;
scrollbar-color: var(--bs-gray-400) var(--bs-white);

height: calc(100vh - 18rem);
max-height: calc(100vh - 18rem);
overflow: auto;
}
7 changes: 2 additions & 5 deletions src/screens/SubTags/SubTags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
USER_TAG_SUB_TAGS,
} from 'GraphQl/Queries/userTagQueries';
import InfiniteScroll from 'react-infinite-scroll-component';
import InfiniteScrollLoader from 'components/InfiniteScrollLoader/InfiniteScrollLoader';

/**
* Component that renders the SubTags screen when the app navigates to '/orgtags/:orgId/subtags/:tagId'.
Expand Down Expand Up @@ -397,11 +398,7 @@ function SubTags(): JSX.Element {
subTagsData?.getUserTag.childTags.pageInfo.hasNextPage ??
false
}
loader={
<div className="simpleLoader">
<div className="spinner" />
</div>
}
loader={<InfiniteScrollLoader />}
scrollableTarget="subTagsScrollableDiv"
>
<DataGrid
Expand Down

0 comments on commit e42b8fe

Please sign in to comment.