diff --git a/src/components/common/Comment.tsx b/src/components/common/Comment.tsx index 58e7b285..3e2d1314 100644 --- a/src/components/common/Comment.tsx +++ b/src/components/common/Comment.tsx @@ -66,6 +66,7 @@ export const Comment: React.FC<{ address, pageId: page!.id, content: values.content, + externalUrl: window.location.href, }) } }) diff --git a/src/components/dashboard/DashboardLayout.tsx b/src/components/dashboard/DashboardLayout.tsx index 5344ce75..64bb3fd9 100644 --- a/src/components/dashboard/DashboardLayout.tsx +++ b/src/components/dashboard/DashboardLayout.tsx @@ -106,7 +106,10 @@ export function DashboardLayout({
diff --git a/src/lib/helpers.ts b/src/lib/helpers.ts index ff8fbc6f..fbc8fb9f 100644 --- a/src/lib/helpers.ts +++ b/src/lib/helpers.ts @@ -2,12 +2,17 @@ import { IS_PROD } from "./constants" import { OUR_DOMAIN } from "./env" export const getSiteLink = ({ + domain, subdomain, noProtocol, }: { + domain?: string subdomain: string noProtocol?: boolean }) => { + if (domain) { + return `https://${domain}` + } if (noProtocol) { return `${subdomain}.${OUR_DOMAIN}` } diff --git a/src/models/page.model.ts b/src/models/page.model.ts index cf096901..44f3cff2 100644 --- a/src/models/page.model.ts +++ b/src/models/page.model.ts @@ -50,6 +50,7 @@ export async function createOrUpdatePage(input: { excerpt?: string /** Only needed when creating page */ isPost?: boolean + externalUrl?: string }) { return await unidata.notes.set( { @@ -59,6 +60,7 @@ export async function createOrUpdatePage(input: { action: input.pageId ? "update" : "add", }, { + ...(input.externalUrl && { related_urls: [input.externalUrl] }), ...(input.pageId && { id: input.pageId }), ...(input.title && { title: input.title }), ...(input.content && { @@ -391,10 +393,12 @@ export async function commentPage({ address, pageId, content, + externalUrl, }: { address: string pageId: string content: string + externalUrl: string }) { const characterId = await getPrimaryCharacter(address) if (!characterId) { @@ -405,6 +409,7 @@ export async function commentPage({ { content, sources: ["xlog"], + external_urls: [externalUrl], tags: ["comment"], }, pageId.split("-")[0], diff --git a/src/models/site.model.ts b/src/models/site.model.ts index 59ef7fae..0988be2d 100644 --- a/src/models/site.model.ts +++ b/src/models/site.model.ts @@ -31,49 +31,7 @@ export const checkSubdomain = async ({ // } } -export const getUserSites = async (address?: string) => { - if (!address) { - return null - } - const profiles = await unidata.profiles.get({ - source: "Crossbell Profile", - identity: address, - platform: "Ethereum", - filter: { - primary: true, - }, - }) - - const sites = profiles.list - ?.sort((a, b) => { - if (a.metadata?.primary) { - return -1 - } else if (b.metadata?.primary) { - return 1 - } else { - return +new Date(b.date_updated || 0) - +new Date(a.date_updated || 0) - } - }) - .map((profile) => { - profile.name = profile.name || profile.username - return profile - }) - - if (!sites || !sites.length) return null - - return sites -} - -export const getSite = async (input: string) => { - const profiles = await unidata.profiles.get({ - source: "Crossbell Profile", - identity: input, - platform: "Crossbell", - }) - - const site: Profile = profiles.list?.sort( - (a, b) => +new Date(b.date_updated || 0) - +new Date(a.date_updated || 0), - )?.[0] +const expandSite = (site: Profile) => { site.navigation = JSON.parse( site.metadata?.raw?.attributes?.find( (a: any) => a.trait_type === "xlog_navigation", @@ -102,6 +60,42 @@ export const getSite = async (input: string) => { return site } +export const getUserSites = async (address?: string) => { + if (!address) { + return null + } + const profiles = await unidata.profiles.get({ + source: "Crossbell Profile", + identity: address, + platform: "Ethereum", + filter: { + primary: true, + }, + }) + + const sites: Profile[] = profiles.list?.map((profile) => { + expandSite(profile) + return profile + }) + + if (!sites || !sites.length) return null + + return sites +} + +export const getSite = async (input: string) => { + const profiles = await unidata.profiles.get({ + source: "Crossbell Profile", + identity: input, + platform: "Crossbell", + }) + + const site: Profile = profiles.list[0] + expandSite(site) + + return site +} + export const getSubscription = async (data: { userId: string siteId: string diff --git a/src/pages/dashboard/[subdomain]/editor.tsx b/src/pages/dashboard/[subdomain]/editor.tsx index 0a521649..0a90f75e 100644 --- a/src/pages/dashboard/[subdomain]/editor.tsx +++ b/src/pages/dashboard/[subdomain]/editor.tsx @@ -18,10 +18,8 @@ import { inLocalTimezone } from "~/lib/date" import { getSiteLink } from "~/lib/helpers" import { getPageVisibility } from "~/lib/page-helpers" import { PageVisibilityEnum, Note } from "~/lib/types" -import { FieldLabel } from "~/components/ui/FieldLabel" -import { Button } from "~/components/ui/Button" -import { useStore } from "~/lib/store" import { useGetPage, useCreateOrUpdatePage } from "~/queries/page" +import { useGetSite } from "~/queries/site" const getInputDatetimeValue = (date: Date | string) => { const str = dayjs(date).format() @@ -35,6 +33,8 @@ export default function SubdomainEditor() { const isPost = router.query.type === "post" const pageId = router.query.id as string | undefined + const site = useGetSite(subdomain) + const page = useGetPage({ site: subdomain!, pageId: pageId, @@ -87,6 +87,11 @@ export default function SubdomainEditor() { isPost: isPost, published, content, + externalUrl: + values.slug && + `${getSiteLink({ subdomain, domain: site.data?.custom_domain })}/${ + values.slug + }`, }) } @@ -256,13 +261,18 @@ export default function SubdomainEditor() { <> This {isPost ? "post" : "page"} will be accessible at{" "} - {getSiteLink({ subdomain, noProtocol: true })}/ - {values.slug} + {getSiteLink({ + subdomain, + domain: site.data?.custom_domain, + noProtocol: true, + })} + /{values.slug} )}