Skip to content

Commit

Permalink
fix duplicate content urls
Browse files Browse the repository at this point in the history
  • Loading branch information
saml33 committed Dec 17, 2023
1 parent 9522b9a commit 76d4642
Show file tree
Hide file tree
Showing 15 changed files with 177 additions and 144 deletions.
22 changes: 0 additions & 22 deletions app/(pages)/explore/[category]/[slug]/layout.tsx

This file was deleted.

33 changes: 7 additions & 26 deletions app/(pages)/explore/[category]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,12 @@ import { Metadata } from 'next'
import { draftMode } from 'next/headers'
import { notFound } from 'next/navigation'
import { fetchTokenPagesForCategory } from '../../../../contentful/tokenPage'
import DataDisclaimer from '../../../components/explore/DataDisclaimer'
import {
fetchTokenCategoryPage,
fetchTokenCategoryPages,
} from '../../../../contentful/tokenCategoryPage'
import RichTextDisplay from '../../../components/shared/RichTextDisplay'
import { fetchMangoTokenData } from '../../../utils/mango'
import TokenTable from '../../../components/explore/TokenTable'
import CategorySwitcher from '../../../components/explore/CategorySwitcher'

const SECTION_WRAPPER_CLASSES = 'border-t border-th-bkg-3 pt-6 mt-12'
import Category from '../../../components/explore/Category'

interface TokenCategoryPageParams {
category: string
Expand Down Expand Up @@ -62,7 +57,7 @@ async function TokenCategoryPage({ params }: TokenCategoryPageProps) {
return notFound()
}

const { category, description, slug } = tokenCategoryPageData
const { category } = tokenCategoryPageData

// fetch token pages from contentful where the entry contains the category (tag)
const tokensForCategory = await fetchTokenPagesForCategory({
Expand All @@ -77,25 +72,11 @@ async function TokenCategoryPage({ params }: TokenCategoryPageProps) {
const mangoTokensData = await Promise.all(promises)

return (
<>
<div className="mb-10 flex flex-col lg:flex-row lg:items-center lg:justify-between">
<h1 className="text-4xl mb-4 lg:mb-0">{`Explore ${category}`}</h1>
<CategorySwitcher tokens={tokensForCategory} />
</div>
<TokenTable
tokens={tokensForCategory}
mangoTokensData={mangoTokensData}
showTableView
categorySlug={slug}
/>
{description ? (
<div className={SECTION_WRAPPER_CLASSES}>
<h2 className="mb-4 text-2xl">{`About ${category}`}</h2>
<RichTextDisplay content={description} />
</div>
) : null}
<DataDisclaimer />
</>
<Category
categoryPageData={tokenCategoryPageData}
tokensForCategory={tokensForCategory}
mangoTokensData={mangoTokensData}
/>
)
}

Expand Down
24 changes: 24 additions & 0 deletions app/(pages)/token/[slug]/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { ArrowLeftIcon } from '@heroicons/react/20/solid'
import Link from 'next/link'

export default function TokenPageLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<div className="px-6 lg:px-20 pb-12 pt-8 max-w-[1280px] mx-auto min-h-screen">
<div className="-mt-6">
<Link
className="text-th-fgd-4 flex items-center space-x-1"
href="/explore"
shallow
>
<ArrowLeftIcon className="h-5 w-5" />
<span>View all tokens</span>
</Link>
<div className="mt-8">{children}</div>
</div>
</div>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,22 @@ import { notFound } from 'next/navigation'
import {
fetchTokenPage,
fetchTokenPages,
} from '../../../../../contentful/tokenPage'
import { CUSTOM_TOKEN_ICONS } from '../../../../utils/constants'
import RichTextDisplay from '../../../../components/shared/RichTextDisplay'
import {
fetchMangoMarketData,
fetchMangoTokenData,
} from '../../../../utils/mango'
import { MangoMarketsData, MangoTokenData } from '../../../../types/mango'
} from '../../../../contentful/tokenPage'
import { CUSTOM_TOKEN_ICONS } from '../../../utils/constants'
import RichTextDisplay from '../../../components/shared/RichTextDisplay'
import { fetchMangoMarketData, fetchMangoTokenData } from '../../../utils/mango'
import { MangoMarketsData, MangoTokenData } from '../../../types/mango'
import Image from 'next/image'
import TokenMangoStats from '../../../../components/explore/token-page/TokenMangoStats'
import { fetchCoingeckoData } from '../../../../utils/coingecko'
import { CoingeckoData } from '../../../../types/coingecko'
import DailyRange from '../../../../components/explore/token-page/DailyRange'
import Links from '../../../../components/explore/token-page/Links'
import TokenInfo from '../../../../components/explore/token-page/TokenInfo'
import TokenMangoStats from '../../../components/explore/token-page/TokenMangoStats'
import { fetchCoingeckoData } from '../../../utils/coingecko'
import { CoingeckoData } from '../../../types/coingecko'
import DailyRange from '../../../components/explore/token-page/DailyRange'
import Links from '../../../components/explore/token-page/Links'
import TokenInfo from '../../../components/explore/token-page/TokenInfo'
import dynamic from 'next/dynamic'
import DataDisclaimer from '../../../../components/explore/DataDisclaimer'
import DataDisclaimer from '../../../components/explore/DataDisclaimer'
const TokenPriceChart = dynamic(
() => import('../../../../components/explore/token-page/TokenPriceChart'),
() => import('../../../components/explore/token-page/TokenPriceChart'),
{ ssr: false },
)

Expand Down
60 changes: 60 additions & 0 deletions app/components/explore/Category.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
'use client'

import { useMemo, useState } from 'react'
import { TokenPageWithData } from '../../../contentful/tokenPage'
import { MangoTokenData } from '../../types/mango'
import CategorySwitcher from './CategorySwitcher'
import TableViewToggle from './TableViewToggle'
import TokenTable from './TokenTable'
import { TokenCategoryPage } from '../../../contentful/tokenCategoryPage'
import RichTextDisplay from '../shared/RichTextDisplay'
import DataDisclaimer from './DataDisclaimer'
import { sortTokens } from './Explore'

const SECTION_WRAPPER_CLASSES = 'border-t border-th-bkg-3 pt-6 mt-12'

const Category = ({
categoryPageData,
tokensForCategory,
mangoTokensData,
}: {
categoryPageData: TokenCategoryPage
tokensForCategory: TokenPageWithData[]
mangoTokensData: MangoTokenData[]
}) => {
const [showTableView, setShowTableView] = useState(true)
const { category, description } = categoryPageData

const sortedTokens = useMemo(() => {
return sortTokens(tokensForCategory)
}, [tokensForCategory])

return (
<>
<div className="mb-10 flex flex-col lg:flex-row lg:items-center lg:justify-between">
<h1 className="text-4xl mb-4 lg:mb-0">{`Explore ${category}`}</h1>
<div className="flex space-x-2">
<CategorySwitcher tokens={tokensForCategory} />
<TableViewToggle
showTableView={showTableView}
setShowTableView={setShowTableView}
/>
</div>
</div>
<TokenTable
tokens={sortedTokens}
mangoTokensData={mangoTokensData}
showTableView={showTableView}
/>
{description ? (
<div className={SECTION_WRAPPER_CLASSES}>
<h2 className="mb-4 text-2xl">{`About ${category}`}</h2>
<RichTextDisplay content={description} />
</div>
) : null}
<DataDisclaimer />
</>
)
}

export default Category
4 changes: 1 addition & 3 deletions app/components/explore/CategorySwitcher.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
'use client'

import { useEffect, useMemo, useState } from 'react'
import Select from '../forms/Select'
import { TokenPageWithData } from '../../../contentful/tokenPage'
import { AppRouterInstance } from 'next/dist/shared/lib/app-router-context.shared-runtime'
import { useParams, useRouter } from 'next/navigation'
import { tagToSlug } from './TokenTable'
import { tagToSlug } from '../../utils'

const goToCategoryPage = (categorySlug: string, router: AppRouterInstance) => {
router.push(`/explore/${categorySlug}`)
Expand Down
43 changes: 8 additions & 35 deletions app/components/explore/Explore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@

import { TokenPageWithData } from '../../../contentful/tokenPage'
import { MangoTokenData } from '../../types/mango'
import {
MagnifyingGlassIcon,
Squares2X2Icon,
TableCellsIcon,
} from '@heroicons/react/20/solid'
import { ChangeEvent, useEffect, useMemo, useState } from 'react'
import { MagnifyingGlassIcon } from '@heroicons/react/20/solid'
import { ChangeEvent, useMemo, useState } from 'react'
import Input from '../forms/Input'
import { useViewport } from '../../hooks/useViewport'
import DataDisclaimer from './DataDisclaimer'
import TokenTable from './TokenTable'
import CategorySwitcher from './CategorySwitcher'
import TableViewToggle from './TableViewToggle'

const generateSearchTerm = (item: TokenPageWithData, searchValue: string) => {
const normalizedSearchValue = searchValue.toLowerCase()
Expand Down Expand Up @@ -51,7 +47,7 @@ const startSearch = (items: TokenPageWithData[], searchValue: string) => {
.map((item) => item.token)
}

const sortTokens = (tokens: TokenPageWithData[]) => {
export const sortTokens = (tokens: TokenPageWithData[]) => {
return tokens.sort((a, b) => {
const aValue = a?.birdeyeData?.v24hUSD
const bValue = b?.birdeyeData?.v24hUSD
Expand All @@ -75,7 +71,6 @@ const Explore = ({
tokens: TokenPageWithData[]
mangoTokensData: MangoTokenData[]
}) => {
const { isDesktop } = useViewport()
const [showTableView, setShowTableView] = useState(true)
const [searchString, setSearchString] = useState('')

Expand All @@ -87,10 +82,6 @@ const Explore = ({
setSearchString(e.target.value)
}

const [mounted, setMounted] = useState(false)
useEffect(() => setMounted(true), [])
if (!mounted) return null

return (
<>
<div className="mb-10 flex flex-col lg:flex-row lg:items-center lg:justify-between">
Expand All @@ -106,28 +97,10 @@ const Explore = ({
/>
<MagnifyingGlassIcon className="absolute left-2 top-3 h-4 w-4 text-th-fgd-3" />
</div>
{isDesktop ? (
<div className="flex h-10">
<button
className={`flex w-10 items-center justify-center rounded-l-md border border-th-input-border border-r-0 focus:outline-none md:hover:bg-th-bkg-3 ${
showTableView ? 'bg-th-bkg-3 text-th-active' : 'text-th-fgd-3'
}`}
onClick={() => setShowTableView(!showTableView)}
>
<TableCellsIcon className="h-5 w-5" />
</button>
<button
className={`flex w-10 items-center justify-center rounded-r-md border border-th-input-border border-l-0 focus:outline-none md:hover:bg-th-bkg-3 ${
!showTableView
? 'bg-th-bkg-3 text-th-active'
: 'text-th-fgd-3'
}`}
onClick={() => setShowTableView(!showTableView)}
>
<Squares2X2Icon className="h-5 w-5" />
</button>
</div>
) : null}
<TableViewToggle
showTableView={showTableView}
setShowTableView={setShowTableView}
/>
</div>
</div>
<TokenTable
Expand Down
32 changes: 32 additions & 0 deletions app/components/explore/TableViewToggle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Squares2X2Icon, TableCellsIcon } from '@heroicons/react/20/solid'

const TableViewToggle = ({
showTableView,
setShowTableView,
}: {
showTableView: boolean
setShowTableView: (show: boolean) => void
}) => {
return (
<div className="h-10 hidden lg:flex">
<button
className={`flex w-10 items-center justify-center rounded-l-md border border-th-input-border border-r-0 focus:outline-none md:hover:bg-th-bkg-3 ${
showTableView ? 'bg-th-bkg-3 text-th-active' : 'text-th-fgd-3'
}`}
onClick={() => setShowTableView(!showTableView)}
>
<TableCellsIcon className="h-5 w-5" />
</button>
<button
className={`flex w-10 items-center justify-center rounded-r-md border border-th-input-border border-l-0 focus:outline-none md:hover:bg-th-bkg-3 ${
!showTableView ? 'bg-th-bkg-3 text-th-active' : 'text-th-fgd-3'
}`}
onClick={() => setShowTableView(!showTableView)}
>
<Squares2X2Icon className="h-5 w-5" />
</button>
</div>
)
}

export default TableViewToggle
5 changes: 2 additions & 3 deletions app/components/explore/TokenCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from '@heroicons/react/20/solid'
import { CUSTOM_TOKEN_ICONS } from '../../utils/constants'
import Link from 'next/link'
import { FormattedTableData, tagToSlug } from './TokenTable'
import { FormattedTableData } from './TokenTable'

const TokenCard = ({ token }: { token: FormattedTableData }) => {
const {
Expand All @@ -22,7 +22,6 @@ const TokenCard = ({ token }: { token: FormattedTableData }) => {
logoURI,
symbol,
slug,
tags,
} = token
const hasCustomIcon = mangoSymbol
? CUSTOM_TOKEN_ICONS[mangoSymbol.toLowerCase()]
Expand Down Expand Up @@ -91,7 +90,7 @@ const TokenCard = ({ token }: { token: FormattedTableData }) => {
</div>
<Link
className="flex items-center justify-between border border-th-bkg-4 py-3 px-4 mx-auto w-full rounded-lg text-sm font-display text-th-fgd-2 mt-6"
href={`/explore/${tagToSlug(tags[0])}/${slug}`}
href={`/token/${slug}`}
>
<span>Stats and info</span>
<ChevronRightIcon className="h-5 w-5 text-th-fgd-3" />
Expand Down
Loading

0 comments on commit 76d4642

Please sign in to comment.