feat: use react query for page requests
This commit is contained in:
@@ -11,7 +11,7 @@ import Link from "next/link"
|
||||
import toast from "react-hot-toast"
|
||||
import { EmptyState } from "../ui/EmptyState"
|
||||
import type { Note } from "unidata.js"
|
||||
import { getPagesBySite, deletePage } from "~/models/page.model"
|
||||
import { useGetPagesBySite, useDeletePage } from "~/queries/page"
|
||||
|
||||
export const PagesManager: React.FC<{
|
||||
isPost: boolean
|
||||
@@ -27,39 +27,21 @@ export const PagesManager: React.FC<{
|
||||
[router.query.visibility]
|
||||
)
|
||||
|
||||
let [pages, setPages] = useState<Note[] | null>(null)
|
||||
|
||||
const pageDelete = (id: string) => {
|
||||
deletePage({
|
||||
site: subdomain,
|
||||
id: id,
|
||||
}).then(() => {
|
||||
toast.success("Deleted!")
|
||||
getPagesBySite({
|
||||
type: isPost ? "post" : "page",
|
||||
site: subdomain,
|
||||
take: 1000,
|
||||
visibility,
|
||||
render: true,
|
||||
}).then((pages) => {
|
||||
setPages(pages?.list || [])
|
||||
})
|
||||
})
|
||||
}
|
||||
const deletePage = useDeletePage()
|
||||
|
||||
useEffect(() => {
|
||||
if (subdomain) {
|
||||
getPagesBySite({
|
||||
type: isPost ? "post" : "page",
|
||||
site: subdomain!,
|
||||
take: 1000,
|
||||
visibility,
|
||||
render: true,
|
||||
}).then((pages) => {
|
||||
setPages(pages?.list || [])
|
||||
})
|
||||
if (deletePage.isSuccess) {
|
||||
toast.success("Deleted!")
|
||||
}
|
||||
}, [subdomain, isPost, visibility])
|
||||
}, [deletePage.isSuccess])
|
||||
|
||||
const pages = useGetPagesBySite({
|
||||
type: isPost ? "post" : "page",
|
||||
site: subdomain!,
|
||||
take: 1000,
|
||||
visibility,
|
||||
render: true,
|
||||
})
|
||||
|
||||
const tabItems: TabItem[] = [
|
||||
{
|
||||
@@ -186,11 +168,11 @@ export const PagesManager: React.FC<{
|
||||
<Tabs items={tabItems} />
|
||||
|
||||
<div className="-mt-3">
|
||||
{pages && pages.length === 0 && (
|
||||
{pages.data?.list.length === 0 && (
|
||||
<EmptyState resource={isPost ? "posts" : "pages"} />
|
||||
)}
|
||||
|
||||
{pages?.map((page) => {
|
||||
{pages.data?.list?.map((page) => {
|
||||
return (
|
||||
<Link key={page.id} href={getPageEditLink(page)}>
|
||||
<a className="group relative hover:bg-zinc-100 rounded-lg py-3 px-3 transition-colors -mx-3 flex justify-between">
|
||||
|
||||
@@ -5,7 +5,7 @@ import { EmptyState } from "../ui/EmptyState"
|
||||
import { Notes, Note } from "~/lib/types"
|
||||
|
||||
export const SiteArchives: React.FC<{
|
||||
posts: Notes
|
||||
posts?: Notes
|
||||
}> = ({ posts }) => {
|
||||
const groupedByYear = useMemo<Map<string, Note[]>>(() => {
|
||||
const map = new Map()
|
||||
|
||||
@@ -6,17 +6,17 @@ import { Profile, Note } from "~/lib/types"
|
||||
|
||||
export const SitePage: React.FC<{
|
||||
site?: Profile,
|
||||
page: Note
|
||||
page?: Note
|
||||
}> = ({ site, page }) => {
|
||||
return (
|
||||
<>
|
||||
<div className="">
|
||||
{page.tags?.includes("post") ? (
|
||||
{page?.tags?.includes("post") ? (
|
||||
<h2 className="text-4xl font-bold">{page.title}</h2>
|
||||
) : (
|
||||
<h2 className="text-xl font-bold page-title">{page.title}</h2>
|
||||
<h2 className="text-xl font-bold page-title">{page?.title}</h2>
|
||||
)}
|
||||
{page.tags?.includes("post") && (
|
||||
{page?.tags?.includes("post") && (
|
||||
<PostMeta
|
||||
publishedAt={page.date_published}
|
||||
authors={[{
|
||||
@@ -28,28 +28,28 @@ export const SitePage: React.FC<{
|
||||
)}
|
||||
</div>
|
||||
<PageContent
|
||||
contentHTML={page.body?.content || ""}
|
||||
contentHTML={page?.body?.content || ""}
|
||||
className="my-10"
|
||||
/>
|
||||
<div className="bg-gray-50 rounded-lg py-8 px-5 break-all">
|
||||
<p className="text-gray-700 mb-4">🔔 This {page.tags?.includes("post") ? "post" : "page"} has been permanently stored on-chain and signed by its creator.</p>
|
||||
<p className="text-gray-700 mb-4">🔔 This {page?.tags?.includes("post") ? "post" : "page"} has been permanently stored on-chain and signed by its creator.</p>
|
||||
<ul className="text-gray-600 text-sm leading-6">
|
||||
<li className="mt-2">
|
||||
<div className="font-bold">Crossbell Transaction</div>
|
||||
<div>{page.related_urls?.filter((url) => url.startsWith("https://scan.crossbell.io/tx/")).map((url) => {
|
||||
<div>{page?.related_urls?.filter((url) => url.startsWith("https://scan.crossbell.io/tx/")).map((url) => {
|
||||
return <a target="_blank" rel="noreferrer" className="inline-block mr-4 break-all" href={url} key={url}>{url.replace("https://scan.crossbell.io/tx/", "").slice(0, 10)}...{url.replace("https://scan.crossbell.io/tx/", "").slice(-10)}</a>
|
||||
})}</div>
|
||||
</li>
|
||||
<li className="mt-2">
|
||||
<div className="font-bold">IPFS Address</div>
|
||||
<div>{page.related_urls?.filter((url) => url.startsWith("https://gateway.ipfs.io/ipfs/")).map((url) => {
|
||||
<div>{page?.related_urls?.filter((url) => url.startsWith("https://gateway.ipfs.io/ipfs/")).map((url) => {
|
||||
return <a target="_blank" rel="noreferrer" className="inline-block mr-4 break-all" href={url} key={url}>{url.replace("https://gateway.ipfs.io/ipfs/", "ipfs://")}</a>
|
||||
})}</div>
|
||||
</li>
|
||||
<li className="mt-2">
|
||||
<div className="font-bold">Author Address</div>
|
||||
<div>
|
||||
<a target="_blank" rel="noreferrer" className="inline-block mr-4 break-all" href={`https://scan.crossbell.io/address/${page.metadata?.owner}`} key={page.metadata?.owner}>{page.metadata?.owner}</a>
|
||||
<a target="_blank" rel="noreferrer" className="inline-block mr-4 break-all" href={`https://scan.crossbell.io/address/${page?.metadata?.owner}`} key={page?.metadata?.owner}>{page?.metadata?.owner}</a>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
Reference in New Issue
Block a user