Skip to content

Commit

Permalink
add custom loading fallback to List components
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonath-z committed Aug 2, 2022
1 parent eda08f4 commit 5872935
Show file tree
Hide file tree
Showing 12 changed files with 138 additions and 130 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React, { FC } from "react";
import NFTCardFallback from "../../NFTCardFallback";

const LoadNftsFallback: FC = () => {
return (
<div className="grid 2xl:grid-cols-4 xl:grid-cols-4 lg:grid-cols-3 md:grid-cols-2 sm:grid-cols-1 gap-3 pb-10 transition-all">
{Array.from({ length: 4 }).map((_, index) => {
return (
<div
key={index}
className="max-w-full min-w-[16rem] mobile:max-w-full mobile:min-w-full"
>
<NFTCardFallback />
</div>
);
})}
</div>
);
};

export default LoadNftsFallback;
23 changes: 6 additions & 17 deletions components/modules/__modules__/ListViewBuilder/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import React, { FC, memo } from "react";
import { IListView, IListViewBuilder } from "@lib/@Types";
import { NftModelToCardData } from "@lib/models/GeneralModel";
import useMediaQuery from "@components/hooks/useMediaQuery";
import { List, Skeleton } from "antd";
import { List } from "antd";
import { LoadMore } from "@components/modules/__modules__/Card/LoadMore";
import SkeletonLoader from "@components/modules/__modules__/Card/SkeletonLoader";
import NFTCardFallback from "../NFTCardFallback";
import NftPreview from "@components/CreateNftPage/NftPreview";
import LoadNftsFallback from "./LoadNftsFallback";

export const ListView: FC<IListView> = ({
loading,
Expand Down Expand Up @@ -34,8 +34,10 @@ export const ListView: FC<IListView> = ({
return (
<div className="items-center">
<List
loading={loading}
className={loading ? "hidden" : "block"}
loading={{
indicator: <LoadNftsFallback />,
spinning: loading,
}}
loadMore={
loadMore || (
<div className={!loadingMore ? "flex justify-center" : ""}>
Expand Down Expand Up @@ -65,19 +67,6 @@ export const ListView: FC<IListView> = ({
return renderItem(item);
}}
/>

<List
grid={grid}
// loading={false}
loading={loading}
className={loading ? "block" : "hidden"}
dataSource={items.slice(0, preloaderLimit())}
renderItem={() => (
<List.Item>
<NFTCardFallback />
</List.Item>
)}
/>
</div>
);
};
Expand Down
18 changes: 8 additions & 10 deletions components/modules/__modules__/NFTCardFallback/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@ import React from "react";

const NFTCardFallback = () => {
return (
<>
<div className="h-fit w-full transition-all flex-none border hover:border-2 border-slate-200 dark:border-gray-500 relative p-2 mobile:mr-0 rounded-xl snap-center">
<div className="h-72 w-full bg-gray-300 animate-pulse rounded-xl" />
<div className="flex justify-between items-center mt-3">
<div className="h-2 w-1/2 bg-gray-300 animate-pulse rounded-sm" />
<div className="h-2 w-1/5 bg-gray-300 animate-pulse rounded-sm" />
</div>
<div className="mt-3 w-full h-16 bg-gray-300 animate-pulse rounded-xl" />
<div className="mt-3 w-full h-10 bg-gray-300 animate-pulse rounded-xl" />
<div className="relative h-fit w-full transition-all flex-none border hover:border-2 border-slate-200 dark:border-gray-500 p-2 mobile:mr-0 rounded-xl snap-center">
<div className="h-72 w-full bg-gray-300/50 animate-pulse rounded-xl" />
<div className="flex justify-between items-center mt-3">
<div className="h-2 w-1/2 bg-gray-300/50 animate-pulse rounded-sm" />
<div className="h-2 w-1/5 bg-gray-300/50 animate-pulse rounded-sm" />
</div>
</>
<div className="mt-3 w-full h-16 bg-gray-300/50 animate-pulse rounded-xl" />
<div className="mt-3 w-full h-10 bg-gray-300/50 animate-pulse rounded-xl" />
</div>
);
};

Expand Down
184 changes: 92 additions & 92 deletions components/modules/__noAuth/ExploreNFTs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,88 +40,57 @@ const ExploreNFTs = () => {
};

return (
<div>
<section className="2xl:w-[80%] xl:w-[85%] lg:w-[90%] md:w-[95%] mx-auto h-fit mt-12 ">
<h2 className="font-bold text-xl text-black font-ibmPlexSans md:text-2xl lg:text-3xl dark:text-white px-6 pb-3">
Explore NFTs
</h2>
<ShowWidget condition={!isLoading}>
<div className="flex justify-between mobile:mx-1 mobile:gap-2 mb-5 items-center dark:text-white font-bold relative px-5">
<div className="flex gap-5 mobile:gap-2 mobile:w-full">
<button
onClick={toggleBlockchainModal}
className="border border-gray-300 dark:border-gray-500 py-2 px-3 rounded-lg"
>
Blockchain
</button>
<button
onClick={togglePriceRangeModal}
className="border border-gray-300 dark:border-gray-500 py-2 px-3 rounded-lg"
>
Price Range
</button>
<ShowWidget condition={isBlockchainModal}>
<div
ref={blockchainModalRef}
className="absolute w-44 top-14 bg-white dark:bg-darkPrimary border border-gray-200 dark:border-darkLight z-20 rounded-lg shadow-lg transition-all"
>
<p className="py-5 px-2 flex justify-between items-center">
Polygon <VSingleDot className="text-green-600" />
</p>
</div>
</ShowWidget>
<ShowWidget condition={isPriceRangeModal}>
<div
ref={priceRangeModalRef}
className="absolute w-60 top-14 left-28 mobile:left-0 mobile:mx-5 bg-white dark:bg-darkPrimary border border-gray-200 dark:border-darkLight z-20 rounded-lg shadow-lg transition-all"
>
<p className="py-5 px-2 flex justify-between items-center">
MATIC
</p>
<div className="flex gap-1">
<input
type="number"
placeholder="from"
className="w-full py-2 bg-gray-200 dark:bg-gray-500 m-1 rounded-lg px-2 outline-none transition-all focus:shadow-md focus:bg-white dark:focus:bg-darkLight"
/>
<input
type="number"
placeholder="to"
className="w-full py-2 bg-gray-200 dark:bg-gray-500 m-1 rounded-lg px-2 outline-none transition-all focus:shadow-md focus:bg-white dark:focus:bg-darkLight"
/>
</div>
<div className="flex gap-1">
<button className="w-full py-2 bg-gray-200 dark:bg-gray-500 m-1 rounded-lg">
Clear
</button>
<button className="w-full py-2 bg-blue-600 text-white m-1 rounded-lg">
Apply
</button>
</div>
</div>
</ShowWidget>
</div>
// <div>
<section className="2xl:w-[80%] xl:w-[85%] lg:w-[90%] md:w-[95%] mx-auto h-fit mt-12">
<h2 className="font-bold text-xl text-black font-ibmPlexSans md:text-2xl lg:text-3xl dark:text-white px-6 pb-3">
Explore NFTs
</h2>
<ShowWidget condition={!isLoading}>
<div className="flex justify-between mobile:mx-1 mobile:gap-2 mb-5 items-center dark:text-white font-bold relative px-5">
<div className="flex gap-5 mobile:gap-2 mobile:w-full">
<button
onClick={toggleSortModal}
onClick={toggleBlockchainModal}
className="border border-gray-300 dark:border-gray-500 py-2 px-3 rounded-lg"
>
<span className="mobile:hidden block">Filter & Sort</span>
<span className="hidden mobile:block text-2xl">
<VFilter />
</span>
Blockchain
</button>
<ShowWidget condition={isSortModal}>
<button
onClick={togglePriceRangeModal}
className="border border-gray-300 dark:border-gray-500 py-2 px-3 rounded-lg"
>
Price Range
</button>
<ShowWidget condition={isBlockchainModal}>
<div
ref={sortModalRef}
className="absolute top-14 bg-white border border-gray-200 dark:border-darkLight dark:bg-darkPrimary z-20 w-60 right-0 rounded-lg shadow-lg transition-all p-4"
ref={blockchainModalRef}
className="absolute w-44 top-14 bg-white dark:bg-darkPrimary border border-gray-200 dark:border-darkLight z-20 rounded-lg shadow-lg transition-all"
>
<p className="py-5 px-2 flex justify-between items-center cursor-pointer hover:bg-gray-200 hover:dark:bg-darkLight rounded-lg transition-all">
DESC <VSingleDot className="text-green-600" />
<p className="py-5 px-2 flex justify-between items-center">
Polygon <VSingleDot className="text-green-600" />
</p>
<p className="py-5 px-2 flex justify-between items-center cursor-pointer hover:bg-gray-200 hover:dark:bg-darkLight rounded-lg transition-all">
ASC
</div>
</ShowWidget>
<ShowWidget condition={isPriceRangeModal}>
<div
ref={priceRangeModalRef}
className="absolute w-60 top-14 left-28 mobile:left-0 mobile:mx-5 bg-white dark:bg-darkPrimary border border-gray-200 dark:border-darkLight z-20 rounded-lg shadow-lg transition-all"
>
<p className="py-5 px-2 flex justify-between items-center">
MATIC
</p>
<div className="flex gap-3 mt-3">
<div className="flex gap-1">
<input
type="number"
placeholder="from"
className="w-full py-2 bg-gray-200 dark:bg-gray-500 m-1 rounded-lg px-2 outline-none transition-all focus:shadow-md focus:bg-white dark:focus:bg-darkLight"
/>
<input
type="number"
placeholder="to"
className="w-full py-2 bg-gray-200 dark:bg-gray-500 m-1 rounded-lg px-2 outline-none transition-all focus:shadow-md focus:bg-white dark:focus:bg-darkLight"
/>
</div>
<div className="flex gap-1">
<button className="w-full py-2 bg-gray-200 dark:bg-gray-500 m-1 rounded-lg">
Clear
</button>
Expand All @@ -132,25 +101,56 @@ const ExploreNFTs = () => {
</div>
</ShowWidget>
</div>
</ShowWidget>

<div className="mx-5 justify-center h-fit">
<ListViewBuilder
items={nfts}
renderItem={(item) => (
<List.Item>
<NFTCard nft={item} />
</List.Item>
)}
hasMore={false}
showLoadMoreButton={shouldShowLoadMoreButton}
loading={currentNfts.isLoading}
loadingMore={false}
onLoadMore={onLoadMore}
/>
<button
onClick={toggleSortModal}
className="border border-gray-300 dark:border-gray-500 py-2 px-3 rounded-lg"
>
<span className="mobile:hidden block">Filter & Sort</span>
<span className="hidden mobile:block text-2xl">
<VFilter />
</span>
</button>
<ShowWidget condition={isSortModal}>
<div
ref={sortModalRef}
className="absolute top-14 bg-white border border-gray-200 dark:border-darkLight dark:bg-darkPrimary z-20 w-60 right-0 rounded-lg shadow-lg transition-all p-4"
>
<p className="py-5 px-2 flex justify-between items-center cursor-pointer hover:bg-gray-200 hover:dark:bg-darkLight rounded-lg transition-all">
DESC <VSingleDot className="text-green-600" />
</p>
<p className="py-5 px-2 flex justify-between items-center cursor-pointer hover:bg-gray-200 hover:dark:bg-darkLight rounded-lg transition-all">
ASC
</p>
<div className="flex gap-3 mt-3">
<button className="w-full py-2 bg-gray-200 dark:bg-gray-500 m-1 rounded-lg">
Clear
</button>
<button className="w-full py-2 bg-blue-600 text-white m-1 rounded-lg">
Apply
</button>
</div>
</div>
</ShowWidget>
</div>
</section>
</div>
</ShowWidget>

<div className="mx-5">
<ListViewBuilder
items={nfts}
renderItem={(item) => (
<List.Item>
<NFTCard nft={item} />
</List.Item>
)}
hasMore={false}
showLoadMoreButton={shouldShowLoadMoreButton}
loading={currentNfts.isLoading}
loadingMore={false}
onLoadMore={onLoadMore}
/>
</div>
</section>
// {/* </div> */}
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const CreatedContainer = ({
const { onLoadMore, shouldShowLoadMoreButton } = useNfTs();

return (
<div className="flex flex-wrap justify-center mobile:justify-center my-5 gap-3">
<div className="my-5 w-full">
<ListViewBuilder
items={createdNFts}
renderItem={(item) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const OwnedContainer = ({
);

return (
<div className="flex justify-center mobile:justify-center my-5 gap-3">
<div className="my-5 w-full">
<ListViewBuilder
items={ownedNfts}
renderItem={(item) => (
Expand Down
1 change: 0 additions & 1 deletion components/modules/__secured/Profile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import { UserAccount } from "@lib/models/UserAccount";
import { NFTData, NFTMetaData } from "@lib/models/GeneralModel";
import { backendApiService } from "@lib/services/BackendApiService";
import ProfileReportOption from "./module/ProfileReportOptions";
import ShowWidget from "@components/modules/__modules__/ShowWidget";

interface IProps {
searchedUserProfile: UserAccount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const SaleContainer = ({
const { onLoadMore, shouldShowLoadMoreButton } = useNfTs();

return (
<div className="flex flex-wrap justify-center mobile:justify-center my-5 gap-3">
<div className="my-5">
<ListViewBuilder
items={listedNfts}
renderItem={(item) => (
Expand Down
2 changes: 1 addition & 1 deletion lib/@Types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const defaultVectorProps: classNameInterface = {
className: "h-6 w-6",
};

export interface updateProfileInterface {
export interface IUpdateProfile {
walletAddress: string;
username?: string;
userBio?: string;
Expand Down
4 changes: 2 additions & 2 deletions lib/services/BackendApiService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { UserAccount } from "@lib/models/UserAccount";
import http from "@lib/http";
import * as Sentry from "@sentry/nextjs";
import { orderObject } from "@lib/Utils";
import { updateProfileInterface } from "@lib/@Types";
import { IUpdateProfile } from "@lib/@Types";
import {
IGetRequestNFTsParams,
NftCardData,
Expand Down Expand Up @@ -52,7 +52,7 @@ class BackendApiService {
coverThumbnailUrl,
coverUrl,
signature,
}: updateProfileInterface): Promise<any | null> {
}: IUpdateProfile): Promise<any | null> {
try {
const profileEndpoint = "/users/profile";
const response = await http.put(
Expand Down
5 changes: 5 additions & 0 deletions styles/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,8 @@ input[type="number"]::-webkit-outer-spin-button {
background-position: 1000px 0;
}
}

/* hide default spin div container as w're using a custom fallback */
.ant-spin-blur {
display: none;
}
4 changes: 0 additions & 4 deletions tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ module.exports = {
],
darkMode: "class",
theme: {
gridTemplateColumns: {
"auto-fit": "repeat(auto-fit, minmax(20rem, 1fr))",
// "auto-fit": "repeat(auto-fit, minmax(16rem, 1fr)",
},
colors: {
...colors,
darkPrimary: "#041C32",
Expand Down

0 comments on commit 5872935

Please sign in to comment.