Commit 9f8355ed authored by vignesh mohankumar's avatar vignesh mohankumar Committed by GitHub

refactor: useIsNftPage hooks (#5142)

parent c5bed1c6
...@@ -3,6 +3,7 @@ import { useWeb3React } from '@web3-react/core' ...@@ -3,6 +3,7 @@ import { useWeb3React } from '@web3-react/core'
import Web3Status from 'components/Web3Status' import Web3Status from 'components/Web3Status'
import { NftVariant, useNftFlag } from 'featureFlags/flags/nft' import { NftVariant, useNftFlag } from 'featureFlags/flags/nft'
import { chainIdToBackendName } from 'graphql/data/util' import { chainIdToBackendName } from 'graphql/data/util'
import { useIsNftPage } from 'hooks/useIsNftPage'
import { Box } from 'nft/components/Box' import { Box } from 'nft/components/Box'
import { Row } from 'nft/components/Flex' import { Row } from 'nft/components/Flex'
import { UniIcon } from 'nft/components/icons' import { UniIcon } from 'nft/components/icons'
...@@ -48,6 +49,8 @@ const PageTabs = () => { ...@@ -48,6 +49,8 @@ const PageTabs = () => {
pathname.startsWith('/increase') || pathname.startsWith('/increase') ||
pathname.startsWith('/find') pathname.startsWith('/find')
const isNftPage = useIsNftPage()
return ( return (
<> <>
<MenuItem href="/swap" isActive={pathname.startsWith('/swap')}> <MenuItem href="/swap" isActive={pathname.startsWith('/swap')}>
...@@ -57,7 +60,7 @@ const PageTabs = () => { ...@@ -57,7 +60,7 @@ const PageTabs = () => {
<Trans>Tokens</Trans> <Trans>Tokens</Trans>
</MenuItem> </MenuItem>
{nftFlag === NftVariant.Enabled && ( {nftFlag === NftVariant.Enabled && (
<MenuItem href="/nfts" isActive={pathname.startsWith('/nfts')}> <MenuItem href="/nfts" isActive={isNftPage}>
<Trans>NFTs</Trans> <Trans>NFTs</Trans>
</MenuItem> </MenuItem>
)} )}
...@@ -69,8 +72,7 @@ const PageTabs = () => { ...@@ -69,8 +72,7 @@ const PageTabs = () => {
} }
const Navbar = () => { const Navbar = () => {
const { pathname } = useLocation() const isNftPage = useIsNftPage()
const isNftPage = pathname.startsWith('/nfts')
return ( return (
<> <>
......
import { useLocation } from 'react-router-dom'
export function useIsNftPage() {
const { pathname } = useLocation()
return pathname.startsWith('/nfts')
}
export function useIsNftProfilePage() {
const { pathname } = useLocation()
return pathname.startsWith('/nfts/profile')
}
export function useIsNftDetailsPage() {
const { pathname } = useLocation()
return pathname.startsWith('/nfts/asset')
}
import { BigNumber } from '@ethersproject/bignumber' import { BigNumber } from '@ethersproject/bignumber'
import { formatEther } from '@ethersproject/units' import { formatEther } from '@ethersproject/units'
import { useWeb3React } from '@web3-react/core' import { useWeb3React } from '@web3-react/core'
import { useIsNftDetailsPage, useIsNftPage, useIsNftProfilePage } from 'hooks/useIsNftPage'
import { BagFooter } from 'nft/components/bag/BagFooter' import { BagFooter } from 'nft/components/bag/BagFooter'
import ListingModal from 'nft/components/bag/profile/ListingModal' import ListingModal from 'nft/components/bag/profile/ListingModal'
import { Box } from 'nft/components/Box' import { Box } from 'nft/components/Box'
...@@ -28,7 +29,6 @@ import { ...@@ -28,7 +29,6 @@ import {
import { combineBuyItemsWithTxRoute } from 'nft/utils/txRoute/combineItemsWithTxRoute' import { combineBuyItemsWithTxRoute } from 'nft/utils/txRoute/combineItemsWithTxRoute'
import { useCallback, useEffect, useMemo, useRef, useState } from 'react' import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
import { useQuery, useQueryClient } from 'react-query' import { useQuery, useQueryClient } from 'react-query'
import { useLocation } from 'react-router-dom'
import styled from 'styled-components/macro' import styled from 'styled-components/macro'
import shallow from 'zustand/shallow' import shallow from 'zustand/shallow'
...@@ -100,13 +100,11 @@ const Bag = () => { ...@@ -100,13 +100,11 @@ const Bag = () => {
} = useBag((state) => ({ ...state, bagIsLocked: state.isLocked, uncheckedItemsInBag: state.itemsInBag }), shallow) } = useBag((state) => ({ ...state, bagIsLocked: state.isLocked, uncheckedItemsInBag: state.itemsInBag }), shallow)
const { uncheckedItemsInBag } = useBag(({ itemsInBag }) => ({ uncheckedItemsInBag: itemsInBag })) const { uncheckedItemsInBag } = useBag(({ itemsInBag }) => ({ uncheckedItemsInBag: itemsInBag }))
const { pathname } = useLocation() const isProfilePage = useIsNftProfilePage()
const isProfilePage = pathname.startsWith('/nfts/profile') const isDetailsPage = useIsNftDetailsPage()
const isNFTPage = pathname.startsWith('/nfts') const isNFTPage = useIsNftPage()
const isMobile = useIsMobile() const isMobile = useIsMobile()
const isDetailsPage = pathname.includes('/nfts/asset/')
const sendTransaction = useSendTransaction((state) => state.sendTransaction) const sendTransaction = useSendTransaction((state) => state.sendTransaction)
const transactionState = useSendTransaction((state) => state.state) const transactionState = useSendTransaction((state) => state.state)
const setTransactionState = useSendTransaction((state) => state.setState) const setTransactionState = useSendTransaction((state) => state.setState)
......
import { useIsNftProfilePage } from 'hooks/useIsNftPage'
import { Center, Column } from 'nft/components/Flex' import { Center, Column } from 'nft/components/Flex'
import { LargeBagIcon, LargeTagIcon } from 'nft/components/icons' import { LargeBagIcon, LargeTagIcon } from 'nft/components/icons'
import { subhead } from 'nft/css/common.css' import { subhead } from 'nft/css/common.css'
import { themeVars } from 'nft/css/sprinkles.css' import { themeVars } from 'nft/css/sprinkles.css'
import { useLocation } from 'react-router-dom'
import styled from 'styled-components/macro' import styled from 'styled-components/macro'
const StyledColumn = styled(Column)<{ isProfilePage?: boolean }>` const StyledColumn = styled(Column)<{ isProfilePage?: boolean }>`
...@@ -14,8 +14,7 @@ const StyledColumn = styled(Column)<{ isProfilePage?: boolean }>` ...@@ -14,8 +14,7 @@ const StyledColumn = styled(Column)<{ isProfilePage?: boolean }>`
` `
const EmptyState = () => { const EmptyState = () => {
const { pathname } = useLocation() const isProfilePage = useIsNftProfilePage()
const isProfilePage = pathname.startsWith('/nfts/profile')
return ( return (
<StyledColumn isProfilePage={isProfilePage}> <StyledColumn isProfilePage={isProfilePage}>
......
import { useWeb3React } from '@web3-react/core' import { useWeb3React } from '@web3-react/core'
import { useIsNftPage } from 'hooks/useIsNftPage'
import { useEffect } from 'react' import { useEffect } from 'react'
import { useLocation } from 'react-router-dom'
import { useDarkModeManager } from 'state/user/hooks' import { useDarkModeManager } from 'state/user/hooks'
import { SupportedChainId } from '../constants/chains' import { SupportedChainId } from '../constants/chains'
...@@ -29,8 +29,7 @@ const setBackground = (newValues: TargetBackgroundStyles) => ...@@ -29,8 +29,7 @@ const setBackground = (newValues: TargetBackgroundStyles) =>
export default function RadialGradientByChainUpdater(): null { export default function RadialGradientByChainUpdater(): null {
const { chainId } = useWeb3React() const { chainId } = useWeb3React()
const [darkMode] = useDarkModeManager() const [darkMode] = useDarkModeManager()
const { pathname } = useLocation() const isNftPage = useIsNftPage()
const isNftPage = pathname.startsWith('/nfts')
// manage background color // manage background color
useEffect(() => { useEffect(() => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment