From 5d9194787bf64c203090de7ff62cdb8aa7d6ff73 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Sun, 7 May 2023 17:12:17 +0100 Subject: [PATCH] feat: use app router for site home --- next-env.d.ts | 1 - public/locales/en/common.json | 3 +- public/locales/en/site.json | 3 +- public/locales/ja/common.json | 3 +- public/locales/ja/site.json | 1 - public/locales/zh-TW/common.json | 171 ++++++++++++----------- public/locales/zh-TW/site.json | 1 - public/locales/zh/common.json | 3 +- public/locales/zh/site.json | 1 - src/app/site/[site]/layout.tsx | 157 +++++++++++++++++++++ src/app/site/[site]/page.tsx | 38 +++++ src/components/common/BlockchainInfo.tsx | 5 +- src/components/site/BackToTopFAB.tsx | 2 + src/components/site/SiteFooter.tsx | 11 +- src/components/site/SiteHeader.tsx | 10 +- src/components/site/SiteHome.tsx | 54 +++---- src/components/ui/Button.tsx | 2 + src/components/ui/FAB.tsx | 2 + src/hooks/useDate.ts | 3 +- src/hooks/useDateServer.ts | 42 ++++++ src/lib/helpers.ts | 2 +- src/lib/i18n/client.ts | 4 +- src/lib/i18n/index.ts | 4 +- src/lib/types.ts | 2 +- src/middleware.ts | 2 +- src/queries/page.ts | 75 +++++----- 26 files changed, 422 insertions(+), 180 deletions(-) create mode 100644 src/app/site/[site]/layout.tsx create mode 100644 src/app/site/[site]/page.tsx create mode 100644 src/hooks/useDateServer.ts diff --git a/next-env.d.ts b/next-env.d.ts index fd36f949..4f11a03d 100644 --- a/next-env.d.ts +++ b/next-env.d.ts @@ -1,6 +1,5 @@ /// /// -/// // NOTE: This file should not be edited // see https://nextjs.org/docs/basic-features/typescript for more information. diff --git a/public/locales/en/common.json b/public/locales/en/common.json index 34fbe517..c2fdc139 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -1,5 +1,6 @@ { "intlDateTime": "{{val, datetime}}", "ago": "{{time}} ago", - "joined ago": "Joined {{time}} ago" + "joined ago": "Joined {{time}} ago", + "signed and stored on the blockchain": "Ownership of this {{name}} data is guaranteed by blockchain and smart contracts to the creator alone." } \ No newline at end of file diff --git a/public/locales/en/site.json b/public/locales/en/site.json index 0fe088ce..a673d1bd 100644 --- a/public/locales/en/site.json +++ b/public/locales/en/site.json @@ -1,4 +1,3 @@ { - "load more": "There are {{count}} more {{name}}, click to load more", - "signed and stored on the blockchain": "Ownership of this {{name}} data is guaranteed by blockchain and smart contracts to the creator alone." + "load more": "There are {{count}} more {{name}}, click to load more" } \ No newline at end of file diff --git a/public/locales/ja/common.json b/public/locales/ja/common.json index 2dd0cc98..63ad2c82 100644 --- a/public/locales/ja/common.json +++ b/public/locales/ja/common.json @@ -55,5 +55,6 @@ "Showcase": "ショーケース", "AI-generated summary": "AIが生成した要約", "Generating": "生成中", - "Show more": "もっと表示する" + "Show more": "もっと表示する", + "signed and stored on the blockchain": "{{name}}は、創作者によって署名され、ブロックチェーンに安全に保存されています。" } diff --git a/public/locales/ja/site.json b/public/locales/ja/site.json index 626c40f4..2ceee34b 100644 --- a/public/locales/ja/site.json +++ b/public/locales/ja/site.json @@ -4,7 +4,6 @@ "About": "紹介", "Tags": "タグ", "load more": "まだ{{count}}件の{{name}}があります。", - "signed and stored on the blockchain": "{{name}}は、創作者によって署名され、ブロックチェーンに安全に保存されています。", "Write a comment on the blockchain": "ブロックチェーンでコメントする", "powered by": "このサイトは  によって作動します" } diff --git a/public/locales/zh-TW/common.json b/public/locales/zh-TW/common.json index 37245f2e..a64f43fe 100644 --- a/public/locales/zh-TW/common.json +++ b/public/locales/zh-TW/common.json @@ -1,87 +1,88 @@ { - "Connect": "連線", - "Followers": "粉絲", - "Following": "追蹤中", - "Followings": "追蹤中", - "Follow": "追蹤", - "Unfollow": "取消追蹤", - "intlDateTime": "{{val, datetime}}", - "post": "文章", - "posts": "文章", - "page": "頁面", - "pages": "頁面", - "comment": "留言", - "comments": "留言", - "Comment": "留言", - "Comments": "留言", - "reply": "回覆", - "replies": "回覆", - "like": "讚", - "likes": "讚", - "blog": "部落格", - "Owner": "擁有者", - "Transaction Hash": "交易雜湊值", - "IPFS Address": "IPFS 位址", - "BNB Greenfield Address": "BNB Greenfield 位址", - "Creation": "創建", - "Last Update": "最後更新", - "Create Character": "創建身份", - "Submit": "提交", - "Reply": "回覆", - "Cancel Reply": "取消回覆", - "Edit": "編輯", - "Cancel Edit": "取消編輯", - "Confirm Modification": "確認編輯", - "ago": "{{time}}前", - "joined ago": "{{time}}前加入", - "obtained ago": "{{time}}前獲得", - "Like": "點讚", - "Mint to an NFT": "珍藏為 NFT", - "Like successfully": "點讚成功", - "Mint successfully": "珍藏完成~", - "like stored": "你的點讚已被安全地儲存在區塊鏈上,可以在 <2>Crossbell Scan 上查看", - "mint stored": "你已將這篇文章珍藏成 NFT,可以在 <2>xChar 或 <6>Crossbell Scan 上查看", - "Got it, thanks!": "知道啦,感恩的心~", - "Like List": "按讚列表", - "Mint List": "珍藏列表", - "Revert": "收回", - "Confirm to revert": "確定收回", - "like revert": "請確定是否想要收回這個點讚操作?", - "Cancel": "算了", - "Confirm": "確定", - "No Content Yet.": "什麼都沒", - "Close": "關閉", - "Dashboard": "主控臺", - "Copied!": "拷貝完成", - "Operator Sign": "簽名授權", - "Switch Characters": "切換身份", - "Upgrade to Wallet": "升級為錢包認證", - "Disconnect": "中斷連線", - "Loading": "載入中...", - "Showcase": "展示櫃", - "AI-generated summary": "AI 生成的摘要", - "Generating": "生成中...", - "Show more": "顯示更多", - "Patron": "贊助", - "Become a patron of {{name}}": "成為 {{name}} 的贊助者", - "Latest patrons": "最新贊助者", - "Latest tipper": "最新贊助者", - "You are here to be the first patron.": "你是第一位贊助者。", - "You are here to be the first tipper.": "你是第一位贊助者。", - "Select a tier": "選擇一個等級", - "One-time": "一次性", - "Monthly and NFT Rewards": "每月和 NFT 獎勵", - "Coming soon": "即將推出", - "What is MIRA? Where can I get some?": "MIRA 是什麼?能吃嗎?我在哪裡可以獲得?", - "Tip": "贊助", - "Tip the post: {{name}}": "贊助文章:{{name}}", - "Custom": "自訂", - "Mintable": "Mintable", - "Successfully followed": "嘿!你已經開始<2>追蹤他們的最新動態囉。", - "Enable AI Filtering": "AI 過濾", - "Filter out possible low-quality content based on AI ratings.": "基於 AI 評分過濾可能不佳的內容", - "Refreshing": "重新載入中", - "Search for your interest": "搜你所想", - "results": "項結果", - "My xLog": "你的 xLog" + "Connect": "連線", + "Followers": "粉絲", + "Following": "追蹤中", + "Followings": "追蹤中", + "Follow": "追蹤", + "Unfollow": "取消追蹤", + "intlDateTime": "{{val, datetime}}", + "post": "文章", + "posts": "文章", + "page": "頁面", + "pages": "頁面", + "comment": "留言", + "comments": "留言", + "Comment": "留言", + "Comments": "留言", + "reply": "回覆", + "replies": "回覆", + "like": "讚", + "likes": "讚", + "blog": "部落格", + "Owner": "擁有者", + "Transaction Hash": "交易雜湊值", + "IPFS Address": "IPFS 位址", + "BNB Greenfield Address": "BNB Greenfield 位址", + "Creation": "創建", + "Last Update": "最後更新", + "Create Character": "創建身份", + "Submit": "提交", + "Reply": "回覆", + "Cancel Reply": "取消回覆", + "Edit": "編輯", + "Cancel Edit": "取消編輯", + "Confirm Modification": "確認編輯", + "ago": "{{time}}前", + "joined ago": "{{time}}前加入", + "obtained ago": "{{time}}前獲得", + "Like": "點讚", + "Mint to an NFT": "珍藏為 NFT", + "Like successfully": "點讚成功", + "Mint successfully": "珍藏完成~", + "like stored": "你的點讚已被安全地儲存在區塊鏈上,可以在 <2>Crossbell Scan 上查看", + "mint stored": "你已將這篇文章珍藏成 NFT,可以在 <2>xChar 或 <6>Crossbell Scan 上查看", + "Got it, thanks!": "知道啦,感恩的心~", + "Like List": "按讚列表", + "Mint List": "珍藏列表", + "Revert": "收回", + "Confirm to revert": "確定收回", + "like revert": "請確定是否想要收回這個點讚操作?", + "Cancel": "算了", + "Confirm": "確定", + "No Content Yet.": "什麼都沒", + "Close": "關閉", + "Dashboard": "主控臺", + "Copied!": "拷貝完成", + "Operator Sign": "簽名授權", + "Switch Characters": "切換身份", + "Upgrade to Wallet": "升級為錢包認證", + "Disconnect": "中斷連線", + "Loading": "載入中...", + "Showcase": "展示櫃", + "AI-generated summary": "AI 生成的摘要", + "Generating": "生成中...", + "Show more": "顯示更多", + "Patron": "贊助", + "Become a patron of {{name}}": "成為 {{name}} 的贊助者", + "Latest patrons": "最新贊助者", + "Latest tipper": "最新贊助者", + "You are here to be the first patron.": "你是第一位贊助者。", + "You are here to be the first tipper.": "你是第一位贊助者。", + "Select a tier": "選擇一個等級", + "One-time": "一次性", + "Monthly and NFT Rewards": "每月和 NFT 獎勵", + "Coming soon": "即將推出", + "What is MIRA? Where can I get some?": "MIRA 是什麼?能吃嗎?我在哪裡可以獲得?", + "Tip": "贊助", + "Tip the post: {{name}}": "贊助文章:{{name}}", + "Custom": "自訂", + "Mintable": "Mintable", + "Successfully followed": "嘿!你已經開始<2>追蹤他們的最新動態囉。", + "Enable AI Filtering": "AI 過濾", + "Filter out possible low-quality content based on AI ratings.": "基於 AI 評分過濾可能不佳的內容", + "Refreshing": "重新載入中", + "Search for your interest": "搜你所想", + "results": "項結果", + "My xLog": "你的 xLog", + "signed and stored on the blockchain": "此{{name}}數據所有權由區塊鏈加密技術和智能合約保障僅歸創作者所有。" } \ No newline at end of file diff --git a/public/locales/zh-TW/site.json b/public/locales/zh-TW/site.json index c2710677..b2c42af1 100644 --- a/public/locales/zh-TW/site.json +++ b/public/locales/zh-TW/site.json @@ -4,7 +4,6 @@ "About": "關於", "Tags": "標籤", "load more": "還有{{count}}篇{{name}},點選載入更多文章", - "signed and stored on the blockchain": "此{{name}}數據所有權由區塊鏈加密技術和智能合約保障僅歸創作者所有。", "Write a comment on the blockchain": "在區塊鏈上留言。", "powered by": " 提供支援", "This address is in local editing preview mode and cannot be viewed by the public.": "此地址處於本地編輯預覽模式,尚未公開。", diff --git a/public/locales/zh/common.json b/public/locales/zh/common.json index 2918aace..4febe2b0 100644 --- a/public/locales/zh/common.json +++ b/public/locales/zh/common.json @@ -83,5 +83,6 @@ "Refreshing": "刷新中", "Search for your interest": "搜索你感兴趣的内容", "results": "条结果", - "My xLog": "我的 xLog" + "My xLog": "我的 xLog", + "signed and stored on the blockchain": "此{{name}}数据所有权由区块链加密技术和智能合约保障仅归创作者所有。" } diff --git a/public/locales/zh/site.json b/public/locales/zh/site.json index 1926e4a1..734dcfbd 100644 --- a/public/locales/zh/site.json +++ b/public/locales/zh/site.json @@ -4,7 +4,6 @@ "About": "关于", "Tags": "标签", "load more": "还有 {{count}} 篇{{name}},点击加载更多", - "signed and stored on the blockchain": "此{{name}}数据所有权由区块链加密技术和智能合约保障仅归创作者所有。", "Write a comment on the blockchain": "在区块链上写下你的评论", "powered by": " 提供支持", "This address is in local editing preview mode and cannot be viewed by the public.": diff --git a/src/app/site/[site]/layout.tsx b/src/app/site/[site]/layout.tsx new file mode 100644 index 00000000..d22cc3c7 --- /dev/null +++ b/src/app/site/[site]/layout.tsx @@ -0,0 +1,157 @@ +import { notFound } from "next/navigation" + +import { Hydrate, dehydrate } from "@tanstack/react-query" + +import { BlockchainInfo } from "~/components/common/BlockchainInfo" +import { Style } from "~/components/common/Style" +import { BackToTopFAB } from "~/components/site/BackToTopFAB" +import { SiteFooter } from "~/components/site/SiteFooter" +import { SiteHeader } from "~/components/site/SiteHeader" +import { FABContainer } from "~/components/ui/FAB" +import getQueryClient from "~/lib/query-client" +import { ExpandedNote } from "~/lib/types" +import { cn } from "~/lib/utils" +import { fetchGetPage } from "~/queries/page.server" +import { + fetchGetSite, + prefetchGetSiteSubscriptions, + prefetchGetSiteToSubscriptions, +} from "~/queries/site.server" + +export default async function SiteLayout({ + children, + params, +}: { + children?: React.ReactNode + params: { + site: string + page?: string + tag?: string + } +}) { + const queryClient = getQueryClient() + + const site = await fetchGetSite(params.site, queryClient) + + let page + if (site?.characterId) { + const result = await Promise.all([ + prefetchGetSiteSubscriptions( + { + characterId: site.characterId, + }, + queryClient, + ), + prefetchGetSiteToSubscriptions( + { + characterId: site.characterId, + }, + queryClient, + ), + new Promise(async (resolve, reject) => { + if (params.page) { + try { + const page = await fetchGetPage( + { + characterId: site.characterId, + slug: params.page, + useStat: true, + }, + queryClient, + ) + + if ( + !page || + new Date(page!.metadata?.content?.date_published || "") > + new Date() + ) { + reject(notFound()) + } else { + resolve(page) + } + } catch (error) { + reject(error) + } + } else { + // if (!options?.skipPages) { + // await prefetchGetPagesBySite( + // { + // characterId: site.characterId, + // ...(options?.limit && { limit: options.limit }), + // type: "post", + // visibility: PageVisibilityEnum.Published, + // ...(params.tag && { tags: [params.tag] }), + // ...(options?.useStat && { + // useStat: true, + // }), + // }, + // queryClient, + // ) + // } + resolve(null) + } + }), + ]) + page = result[2] + } else { + notFound() + } + + const dehydratedState = dehydrate(queryClient) + + return ( + +
+ {/* ]*>/g, "") + } + image={ + page.data?.metadata?.content?.cover || + getUserContentsUrl(site.data?.metadata?.content?.avatars?.[0]) + } + icon={getUserContentsUrl(site.data?.metadata?.content?.avatars?.[0])} + site={domainOrSubdomain} + /> */} +