Merge remote-tracking branch 'origin/dev' into feature/nextjs-app-router
This commit is contained in:
@@ -1,14 +1,11 @@
|
||||
import { useEffect, useState } from "react"
|
||||
|
||||
import { FollowingButton } from "~/components/common/FollowingButton"
|
||||
import { FollowingCount } from "~/components/common/FollowingCount"
|
||||
import { Titles } from "~/components/common/Titles"
|
||||
import { Avatar } from "~/components/ui/Avatar"
|
||||
import { useDate } from "~/hooks/useDate"
|
||||
import { useTranslation } from "~/lib/i18n/client"
|
||||
import type { ExpandedCharacter } from "~/lib/types"
|
||||
import { cn } from "~/lib/utils"
|
||||
import * as siteModel from "~/models/site.model"
|
||||
import { useGetCharacterCard } from "~/queries/site"
|
||||
|
||||
export const CharacterCard: React.FC<{
|
||||
siteId?: string
|
||||
@@ -27,25 +24,14 @@ export const CharacterCard: React.FC<{
|
||||
simple,
|
||||
style,
|
||||
}) => {
|
||||
const [firstOpen, setFirstOpen] = useState("")
|
||||
const [site, setSite] = useState<ExpandedCharacter>()
|
||||
const date = useDate()
|
||||
const { t } = useTranslation("common")
|
||||
|
||||
useEffect(() => {
|
||||
if (open && (firstOpen !== (siteId || address) || !site)) {
|
||||
if (siteId || address) {
|
||||
setFirstOpen(siteId || address || "")
|
||||
if (siteId) {
|
||||
siteModel.getSite(siteId).then((site) => setSite(site))
|
||||
} else if (address) {
|
||||
siteModel.getSiteByAddress(address).then((site) => setSite(site))
|
||||
}
|
||||
} else {
|
||||
setSite(undefined)
|
||||
}
|
||||
}
|
||||
}, [open, firstOpen, siteId, address, site])
|
||||
const { data: site } = useGetCharacterCard({
|
||||
siteId,
|
||||
address,
|
||||
enabled: open || false,
|
||||
})
|
||||
|
||||
return (
|
||||
<span
|
||||
|
||||
@@ -5,6 +5,7 @@ import { ReactElement, createElement } from "react"
|
||||
import { toast } from "react-hot-toast"
|
||||
import { refractor } from "refractor"
|
||||
import jsx from "refractor/lang/jsx"
|
||||
import solidity from "refractor/lang/solidity"
|
||||
import tsx from "refractor/lang/tsx"
|
||||
import rehypeAutolinkHeadings from "rehype-autolink-headings"
|
||||
import rehypeInferDescriptionMeta from "rehype-infer-description-meta"
|
||||
@@ -72,6 +73,7 @@ export type Rendered = {
|
||||
refractor.alias("html", ["svelte", "vue"])
|
||||
refractor.register(tsx)
|
||||
refractor.register(jsx)
|
||||
refractor.register(solidity)
|
||||
|
||||
const rehypePrism = rehypePrismGenerator(refractor)
|
||||
|
||||
|
||||
@@ -387,3 +387,29 @@ export const useGetGreenfieldId = (cid?: string) => {
|
||||
return siteModel.getGreenfieldId(cid)
|
||||
})
|
||||
}
|
||||
|
||||
export const useGetCharacterCard = ({
|
||||
siteId,
|
||||
address,
|
||||
enabled,
|
||||
}: {
|
||||
siteId?: string
|
||||
address?: string
|
||||
enabled: boolean
|
||||
}) => {
|
||||
return useQuery(
|
||||
["useGetCharacterCard", { siteId, address }],
|
||||
async () => {
|
||||
if (siteId) {
|
||||
return siteModel.getSite(siteId)
|
||||
} else if (address) {
|
||||
return siteModel.getSiteByAddress(address)
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
},
|
||||
{
|
||||
enabled,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user