Skip to content

Commit

Permalink
fix: remove loading state if already data is already loaded to avoid …
Browse files Browse the repository at this point in the history
…flickering
  • Loading branch information
rpenido committed Jul 3, 2024
1 parent 782386f commit 07b3a03
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions src/library-authoring/components/LibraryComponents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,28 +63,24 @@ const LibraryComponents = ({
return result;
}, [blockTypesData]);

const { showLoading, showContent } = useMemo(() => {

Check failure on line 66 in src/library-authoring/components/LibraryComponents.tsx

View workflow job for this annotation

GitHub Actions / tests

More than 1 blank line not allowed
const a = (isFetching, isFetchingNextPage) => {

Check failure on line 67 in src/library-authoring/components/LibraryComponents.tsx

View workflow job for this annotation

GitHub Actions / tests

'a' is assigned a value but never used

Check failure on line 67 in src/library-authoring/components/LibraryComponents.tsx

View workflow job for this annotation

GitHub Actions / tests

'isFetching' is already declared in the upper scope on line 28 column 5

Check failure on line 67 in src/library-authoring/components/LibraryComponents.tsx

View workflow job for this annotation

GitHub Actions / tests

'isFetchingNextPage' is already declared in the upper scope on line 29 column 5
let resultShowLoading = false;
let resultShowContent = false;

if (isFetching && !isFetchingNextPage) {
// First load; show loading but not content.
resultShowLoading = true;
resultShowContent = false;
} else if (isFetchingNextPage) {
// Load next page; show content and loading.
resultShowLoading = true;
resultShowContent = true;
} else if (!isFetching && !isFetchingNextPage) {
// State without loads; show content.
resultShowLoading = false;
resultShowContent = true;
}
return {
showLoading: resultShowLoading,
showContent: resultShowContent,
};
}, [isFetching, isFetchingNextPage]);
return resultShowLoading;
};

const showLoading = isFetching || isFetchingNextPage;

useEffect(() => {
if (variant === 'full') {
Expand Down Expand Up @@ -121,7 +117,7 @@ const LibraryComponents = ({
}}
hasEqualColumnHeights
>
{ showContent ? componentList.map((component) => (
{componentList.map((component) => (
<ComponentCard
key={component.id}
title={component.displayName}
Expand All @@ -130,7 +126,7 @@ const LibraryComponents = ({
blockType={component.blockType}
blockTypeDisplayName={blockTypes[component.blockType]?.displayName ?? ''}
/>
)) : <ComponentCardLoading />}
))}
{ showLoading && <ComponentCardLoading /> }
</CardGrid>
);
Expand Down

0 comments on commit 07b3a03

Please sign in to comment.