Added skeleton loader for 'My Data' and 'Following' Section on home page (#9476)

Fixed counts mismatch for view all button in 'My Data' Section
This commit is contained in:
Aniket Katkar 2022-12-22 10:41:20 +05:30 committed by GitHub
parent 26300363b4
commit 5097a9cf16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 57 additions and 40 deletions

View File

@ -11,7 +11,7 @@
* limitations under the License. * limitations under the License.
*/ */
import { Button, Card, Typography } from 'antd'; import { Button, Card, Skeleton, Typography } from 'antd';
import React, { Fragment, FunctionComponent } from 'react'; import React, { Fragment, FunctionComponent } from 'react';
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
import { EntityReference } from '../../generated/type/entityReference'; import { EntityReference } from '../../generated/type/entityReference';
@ -27,6 +27,7 @@ interface Prop {
} }
interface AntdEntityListProp { interface AntdEntityListProp {
isLoadingOwnedData?: boolean;
entityList: Array<EntityReference>; entityList: Array<EntityReference>;
headerText?: string | JSX.Element; headerText?: string | JSX.Element;
headerTextLabel: string; headerTextLabel: string;
@ -86,14 +87,17 @@ export const EntityListWithAntd: FunctionComponent<AntdEntityListProp> = ({
headerTextLabel, headerTextLabel,
noDataPlaceholder, noDataPlaceholder,
testIDText, testIDText,
isLoadingOwnedData,
}: AntdEntityListProp) => { }: AntdEntityListProp) => {
return ( return (
<Card <Card
extra={headerText} extra={headerText}
style={leftPanelAntCardStyle} style={leftPanelAntCardStyle}
title={headerTextLabel}> title={headerTextLabel}>
{entityList.length {isLoadingOwnedData ? (
? entityList.map((item, index) => { <Skeleton active />
) : entityList.length ? (
entityList.map((item, index) => {
return ( return (
<div <div
className="flex items-center justify-between" className="flex items-center justify-between"
@ -124,7 +128,9 @@ export const EntityListWithAntd: FunctionComponent<AntdEntityListProp> = ({
</div> </div>
); );
}) })
: noDataPlaceholder} ) : (
noDataPlaceholder
)}
</Card> </Card>
); );
}; };

View File

@ -60,6 +60,7 @@ const MyData: React.FC<MyDataProps> = ({
fetchFeedHandler, fetchFeedHandler,
paging, paging,
updateThreadHandler, updateThreadHandler,
isLoadingOwnedData,
}: MyDataProps): React.ReactElement => { }: MyDataProps): React.ReactElement => {
const isMounted = useRef(false); const isMounted = useRef(false);
const [elementRef, isInView] = useInfiniteScroll(observerOptions); const [elementRef, isInView] = useInfiniteScroll(observerOptions);
@ -138,6 +139,7 @@ const MyData: React.FC<MyDataProps> = ({
</> </>
} }
headerTextLabel="My Data" headerTextLabel="My Data"
isLoadingOwnedData={isLoadingOwnedData}
noDataPlaceholder={<>You have not owned anything yet.</>} noDataPlaceholder={<>You have not owned anything yet.</>}
testIDText="My data" testIDText="My data"
/> />
@ -166,6 +168,7 @@ const MyData: React.FC<MyDataProps> = ({
</> </>
} }
headerTextLabel="Following" headerTextLabel="Following"
isLoadingOwnedData={isLoadingOwnedData}
noDataPlaceholder={<>You have not followed anything yet.</>} noDataPlaceholder={<>You have not followed anything yet.</>}
testIDText="Following data" testIDText="Following data"
/> />
@ -173,7 +176,7 @@ const MyData: React.FC<MyDataProps> = ({
<div className="tw-mt-5" /> <div className="tw-mt-5" />
</> </>
); );
}, [ownedData, followedData, pendingTaskCount]); }, [ownedData, followedData, pendingTaskCount, isLoadingOwnedData]);
const fetchMoreFeed = useCallback( const fetchMoreFeed = useCallback(
(isElementInView: boolean, pagingObj: Paging) => { (isElementInView: boolean, pagingObj: Paging) => {

View File

@ -31,6 +31,7 @@ export interface MyDataProps {
userDetails?: User; userDetails?: User;
ownedData: Array<EntityReference>; ownedData: Array<EntityReference>;
followedData: Array<EntityReference>; followedData: Array<EntityReference>;
isLoadingOwnedData: boolean;
feedData: Thread[]; feedData: Thread[];
paging: Paging; paging: Paging;
isFeedLoading: boolean; isFeedLoading: boolean;

View File

@ -340,6 +340,7 @@ const mockProp: MyDataProps = {
fetchFeedHandler: mockFetchFeedHandler, fetchFeedHandler: mockFetchFeedHandler,
followedData: currentUserMockData, followedData: currentUserMockData,
isFeedLoading: false, isFeedLoading: false,
isLoadingOwnedData: false,
ownedData: currentUserMockData, ownedData: currentUserMockData,
paging: mockPaging, paging: mockPaging,
postFeedHandler: postFeed, postFeedHandler: postFeed,

View File

@ -60,6 +60,7 @@ const MyDataPage = () => {
const [entityThread, setEntityThread] = useState<Thread[]>([]); const [entityThread, setEntityThread] = useState<Thread[]>([]);
const [isFeedLoading, setIsFeedLoading] = useState<boolean>(false); const [isFeedLoading, setIsFeedLoading] = useState<boolean>(false);
const [isLoadingOwnedData, setIsLoadingOwnedData] = useState<boolean>(false);
const [isSandbox, setIsSandbox] = useState<boolean>(false); const [isSandbox, setIsSandbox] = useState<boolean>(false);
const [activityFeeds, setActivityFeeds] = useState<Thread[]>([]); const [activityFeeds, setActivityFeeds] = useState<Thread[]>([]);
@ -104,6 +105,7 @@ const MyDataPage = () => {
if (!currentUser || !currentUser.id) { if (!currentUser || !currentUser.id) {
return; return;
} }
setIsLoadingOwnedData(true);
try { try {
const userData = await getUserById(currentUser?.id, 'follows, owns'); const userData = await getUserById(currentUser?.id, 'follows, owns');
@ -112,15 +114,15 @@ const MyDataPage = () => {
const owns: EntityReference[] = userData.owns ?? []; const owns: EntityReference[] = userData.owns ?? [];
const follows: EntityReference[] = userData.follows ?? []; const follows: EntityReference[] = userData.follows ?? [];
setFollowedDataCount(follows.length);
setOwnedDataCount(owns.length);
const includedOwnsData = owns.filter((data) =>
includeData.includes(data.type as AssetsType)
);
const includedFollowsData = follows.filter((data) => const includedFollowsData = follows.filter((data) =>
includeData.includes(data.type as AssetsType) includeData.includes(data.type as AssetsType)
); );
const includedOwnsData = owns.filter((data) =>
includeData.includes(data.type as AssetsType)
);
setFollowedDataCount(includedFollowsData.length);
setOwnedDataCount(includedOwnsData.length);
setFollowedData(includedFollowsData.slice(0, 8)); setFollowedData(includedFollowsData.slice(0, 8));
setOwnedData(includedOwnsData.slice(0, 8)); setOwnedData(includedOwnsData.slice(0, 8));
@ -128,6 +130,8 @@ const MyDataPage = () => {
} catch (err) { } catch (err) {
setOwnedData([]); setOwnedData([]);
setFollowedData([]); setFollowedData([]);
} finally {
setIsLoadingOwnedData(false);
} }
}; };
@ -307,6 +311,7 @@ const MyDataPage = () => {
followedData={followedData || []} followedData={followedData || []}
followedDataCount={followedDataCount} followedDataCount={followedDataCount}
isFeedLoading={isFeedLoading} isFeedLoading={isFeedLoading}
isLoadingOwnedData={isLoadingOwnedData}
ownedData={ownedData || []} ownedData={ownedData || []}
ownedDataCount={ownedDataCount} ownedDataCount={ownedDataCount}
paging={paging} paging={paging}

View File

@ -139,6 +139,7 @@ const TourPage = () => {
followedData={[]} followedData={[]}
followedDataCount={1} followedDataCount={1}
isFeedLoading={false} isFeedLoading={false}
isLoadingOwnedData={false}
ownedData={[]} ownedData={[]}
ownedDataCount={1} ownedDataCount={1}
paging={{} as Paging} paging={{} as Paging}