feat: add edit link for site owner
This commit is contained in:
@@ -30,7 +30,7 @@ export function DashboardLayout({
|
||||
const site = useGetSite(subdomain)
|
||||
const userSite = useAccountSites()
|
||||
|
||||
const isOwner = useIsOwner()
|
||||
const isOwner = useIsOwner(subdomain)
|
||||
|
||||
useEffect(() => {
|
||||
if (isOwner.isSuccess && !isOwner.data) {
|
||||
|
||||
@@ -2,12 +2,13 @@ import { formatDate, formatToISO } from "~/lib/date"
|
||||
import { BlockchainIcon } from "~/components/icons/BlockchainIcon"
|
||||
import { UniLink } from "~/components/ui/UniLink"
|
||||
import { Note, Profile } from "~/lib/types"
|
||||
import { CSB_SCAN } from "~/lib/env"
|
||||
import { CSB_SCAN, SITE_URL } from "~/lib/env"
|
||||
import { useEffect, useState } from "react"
|
||||
import { CharacterFloatCard } from "~/components/common/CharacterFloatCard"
|
||||
import { getSiteLink } from "~/lib/helpers"
|
||||
import { Avatar } from "~/components/ui/Avatar"
|
||||
import { EyeIcon } from "@heroicons/react/24/outline"
|
||||
import { EyeIcon, PencilSquareIcon } from "@heroicons/react/24/outline"
|
||||
import { useIsOwner } from "~/hooks/useIsOwner"
|
||||
|
||||
export const PostMeta: React.FC<{
|
||||
page: Note
|
||||
@@ -20,6 +21,14 @@ export const PostMeta: React.FC<{
|
||||
setIsMounted(true)
|
||||
}, [])
|
||||
|
||||
const [showEdit, setShowEdit] = useState(false)
|
||||
const isOwner = useIsOwner(site?.username)
|
||||
useEffect(() => {
|
||||
if (isOwner.isSuccess && isOwner.data) {
|
||||
setShowEdit(true)
|
||||
}
|
||||
}, [isOwner.isSuccess, isOwner.data])
|
||||
|
||||
return (
|
||||
<div className="text-zinc-400 mt-4 xlog-post-meta space-x-5 flex items-center">
|
||||
<time
|
||||
@@ -85,6 +94,14 @@ export const PostMeta: React.FC<{
|
||||
>
|
||||
<BlockchainIcon className="fill-zinc-500 ml-1" />
|
||||
</UniLink>
|
||||
{showEdit && (
|
||||
<UniLink
|
||||
className="xlog-post-editor inline-flex items-center"
|
||||
href={`${SITE_URL}/dashboard/${site?.username}/editor?id=${page.id}`}
|
||||
>
|
||||
<PencilSquareIcon className="w-4 h-4 mx-1 inline-block" /> Edit
|
||||
</UniLink>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
import { useAccountBalance as _useAccountBalance } from "@crossbell/connect-kit"
|
||||
import { useRouter } from "next/router"
|
||||
import { useAccountSites } from "~/queries/site"
|
||||
import { useGetSite, useIsOperators } from "~/queries/site"
|
||||
import { useAccountState } from "@crossbell/connect-kit"
|
||||
|
||||
export function useIsOwner() {
|
||||
const router = useRouter()
|
||||
const subdomain = router.query.subdomain as string
|
||||
export function useIsOwner(subdomain?: string) {
|
||||
const site = useGetSite(subdomain)
|
||||
|
||||
const userSite = useAccountSites()
|
||||
@@ -24,10 +21,11 @@ export function useIsOwner() {
|
||||
site.isSuccess &&
|
||||
userSite.isSuccess &&
|
||||
isOperator.isSuccess,
|
||||
data:
|
||||
data: !!(
|
||||
subdomain &&
|
||||
address &&
|
||||
(userSite.data?.find((site) => site.username === subdomain) ||
|
||||
isOperator.data),
|
||||
isOperator.data)
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ export const useAccountSites = () => {
|
||||
})
|
||||
}
|
||||
|
||||
export const useGetSite = (input: string) => {
|
||||
export const useGetSite = (input?: string) => {
|
||||
const unidata = useUnidata()
|
||||
return useQuery(["getSite", input], async () => {
|
||||
if (!input) {
|
||||
|
||||
Reference in New Issue
Block a user