Skip to content

Commit

Permalink
add loader on different pages
Browse files Browse the repository at this point in the history
  • Loading branch information
antho1404 committed Apr 21, 2023
1 parent ef97a9c commit e3fadeb
Show file tree
Hide file tree
Showing 22 changed files with 78 additions and 28 deletions.
4 changes: 3 additions & 1 deletion pages/account/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useRouter } from 'next/router'
import { useCallback } from 'react'
import AccountTemplate from '../../components/Account/Account'
import Head from '../../components/Head'
import Loader from '../../components/Loader'
import UserFormEdit from '../../components/User/Form/Edit'
import environment from '../../environment'
import { useGetAccountQuery } from '../../graphql'
Expand All @@ -24,7 +25,7 @@ const EditPage: NextPage = () => {

const toast = useToast()

const { data } = useGetAccountQuery({
const { data, loading } = useGetAccountQuery({
variables: {
address: address || '',
},
Expand All @@ -42,6 +43,7 @@ const EditPage: NextPage = () => {
[toast, t, push],
)

if (loading) return <Loader fullPage />
if (!data?.account) return <></>
return (
<SmallLayout>
Expand Down
4 changes: 3 additions & 1 deletion pages/account/wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { NextPage } from 'next'
import { useMemo } from 'react'
import AccountTemplate from '../../components/Account/Account'
import Head from '../../components/Head'
import Loader from '../../components/Loader'
import WalletAccount from '../../components/Wallet/Account/Wallet'
import { useWalletCurrenciesQuery } from '../../graphql'
import useAccount from '../../hooks/useAccount'
Expand All @@ -13,9 +14,10 @@ const WalletPage: NextPage = () => {
const ready = useEagerConnect()
const { address } = useAccount()
useLoginRedirect(ready)
const { data } = useWalletCurrenciesQuery()
const { data, loading } = useWalletCurrenciesQuery()
const currencies = useMemo(() => data?.currencies?.nodes, [data])

if (loading) return <Loader fullPage />
if (!currencies) return <></>
if (!address) return <></>
return (
Expand Down
4 changes: 3 additions & 1 deletion pages/checkout/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { useRouter } from 'next/router'
import { useCallback, useMemo } from 'react'
import Head from '../../components/Head'
import Image from '../../components/Image/Image'
import Loader from '../../components/Loader'
import BackButton from '../../components/Navbar/BackButton'
import OfferFormCheckout from '../../components/Offer/Form/Checkout'
import Price from '../../components/Price/Price'
Expand Down Expand Up @@ -49,7 +50,7 @@ const CheckoutPage: NextPage<Props> = ({ now }) => {
const { address } = useAccount()

const date = useMemo(() => new Date(now), [now])
const { data } = useCheckoutQuery({
const { data, loading } = useCheckoutQuery({
variables: {
id: offerId,
now: date,
Expand Down Expand Up @@ -79,6 +80,7 @@ const CheckoutPage: NextPage<Props> = ({ now }) => {
await push(`/tokens/${data.offer.asset.id}`)
}, [data, toast, t, push])

if (loading) return <Loader fullPage />
if (!offer) return null
if (!asset) return null
return (
Expand Down
7 changes: 5 additions & 2 deletions pages/collection/[chainId]/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import Empty from '../../../components/Empty/Empty'
import FilterAsset, { NoFilter } from '../../../components/Filter/FilterAsset'
import FilterNav from '../../../components/Filter/FilterNav'
import Head from '../../../components/Head'
import Loader from '../../../components/Loader'
import Pagination from '../../../components/Pagination/Pagination'
import Select from '../../../components/Select/Select'
import TokenCard from '../../../components/Token/Card'
Expand Down Expand Up @@ -67,7 +68,7 @@ const CollectionPage: FC<Props> = ({ now }) => {
const { t } = useTranslation('templates')
const date = useMemo(() => new Date(now), [now])
const { address } = useAccount()
const { data: collectionData } = useFetchCollectionDetailsQuery({
const { data: collectionData, loading } = useFetchCollectionDetailsQuery({
variables: {
collectionAddress: collectionAddress,
chainId: chainId,
Expand All @@ -83,7 +84,7 @@ const CollectionPage: FC<Props> = ({ now }) => {
[currencyData],
)
const filter = useAssetFilterFromQuery(currencies)
const { data } = useFetchCollectionAssetsQuery({
const { data, loading: assetLoading } = useFetchCollectionAssetsQuery({
variables: {
collectionAddress,
now: date,
Expand Down Expand Up @@ -141,6 +142,7 @@ const CollectionPage: FC<Props> = ({ now }) => {

const [changePage, changeLimit] = usePaginate()

if (loading) return <Loader fullPage />
if (!collectionDetails) return null
return (
<LargeLayout>
Expand Down Expand Up @@ -216,6 +218,7 @@ const CollectionPage: FC<Props> = ({ now }) => {
</GridItem>
)}
<GridItem gap={6} colSpan={showFilters ? 1 : 2}>
{assetLoading && <Loader />}
{data?.assets?.totalCount && data?.assets?.totalCount > 0 ? (
<SimpleGrid
flexWrap="wrap"
Expand Down
5 changes: 4 additions & 1 deletion pages/create/[chainId]/[collectionAddress].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { useRouter } from 'next/router'
import React, { useCallback, useMemo, useState } from 'react'
import Head from '../../../components/Head'
import Link from '../../../components/Link/Link'
import Loader from '../../../components/Loader'
import BackButton from '../../../components/Navbar/BackButton'
import type { Props as NFTCardProps } from '../../../components/Token/Card'
import TokenCard from '../../../components/Token/Card'
Expand Down Expand Up @@ -62,7 +63,7 @@ const CreatePage: NextPage = ({}) => {
const { address } = useAccount()
const { data: config } = useConfig()
const toast = useToast()
const { data } = useFetchAccountAndCollectionQuery({
const { data, loading } = useFetchAccountAndCollectionQuery({
variables: {
chainId,
collectionAddress,
Expand Down Expand Up @@ -130,6 +131,8 @@ const CreatePage: NextPage = ({}) => {
[push, t, toast],
)

if (loading) return <Loader fullPage />

if (environment.RESTRICT_TO_VERIFIED_ACCOUNT && !creator.verified) {
return (
<Layout>
Expand Down
3 changes: 2 additions & 1 deletion pages/create/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import React from 'react'
import Empty from '../../components/Empty/Empty'
import Head from '../../components/Head'
import Link from '../../components/Link/Link'
import Loader from '../../components/Loader'
import BackButton from '../../components/Navbar/BackButton'
import environment from '../../environment'
import {
Expand Down Expand Up @@ -62,7 +63,7 @@ const CreatePage: NextPage = () => {
},
})

if (loading) return <></>
if (loading) return <Loader fullPage />

if (
environment.RESTRICT_TO_VERIFIED_ACCOUNT &&
Expand Down
4 changes: 2 additions & 2 deletions pages/explore/collections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const CollectionsPage: NextPage<Props> = ({}) => {
const { limit, offset, page } = usePaginateQuery()
const orderBy = useOrderByQuery<CollectionsOrderBy>('TOTAL_VOLUME_DESC')
const search = useQueryParamSingle('search')
const { data } = useFetchExploreCollectionsQuery({
const { data, loading } = useFetchExploreCollectionsQuery({
variables: {
limit,
offset,
Expand Down Expand Up @@ -83,7 +83,7 @@ const CollectionsPage: NextPage<Props> = ({}) => {

<ExploreTemplate
title={t('explore.title')}
loading={pageLoading || loadingOrder}
loading={pageLoading || loadingOrder || loading}
search={search}
selectedTabIndex={1}
>
Expand Down
4 changes: 2 additions & 2 deletions pages/explore/users.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const UsersPage: NextPage<Props> = () => {
const { t } = useTranslation('templates')
const { limit, offset, page } = usePaginateQuery()
const search = useQueryParamSingle('search')
const { data } = useFetchExploreUsersQuery({
const { data, loading } = useFetchExploreUsersQuery({
variables: {
limit,
offset,
Expand All @@ -50,7 +50,7 @@ const UsersPage: NextPage<Props> = () => {

<ExploreTemplate
title={t('explore.title')}
loading={pageLoading}
loading={pageLoading || loading}
search={search}
selectedTabIndex={2}
>
Expand Down
6 changes: 5 additions & 1 deletion pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { NextPage } from 'next'
import useTranslation from 'next-translate/useTranslation'
import { useCallback, useEffect, useMemo } from 'react'
import Link from '../components/Link/Link'
import Loader from '../components/Loader'
import Slider from '../components/Slider/Slider'
import TokenCard from '../components/Token/Card'
import TokenHeader from '../components/Token/Header'
Expand Down Expand Up @@ -58,7 +59,7 @@ const HomePage: NextPage<Props> = ({ now }) => {
return (tokensToRender?.assets?.nodes || []).map((x) => x.id)
}, [tokensToRender])

const { data, refetch, error } = useFetchHomePageQuery({
const { data, refetch, error, loading } = useFetchHomePageQuery({
variables: {
featuredIds: environment.FEATURED_TOKEN,
now: date,
Expand Down Expand Up @@ -119,6 +120,9 @@ const HomePage: NextPage<Props> = ({ now }) => {
)),
[featured, address, signer, reloadInfo, currencies],
)

if (loading) return <Loader fullPage />

return (
<LargeLayout>
{featuredAssets && featuredAssets.length > 0 && (
Expand Down
9 changes: 8 additions & 1 deletion pages/notification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useCallback, useEffect, useMemo, useState } from 'react'
import { useCookies } from 'react-cookie'
import Empty from '../components/Empty/Empty'
import Head from '../components/Head'
import Loader from '../components/Loader'
import NotificationDetail from '../components/Notification/Detail'
import { concatToQuery } from '../concat'
import { useGetNotificationsQuery } from '../graphql'
Expand All @@ -24,7 +25,11 @@ const NotificationPage: NextPage = ({}) => {
const [_, setCookies] = useCookies()
const [loading, setLoading] = useState(false)

const { data, fetchMore } = useGetNotificationsQuery({
const {
data,
fetchMore,
loading: fetching,
} = useGetNotificationsQuery({
variables: {
cursor: null,
address: address || '',
Expand Down Expand Up @@ -65,6 +70,8 @@ const NotificationPage: NextPage = ({}) => {
})
}, [address, setCookies])

if (fetching) return <Loader fullPage />

return (
<SmallLayout>
<Head title="Notifications" />
Expand Down
4 changes: 3 additions & 1 deletion pages/tokens/[id]/bid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { useCallback, useMemo } from 'react'
import Countdown from '../../../components/Countdown/Countdown'
import Head from '../../../components/Head'
import Image from '../../../components/Image/Image'
import Loader from '../../../components/Loader'
import BackButton from '../../../components/Navbar/BackButton'
import OfferFormBid from '../../../components/Offer/Form/Bid'
import Price from '../../../components/Price/Price'
Expand Down Expand Up @@ -51,7 +52,7 @@ const BidPage: NextPage<Props> = ({ now }) => {
const assetId = useRequiredQueryParamSingle('id')

const date = useMemo(() => new Date(now), [now])
const { data } = useBidOnAssetQuery({
const { data, loading } = useBidOnAssetQuery({
variables: {
id: assetId,
now: date,
Expand Down Expand Up @@ -95,6 +96,7 @@ const BidPage: NextPage<Props> = ({ now }) => {
await push(`/tokens/${assetId}`)
}, [toast, t, push, assetId])

if (loading) return <Loader fullPage />
if (!asset) return <></>
return (
<SmallLayout>
Expand Down
8 changes: 5 additions & 3 deletions pages/tokens/[id]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import BidList from '../../../components/Bid/BidList'
import Head from '../../../components/Head'
import HistoryList from '../../../components/History/HistoryList'
import ChakraLink from '../../../components/Link/Link'
import Loader from '../../../components/Loader'
import SaleDetail from '../../../components/Sales/Detail'
import TokenMedia from '../../../components/Token/Media'
import TokenMetadata from '../../../components/Token/Metadata'
Expand Down Expand Up @@ -83,7 +84,7 @@ const DetailPage: NextPage<Props> = ({ now: nowProp }) => {
const assetId = useRequiredQueryParamSingle('id')

const date = useMemo(() => new Date(nowProp), [nowProp])
const { data, refetch } = useFetchAssetQuery({
const { data, refetch, loading } = useFetchAssetQuery({
variables: {
id: assetId,
now: date,
Expand Down Expand Up @@ -226,6 +227,7 @@ const DetailPage: NextPage<Props> = ({ now: nowProp }) => {
[refetch, refreshAsset, toast],
)

if (loading) return <Loader fullPage />
if (!asset) return <></>
return (
<LargeLayout>
Expand Down Expand Up @@ -315,11 +317,11 @@ const DetailPage: NextPage<Props> = ({ now: nowProp }) => {
<Stack spacing={1}>
{asset.collection.name && (
<Heading as="p" variant="heading1" color="gray.500">
<Link
<ChakraLink
href={`/collection/${asset.collection.chainId}/${asset.collection.address}`}
>
{asset.collection.name}
</Link>
</ChakraLink>
</Heading>
)}
<Heading
Expand Down
4 changes: 3 additions & 1 deletion pages/tokens/[id]/offer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import useTranslation from 'next-translate/useTranslation'
import { useRouter } from 'next/router'
import { useCallback, useMemo, useState } from 'react'
import Head from '../../../components/Head'
import Loader from '../../../components/Loader'
import BackButton from '../../../components/Navbar/BackButton'
import Radio from '../../../components/Radio/Radio'
import SalesAuctionForm from '../../../components/Sales/Auction/Form'
Expand Down Expand Up @@ -74,7 +75,7 @@ const OfferPage: NextPage<Props> = ({ now }) => {
const assetId = useRequiredQueryParamSingle('id')

const date = useMemo(() => new Date(now), [now])
const { data } = useOfferForAssetQuery({
const { data, loading } = useOfferForAssetQuery({
variables: {
id: assetId,
now: date,
Expand Down Expand Up @@ -191,6 +192,7 @@ const OfferPage: NextPage<Props> = ({ now }) => {
onCreated,
])

if (loading) return <Loader fullPage />
if (!asset) return <></>
return (
<SmallLayout>
Expand Down
4 changes: 3 additions & 1 deletion pages/users/[id]/bids/placed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import Empty from '../../../../components/Empty/Empty'
import Head from '../../../../components/Head'
import Image from '../../../../components/Image/Image'
import Link from '../../../../components/Link/Link'
import Loader from '../../../../components/Loader'
import Pagination from '../../../../components/Pagination/Pagination'
import Price from '../../../../components/Price/Price'
import UserProfileTemplate from '../../../../components/Profile'
Expand Down Expand Up @@ -64,7 +65,7 @@ const BidPlacedPage: NextPage<Props> = ({ now }) => {
const ownerLoggedIn = useIsLoggedIn(userAddress)

const date = useMemo(() => new Date(now), [now])
const { data, refetch } = useFetchUserBidsPlacedQuery({
const { data, refetch, loading } = useFetchUserBidsPlacedQuery({
variables: {
address: userAddress,
limit,
Expand Down Expand Up @@ -102,6 +103,7 @@ const BidPlacedPage: NextPage<Props> = ({ now }) => {
},
[replace, pathname, query],
)
if (loading) return <Loader fullPage />
return (
<LargeLayout>
<Head
Expand Down
4 changes: 3 additions & 1 deletion pages/users/[id]/bids/received.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import Empty from '../../../../components/Empty/Empty'
import Head from '../../../../components/Head'
import Image from '../../../../components/Image/Image'
import Link from '../../../../components/Link/Link'
import Loader from '../../../../components/Loader'
import Pagination from '../../../../components/Pagination/Pagination'
import Price from '../../../../components/Price/Price'
import UserProfileTemplate from '../../../../components/Profile'
Expand Down Expand Up @@ -68,7 +69,7 @@ const BidReceivedPage: NextPage<Props> = ({ now }) => {
const ownerLoggedIn = useIsLoggedIn(userAddress)

const date = useMemo(() => new Date(now), [now])
const { data, refetch } = useFetchUserBidsReceivedQuery({
const { data, refetch, loading } = useFetchUserBidsReceivedQuery({
variables: {
address: userAddress,
limit,
Expand Down Expand Up @@ -107,6 +108,7 @@ const BidReceivedPage: NextPage<Props> = ({ now }) => {
[replace, pathname, query],
)

if (loading) return <Loader fullPage />
return (
<LargeLayout>
<Head
Expand Down
Loading

0 comments on commit e3fadeb

Please sign in to comment.