feat: add oia button for universal links. (#597)

This commit is contained in:
Caspian Zhao
2023-05-31 10:03:02 +03:00
committed by GitHub
parent 2709553692
commit 79e8e22335
5 changed files with 54 additions and 0 deletions
+2
View File
@@ -5,6 +5,7 @@ import serialize from "serialize-javascript"
import { Hydrate, dehydrate } from "@tanstack/react-query"
import { PageContent } from "~/components/common/PageContent"
import { OIAButton } from "~/components/site/OIAButton"
import { PostFooter } from "~/components/site/PostFooter"
import PostMeta from "~/components/site/PostMeta"
import { SITE_URL } from "~/lib/env"
@@ -155,6 +156,7 @@ export default async function SitePagePage({
site={site}
withActions={true}
/>
<OIAButton link={`/notes/${page?.noteId}/${page?.characterId}`} />
</article>
{!onlyContent && (
<Hydrate state={dehydratedState}>
+49
View File
@@ -0,0 +1,49 @@
"use client"
import React, { useCallback, useEffect, useState } from "react"
import { useIsMobileLayout } from "~/hooks/useMobileLayout"
import { useTranslation } from "~/lib/i18n/client"
export const OIAButton: React.FC<{
link: `/${string}`
}> = ({ link }) => {
const { t, i18n } = useTranslation("site")
const [isVisible, setIsVisible] = useState(true)
const oia = useCallback(() => {
window.open(`https://oia.xlog.app${link}`, "_blank")
}, [])
const isMobileLayout = useIsMobileLayout()
useEffect(() => {
if (!isMobileLayout) {
return
}
let timeoutId: ReturnType<typeof setTimeout> | null = null
const handleScroll = () => {
setIsVisible(false)
timeoutId && clearTimeout(timeoutId)
timeoutId = setTimeout(() => setIsVisible(true), 1000)
}
window.addEventListener("scroll", handleScroll)
return () => window.removeEventListener("scroll", handleScroll)
}, [isMobileLayout])
if (!isMobileLayout) {
return null
}
return (
<button
onClick={oia}
className={`fixed bottom-[10%] left-1/2 -translate-x-1/2 bg-black rounded-3xl px-5 py-3 text-accent z-50 transition-opacity duration-500 ${
isVisible ? "opacity-100" : "opacity-0"
}`}
>
{t("Open in App")}
</button>
)
}
+1
View File
@@ -6,5 +6,6 @@
"load more": "まだ{{count}}件の{{name}}があります。",
"signed and stored on the blockchain": "{{name}}は、創作者によって署名され、ブロックチェーンに安全に保存されています。",
"Write a comment on the blockchain": "ブロックチェーンでコメントする",
"Open in App": "アプリで開く",
"powered by": "<span>このサイトは </span><name/><span> によって作動します</span>"
}
+1
View File
@@ -18,5 +18,6 @@
"404 - Whoops, this page is gone.": "404 - 哎呀,這個頁面不見了。",
"Back to Home": "回到首頁",
"All Posts": "所有文章",
"Open in App": "在 App 中開啟",
"Search Posts": "搜尋文章"
}
+1
View File
@@ -19,5 +19,6 @@
"404 - Whoops, this page is gone.": "404 - 哎呀,这个页面不见了。",
"Back to Home": "返回主页",
"All Posts": "所有文章",
"Open in App": "在 App 中打开",
"Search Posts": "搜索文章"
}