feat: add related_urls

This commit is contained in:
DIYgod 2022-08-23 17:29:51 +01:00
parent e5fb6b7f8d
commit 34a6e27d29
No known key found for this signature in database
GPG Key ID: D159328F47A80DCA
6 changed files with 70 additions and 52 deletions

View File

@ -66,6 +66,7 @@ export const Comment: React.FC<{
address,
pageId: page!.id,
content: values.content,
externalUrl: window.location.href,
})
}
})

View File

@ -106,7 +106,10 @@ export function DashboardLayout({
<div className="absolute bottom-0 left-0 right-0 h-20 flex items-center px-4">
<UniLink
href={getSiteLink({ subdomain })}
href={getSiteLink({
subdomain,
domain: userSite.data?.[0]?.custom_domain,
})}
className="space-x-2 border rounded-lg bg-gray-100 border-gray-200 text-gray-500 hover:border-indigo-300 hover:bg-indigo-100 hover:text-indigo-500 flex w-full h-12 items-center justify-center transition-colors"
>
<span className="i-bi:box-arrow-up-right"></span>

View File

@ -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}`
}

View File

@ -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],

View File

@ -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

View File

@ -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{" "}
<UniLink
href={`${getSiteLink({ subdomain })}/${
values.slug
}`}
href={`${getSiteLink({
subdomain,
domain: site.data?.custom_domain,
})}/${values.slug}`}
className="hover:underline"
>
{getSiteLink({ subdomain, noProtocol: true })}/
{values.slug}
{getSiteLink({
subdomain,
domain: site.data?.custom_domain,
noProtocol: true,
})}
/{values.slug}
</UniLink>
</>
)}