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 dfd3190
Showing 1 changed file with 3 additions and 24 deletions.
27 changes: 3 additions & 24 deletions src/library-authoring/components/LibraryComponents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,28 +63,7 @@ const LibraryComponents = ({
return result;
}, [blockTypesData]);

const { showLoading, showContent } = useMemo(() => {
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]);
const showLoading = isFetching || isFetchingNextPage;

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

0 comments on commit dfd3190

Please sign in to comment.