feat: use app router for site home
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import { useTranslation } from "next-i18next"
|
||||
"use client"
|
||||
|
||||
import { Disclosure } from "@headlessui/react"
|
||||
|
||||
import { BlockchainIcon } from "~/components/icons/BlockchainIcon"
|
||||
import { CSB_SCAN } from "~/lib/env"
|
||||
import { useTranslation } from "~/lib/i18n/client"
|
||||
import { toCid, toGateway, toIPFS } from "~/lib/ipfs-parser"
|
||||
import { ExpandedCharacter, ExpandedNote } from "~/lib/types"
|
||||
import { cn } from "~/lib/utils"
|
||||
@@ -13,7 +14,7 @@ export const BlockchainInfo: React.FC<{
|
||||
site?: ExpandedCharacter
|
||||
page?: ExpandedNote
|
||||
}> = ({ site, page }) => {
|
||||
const { t } = useTranslation(["common", "site"])
|
||||
const { t } = useTranslation("common")
|
||||
|
||||
const ipfs = (page ? page.metadata?.uri : site?.metadata?.uri) || ""
|
||||
const greenfieldId = useGetGreenfieldId(toCid(ipfs))
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
"use client"
|
||||
|
||||
import { useEffect, useState } from "react"
|
||||
|
||||
import { throttle } from "~/lib/utils"
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import { Trans } from "next-i18next"
|
||||
import Script from "next/script"
|
||||
import { useEffect, useState } from "react"
|
||||
|
||||
import { Logo } from "~/components/common/Logo"
|
||||
import { Platform } from "~/components/site/Platform"
|
||||
import { SITE_URL } from "~/lib/env"
|
||||
import { Trans } from "~/lib/i18n"
|
||||
import { ExpandedCharacter } from "~/lib/types"
|
||||
|
||||
import { DarkModeSwitch } from "../common/DarkModeSwitch"
|
||||
@@ -13,19 +12,13 @@ import { UniLink } from "../ui/UniLink"
|
||||
export const SiteFooter: React.FC<{
|
||||
site?: ExpandedCharacter
|
||||
}> = ({ site }) => {
|
||||
const [logoType, setLogoType] = useState<"svg" | "png" | "lottie">("svg")
|
||||
|
||||
useEffect(() => {
|
||||
setLogoType("lottie")
|
||||
}, [])
|
||||
|
||||
const LogoWithLink = () => {
|
||||
return (
|
||||
<UniLink
|
||||
href={SITE_URL}
|
||||
className="inline-flex items-center align-text-top mx-1"
|
||||
>
|
||||
<Logo type={logoType} width={20} height={20} autoplay={false} />
|
||||
<Logo type="lottie" width={20} height={20} autoplay={false} />
|
||||
</UniLink>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
"use client"
|
||||
|
||||
import chroma from "chroma-js"
|
||||
import { FastAverageColor } from "fast-average-color"
|
||||
import { useTranslation } from "next-i18next"
|
||||
import { useRouter } from "next/router"
|
||||
import { usePathname } from "next/navigation"
|
||||
import { MutableRefObject, RefObject, useEffect, useRef, useState } from "react"
|
||||
|
||||
import { XCharLogo, XFeedLogo } from "@crossbell/ui"
|
||||
@@ -17,6 +18,7 @@ import { Modal } from "~/components/ui/Modal"
|
||||
import { Tooltip } from "~/components/ui/Tooltip"
|
||||
import { useIsDark } from "~/hooks/useDarkMode"
|
||||
import { CSB_IO, CSB_SCAN, CSB_XCHAR } from "~/lib/env"
|
||||
import { useTranslation } from "~/lib/i18n/client"
|
||||
import { ExpandedCharacter } from "~/lib/types"
|
||||
import { getUserContentsUrl } from "~/lib/user-contents"
|
||||
import { cn } from "~/lib/utils"
|
||||
@@ -37,9 +39,9 @@ type HeaderLinkType = {
|
||||
const fac = new FastAverageColor()
|
||||
|
||||
const HeaderLink: React.FC<{ link: HeaderLinkType }> = ({ link }) => {
|
||||
const router = useRouter()
|
||||
const pathname = usePathname()
|
||||
const { t } = useTranslation("site")
|
||||
const active = router.asPath === link.url
|
||||
const active = pathname === link.url // TODO
|
||||
return (
|
||||
<UniLink
|
||||
href={link.url}
|
||||
|
||||
@@ -1,29 +1,30 @@
|
||||
import { useTranslation } from "next-i18next"
|
||||
"use client"
|
||||
|
||||
import Link from "next/link"
|
||||
import { useRouter } from "next/router"
|
||||
import { useRouter } from "next/navigation"
|
||||
import { useEffect, useState } from "react"
|
||||
|
||||
import type { InfiniteData } from "@tanstack/react-query"
|
||||
|
||||
import { Button } from "~/components/ui/Button"
|
||||
import { EmptyState } from "~/components/ui/EmptyState"
|
||||
import { Image } from "~/components/ui/Image"
|
||||
import { useDate } from "~/hooks/useDate"
|
||||
import { getSlugUrl } from "~/lib/helpers"
|
||||
import { ExpandedNote } from "~/lib/types"
|
||||
import { useTranslation } from "~/lib/i18n/client"
|
||||
import { PageVisibilityEnum } from "~/lib/types"
|
||||
import { useGetPagesBySiteLite } from "~/queries/page"
|
||||
import { useGetSite } from "~/queries/site"
|
||||
|
||||
import { EmptyState } from "../ui/EmptyState"
|
||||
|
||||
export const SiteHome: React.FC<{
|
||||
posts?: InfiniteData<{
|
||||
list: ExpandedNote[]
|
||||
count: number
|
||||
}>
|
||||
fetchNextPage: () => void
|
||||
hasNextPage?: boolean
|
||||
isFetchingNextPage?: boolean
|
||||
}> = ({ posts, fetchNextPage, hasNextPage, isFetchingNextPage }) => {
|
||||
export default function SiteHome({ handle }: { handle: string }) {
|
||||
const router = useRouter()
|
||||
const { t } = useTranslation(["common", "site"])
|
||||
const site = useGetSite(handle)
|
||||
const posts = useGetPagesBySiteLite({
|
||||
characterId: site.data?.characterId,
|
||||
type: "post",
|
||||
visibility: PageVisibilityEnum.Published,
|
||||
useStat: true,
|
||||
})
|
||||
|
||||
const { t } = useTranslation("site")
|
||||
const date = useDate()
|
||||
|
||||
const [isMounted, setIsMounted] = useState(false)
|
||||
@@ -32,16 +33,16 @@ export const SiteHome: React.FC<{
|
||||
setIsMounted(true)
|
||||
}, [])
|
||||
|
||||
if (!posts?.pages?.length) return null
|
||||
if (!posts.data?.pages?.length) return null
|
||||
|
||||
let currentLength = 0
|
||||
|
||||
return (
|
||||
<>
|
||||
{!posts.pages[0].count && <EmptyState />}
|
||||
{!!posts.pages[0].count && (
|
||||
{!posts.data.pages[0].count && <EmptyState />}
|
||||
{!!posts.data.pages[0].count && (
|
||||
<div className="xlog-posts space-y-8">
|
||||
{posts.pages.map((posts) =>
|
||||
{posts.data.pages.map((posts) =>
|
||||
posts.list.map((post) => {
|
||||
currentLength++
|
||||
return (
|
||||
@@ -127,20 +128,21 @@ export const SiteHome: React.FC<{
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
{hasNextPage && (
|
||||
{posts.hasNextPage && (
|
||||
<Button
|
||||
className="mt-8 w-full bg-zinc-50 text-sm"
|
||||
variant="text"
|
||||
onClick={fetchNextPage}
|
||||
isLoading={isFetchingNextPage}
|
||||
onClick={() => posts.fetchNextPage()}
|
||||
isLoading={posts.isFetchingNextPage}
|
||||
aria-label="load more"
|
||||
>
|
||||
{t("load more", {
|
||||
ns: "site",
|
||||
name: t(
|
||||
"post" + (posts?.pages[0].count - currentLength > 1 ? "s" : ""),
|
||||
"post" +
|
||||
(posts.data?.pages[0].count - currentLength > 1 ? "s" : ""),
|
||||
),
|
||||
count: posts?.pages[0].count - currentLength,
|
||||
count: posts.data?.pages[0].count - currentLength,
|
||||
})}
|
||||
</Button>
|
||||
)}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
"use client"
|
||||
|
||||
import React, { memo } from "react"
|
||||
|
||||
import { cn } from "~/lib/utils"
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
"use client"
|
||||
|
||||
import React, { FC, PropsWithChildren, useEffect, useState } from "react"
|
||||
|
||||
import { useGetState } from "~/hooks/useGetState"
|
||||
|
||||
Reference in New Issue
Block a user