feat: add title badge

This commit is contained in:
DIYgod
2023-04-07 03:20:46 +01:00
parent a9c44cdf83
commit ba00fbd672
6 changed files with 74 additions and 3 deletions
+4 -2
View File
@@ -7,6 +7,7 @@ import type { Profile } from "~/lib/types"
import { cn } from "~/lib/utils"
import { useDate } from "~/hooks/useDate"
import { useTranslation } from "next-i18next"
import { Titles } from "~/components/common/Titles"
export const CharacterCard: React.FC<{
siteId?: string
@@ -71,11 +72,12 @@ export const CharacterCard: React.FC<{
/>
)}
</span>
<span className="block">
<span className="flex items-center space-x-1">
<span className="font-bold text-base text-zinc-800">
{site?.name}
</span>
<span className="ml-1 text-gray-600">@{site?.username}</span>
<Titles characterId={+(site.metadata?.proof || "")} />
<span className="text-gray-600">@{site?.username}</span>
</span>
{site?.description && (
<span
+2
View File
@@ -13,6 +13,7 @@ import { CharacterFloatCard } from "~/components/common/CharacterFloatCard"
import { useTranslation } from "next-i18next"
import { useDate } from "~/hooks/useDate"
import { useAccountState } from "@crossbell/connect-kit"
import { Titles } from "~/components/common/Titles"
export const CommentItem: React.FC<{
comment: NoteEntity & {
@@ -70,6 +71,7 @@ export const CommentItem: React.FC<{
>
{comment?.character?.metadata?.content?.name}
</UniLink>
<Titles characterId={comment.characterId} />
<span>·</span>
<time dateTime={date.formatToISO(comment?.createdAt)}>
{t("ago", {
+49
View File
@@ -0,0 +1,49 @@
import { cn } from "~/lib/utils"
import data from "../../../data/titles.json"
import { Tooltip } from "../ui/Tooltip"
import { UniLink } from "../ui/UniLink"
const icons: {
[key: string]: {
bg: string
icon: string
}
} = {
"xLog contributor": {
bg: "bg-zinc-700 text-white",
icon: "i-mingcute:terminal-line",
},
}
export const Titles: React.FC<{
characterId?: number
}> = ({ characterId }) => {
if (!characterId) {
return null
}
const list = data.filter((title) => title.list.includes(characterId))
if (!list.length) {
return null
}
return (
<span className="inline-flex">
{list.map((title) => (
<Tooltip
key={title.name}
label={title.name}
childrenClassName={cn(
icons[title.name].bg,
"inline-flex p-[1px] rounded-sm",
)}
>
<UniLink href={title.link} className="inline-flex">
<i className={cn(icons[title.name].icon, "text-[10px]")} />
</UniLink>
</Tooltip>
))}
</span>
)
}