feat: easier mention syntax
This commit is contained in:
@@ -42,7 +42,7 @@ export const CharacterFloatCard: React.FC<{
|
||||
|
||||
return (
|
||||
<>
|
||||
<div ref={refs.setReference} {...getReferenceProps()}>
|
||||
<div className="inline" ref={refs.setReference} {...getReferenceProps()}>
|
||||
{children}
|
||||
</div>
|
||||
{isMounted && (
|
||||
|
||||
@@ -2,21 +2,39 @@ import React from "react"
|
||||
import { CharacterFloatCard } from "../common/CharacterFloatCard"
|
||||
import { UniLink } from "./UniLink"
|
||||
import { getSiteLink } from "~/lib/helpers"
|
||||
import { useGetSite } from "~/queries/site"
|
||||
|
||||
export const Mention: React.FC<{
|
||||
id: string
|
||||
}> = ({ id }) => {
|
||||
const siteId = id?.replace(/^user-content-/, "")
|
||||
return (
|
||||
<CharacterFloatCard siteId={siteId}>
|
||||
<UniLink
|
||||
href={getSiteLink({
|
||||
subdomain: siteId,
|
||||
})}
|
||||
className="inline-block"
|
||||
>
|
||||
@{siteId}
|
||||
</UniLink>
|
||||
</CharacterFloatCard>
|
||||
)
|
||||
children?: any
|
||||
}> = ({ id, children }) => {
|
||||
let siteId
|
||||
if (
|
||||
children?.[0] &&
|
||||
typeof children[0] === "string" &&
|
||||
children[0].startsWith("@")
|
||||
) {
|
||||
siteId = children[0].replace(/^@/, "")
|
||||
} else if (id) {
|
||||
siteId = id.replace(/^user-content-/, "")
|
||||
}
|
||||
|
||||
const site = useGetSite(siteId)
|
||||
|
||||
if (siteId && site.data) {
|
||||
return (
|
||||
<CharacterFloatCard siteId={siteId}>
|
||||
<UniLink
|
||||
href={getSiteLink({
|
||||
subdomain: siteId,
|
||||
})}
|
||||
className="inline-block"
|
||||
>
|
||||
@{siteId}
|
||||
</UniLink>
|
||||
</CharacterFloatCard>
|
||||
)
|
||||
} else {
|
||||
return <>{children}</>
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user