From f53decd7367b4a8d27d816aff208995646be676f Mon Sep 17 00:00:00 2001 From: DIYgod Date: Thu, 24 Nov 2022 00:38:09 +0000 Subject: [PATCH] feat: operators in post meta --- package.json | 2 +- pnpm-lock.yaml | 14 ++-- src/components/common/CharacterCard.tsx | 4 +- src/components/dashboard/DashboardLayout.tsx | 22 ++++-- src/components/site/PostMeta.tsx | 72 ++++++++++++++------ src/components/site/SitePage.tsx | 7 +- src/components/ui/Avatar.tsx | 2 +- src/pages/_site/[site]/[page].tsx | 4 +- src/pages/_site/[site]/preview/[page].tsx | 9 ++- src/queries/site.ts | 13 +++- 10 files changed, 106 insertions(+), 43 deletions(-) diff --git a/package.json b/package.json index 125e6c40..2d58e204 100644 --- a/package.json +++ b/package.json @@ -80,7 +80,7 @@ "remark-stringify": "10.0.2", "sharp": "0.31.2", "sortablejs": "1.15.0", - "unidata.js": "0.7.6", + "unidata.js": "0.7.7", "unified": "10.1.2", "unist-builder": "3.0.0", "unist-util-visit": "4.1.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 16acb5a3..8f754812 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -98,7 +98,7 @@ specifiers: sortablejs: 1.15.0 tailwindcss: 3.2.4 typescript: 4.9.3 - unidata.js: 0.7.6 + unidata.js: 0.7.7 unified: 10.1.2 unist-builder: 3.0.0 unist-util-visit: 4.1.1 @@ -173,7 +173,7 @@ dependencies: remark-stringify: 10.0.2 sharp: 0.31.2 sortablejs: 1.15.0 - unidata.js: 0.7.6 + unidata.js: 0.7.7 unified: 10.1.2 unist-builder: 3.0.0 unist-util-visit: 4.1.1 @@ -1734,8 +1734,8 @@ packages: resolution: {integrity: sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==} dev: true - /@types/lodash/4.14.189: - resolution: {integrity: sha512-kb9/98N6X8gyME9Cf7YaqIMvYGnBSWqEci6tiettE6iJWH1XdJz/PO8LB0GtLCG7x8dU3KWhZT+lA1a35127tA==} + /@types/lodash/4.14.190: + resolution: {integrity: sha512-5iJ3FBJBvQHQ8sFhEhJfjUP+G+LalhavTkYyrAYqz5MEJG+erSv0k9KJLb6q7++17Lafk1scaTIFXcMJlwK8Mw==} dev: false /@types/mdast/3.0.10: @@ -8284,10 +8284,10 @@ packages: dependencies: busboy: 1.6.0 - /unidata.js/0.7.6: - resolution: {integrity: sha512-m5RBr4BIjbhUV0V8OlLnh40z+zmj0fS8iZlEjmgLF5mz5Bz0c7sFVCLZSmwWWV5Xlnl1ToFRDzzh8HUR5hihZA==} + /unidata.js/0.7.7: + resolution: {integrity: sha512-RPUA4r6nf63TNeuFaY1CljfHOly1iIWFmjS+UC8h4ew/gWgTzBKxqOLRRk9+0tiorOzjyoysJsvQIoNn/BRc+A==} dependencies: - '@types/lodash': 4.14.189 + '@types/lodash': 4.14.190 '@urql/core': 3.0.5_graphql@16.6.0 axios: 1.1.3 axios-retry: 3.3.1 diff --git a/src/components/common/CharacterCard.tsx b/src/components/common/CharacterCard.tsx index 4909112e..205bb29f 100644 --- a/src/components/common/CharacterCard.tsx +++ b/src/components/common/CharacterCard.tsx @@ -53,7 +53,9 @@ export const CharacterCard: React.FC<{ )} - {site?.name} + + {site?.name} + @{site.username} {site?.description && ( diff --git a/src/components/dashboard/DashboardLayout.tsx b/src/components/dashboard/DashboardLayout.tsx index 4a1dc517..ef4684bd 100644 --- a/src/components/dashboard/DashboardLayout.tsx +++ b/src/components/dashboard/DashboardLayout.tsx @@ -10,7 +10,7 @@ import { DashboardSidebar } from "./DashboardSidebar" import { useGetUserSites } from "~/queries/site" import { useAccount } from "wagmi" import { ConnectButton } from "~/components/common/ConnectButton" -import { useGetNotifications, useGetSite } from "~/queries/site" +import { useGetNotifications, useGetSite, useIsOperators } from "~/queries/site" import { getStorage } from "~/lib/storage" import { toGateway } from "~/lib/ipfs-parser" @@ -33,6 +33,11 @@ export function DashboardLayout({ siteCId: site.data?.metadata?.proof, }) + const isOperator = useIsOperators({ + characterId: +(site.data?.metadata?.proof || 0), + operator: address, + }) + const notificationCreatedAt = getStorage(`notification-${subdomain}`)?.createdAt || 0 @@ -53,11 +58,21 @@ export function DashboardLayout({ router.push("/") } if (userSite.isSuccess && subdomain) { - if (!userSite.data?.find((site) => site.username === subdomain)) { + if ( + !userSite.data?.find((site) => site.username === subdomain) && + !isOperator.data + ) { router.push("/dashboard") } } - }, [address, router, userSite.isSuccess, userSite.data, subdomain]) + }, [ + address, + router, + userSite.isSuccess, + userSite.data, + subdomain, + isOperator.data, + ]) const links: { href: string @@ -147,7 +162,6 @@ export function DashboardLayout({ diff --git a/src/components/site/PostMeta.tsx b/src/components/site/PostMeta.tsx index f96618e9..9bcb2a60 100644 --- a/src/components/site/PostMeta.tsx +++ b/src/components/site/PostMeta.tsx @@ -1,24 +1,30 @@ import { formatDate, formatToISO } from "~/lib/date" import { BlockchainIcon } from "~/components/icons/BlockchainIcon" import { UniLink } from "~/components/ui/UniLink" -import { Note } from "~/lib/types" +import { Note, Profile } from "~/lib/types" import { CSB_SCAN } from "~/lib/env" import { useEffect, useState } from "react" +import { useGetUserSites } from "~/queries/site" +import { CharacterFloatCard } from "~/components/common/CharacterFloatCard" +import { getSiteLink } from "~/lib/helpers" +import { Avatar } from "~/components/ui/Avatar" export const PostMeta: React.FC<{ page: Note -}> = ({ page }) => { + site?: Profile | null +}> = ({ page, site }) => { const [isMounted, setIsMounted] = useState(false) + const author = useGetUserSites(page.authors[0]) useEffect(() => { setIsMounted(true) }, []) return ( -
+
- - {page.tags - ?.filter((tag) => tag !== "post" && tag !== "page") - .map((tag) => ( - - <>#{tag} - - ))} - - ยท + {page.tags?.filter((tag) => tag !== "post" && tag !== "page").length ? ( + <> + + {page.tags + ?.filter((tag) => tag !== "post" && tag !== "page") + .map((tag) => ( + + <>#{tag} + + ))} + + + ) : null} + {author.data?.[0].username && + site?.username !== author.data?.[0].username && ( + <> + + + + + {author.data[0].name} + + + + + )} url.startsWith(CSB_SCAN + "/tx/"), )?.[0] } > - +
) diff --git a/src/components/site/SitePage.tsx b/src/components/site/SitePage.tsx index 2448c4cd..b204a7a8 100644 --- a/src/components/site/SitePage.tsx +++ b/src/components/site/SitePage.tsx @@ -1,11 +1,12 @@ import { PageContent } from "../common/PageContent" import { PostMeta } from "./PostMeta" import { PostFooter } from "./PostFooter" -import { Note } from "~/lib/types" +import { Note, Profile } from "~/lib/types" export const SitePage: React.FC<{ page?: Note | null -}> = ({ page }) => { + site?: Profile | null +}> = ({ page, site }) => { return ( <> {page?.preview && ( @@ -22,7 +23,7 @@ export const SitePage: React.FC<{ {page?.title} )} - {page?.tags?.includes("post") && } + {page?.tags?.includes("post") && }
+ return } SitePagePage.getLayout = (page: ReactElement) => { diff --git a/src/pages/_site/[site]/preview/[page].tsx b/src/pages/_site/[site]/preview/[page].tsx index 90444e1a..63e98e95 100644 --- a/src/pages/_site/[site]/preview/[page].tsx +++ b/src/pages/_site/[site]/preview/[page].tsx @@ -3,18 +3,21 @@ import { SitePage } from "~/components/site/SitePage" import { useGetPage } from "~/queries/page" import type { ReactElement } from "react" import { useRouter } from "next/router" +import { useGetSite } from "~/queries/site" function SitePagePage() { const router = useRouter() - const site = router.query.site as string + const domainOrSubdomain = router.query.site as string const pageSlug = router.query.page as string const page = useGetPage({ - site: site, + site: domainOrSubdomain, pageId: pageSlug, }) - return + const site = useGetSite(domainOrSubdomain) + + return } SitePagePage.getLayout = (page: ReactElement) => { diff --git a/src/queries/site.ts b/src/queries/site.ts index 34246996..efb39162 100644 --- a/src/queries/site.ts +++ b/src/queries/site.ts @@ -197,11 +197,20 @@ export const useGetOperators = ( } export const useIsOperators = ( - data: Parameters[0], + data: Partial[0]>, ) => { const contract = useContract() return useQuery(["isOperators", data], async () => { - return siteModel.isOperators(data, contract) + if (!data.characterId || !data.operator) { + return null + } + return siteModel.isOperators( + { + characterId: data.characterId, + operator: data.operator, + }, + contract, + ) }) }