diff --git a/src/components/common/CharacterCard.tsx b/src/components/common/CharacterCard.tsx new file mode 100644 index 00000000..8c8aeadd --- /dev/null +++ b/src/components/common/CharacterCard.tsx @@ -0,0 +1,119 @@ +import { useEffect, useState } from "react" +import { + offset, + flip, + shift, + autoUpdate, + useFloating, + useInteractions, + useHover, + useFocus, + useRole, + useDismiss, +} from "@floating-ui/react-dom-interactions" +import { Avatar } from "~/components/ui/Avatar" +import dayjs from "dayjs" +import duration from "dayjs/plugin/duration" +import relativeTime from "dayjs/plugin/relativeTime" +import { FollowingButton } from "~/components/common/FollowingButton" +import { FollowingCount } from "~/components/common/FollowingCount" +import * as siteModel from "~/models/site.model" +import type { Profile } from "~/lib/types" + +dayjs.extend(duration) +dayjs.extend(relativeTime) + +export const CharacterCard: React.FC<{ + siteId?: string + children: JSX.Element +}> = ({ siteId, children }) => { + const [open, setOpen] = useState(false) + + const { x, y, reference, floating, strategy, context } = useFloating({ + placement: "bottom-start", + open, + onOpenChange: setOpen, + middleware: [offset(5), flip(), shift({ padding: 8 })], + whileElementsMounted: autoUpdate, + }) + + const { getReferenceProps, getFloatingProps } = useInteractions([ + useHover(context, { delay: { close: 100 } }), + useFocus(context), + useRole(context, { role: "tooltip" }), + useDismiss(context), + ]) + + const [buttonLoading, setButtonLoading] = useState(false) + const [firstOpen, setFirstOpen] = useState(false) + const [site, setSite] = useState() + + useEffect(() => { + if (!firstOpen && open && siteId && !site) { + setFirstOpen(true) + siteModel.getSite(siteId).then((site) => setSite(site)) + } + }, [open, firstOpen, siteId, site]) + + return ( +
+ {children} + {(open || buttonLoading) && ( +
+ {site ? ( + <> +
+ + setButtonLoading(status)} + /> +
+
+ {site?.name} + @{siteId} +
+ {site?.description && ( +
+ )} +
+ +
+
+ Joined{" "} + {dayjs + .duration( + dayjs(site?.date_created).diff(dayjs(), "minute"), + "minute", + ) + .humanize()}{" "} + ago +
+ + ) : ( + "Loading..." + )} +
+ )} +
+ ) +} diff --git a/src/components/common/CharacterList.tsx b/src/components/common/CharacterList.tsx index 25f7125e..b69be993 100644 --- a/src/components/common/CharacterList.tsx +++ b/src/components/common/CharacterList.tsx @@ -7,6 +7,7 @@ import { CSB_SCAN } from "~/lib/env" import { Avatar } from "../ui/Avatar" import { BlockchainIcon } from "~/components/icons/BlockchainIcon" import { getSiteLink } from "~/lib/helpers" +import { CharacterCard } from "~/components/common/CharacterCard" export const CharacterList: React.FC<{ open: boolean @@ -41,15 +42,17 @@ export const CharacterList: React.FC<{ })} className="flex items-center space-x-2 text-sm" > - + + + {sub.character?.metadata?.content?.name} @{sub.character?.handle} diff --git a/src/components/common/CommentItem.tsx b/src/components/common/CommentItem.tsx index 67ce0807..c37f9ed9 100644 --- a/src/components/common/CommentItem.tsx +++ b/src/components/common/CommentItem.tsx @@ -12,6 +12,7 @@ import { Button } from "~/components/ui/Button" import { Reactions } from "~/components/common/Reactions" import { useState } from "react" import { CommentInput } from "~/components/common/CommentInput" +import { CharacterCard } from "~/components/common/CharacterCard" dayjs.extend(duration) dayjs.extend(relativeTime) @@ -31,21 +32,27 @@ export const CommentItem: React.FC<{ className={depth > 0 ? "" : "border-b border-dashed pb-6"} >
- - - +
+ +
+ + + +
+
+
= ({ siteId }) => { + variant?: Variant + className?: string + size?: "sm" | "xl" + loadingStatusChange?: (status: boolean) => void +}> = ({ siteId, variant, className, size, loadingStatusChange }) => { const { address } = useAccount() const subscribeToSite = useSubscribeToSite() const unsubscribeFromSite = useUnsubscribeFromSite() @@ -93,11 +97,23 @@ export const FollowingButton: React.FC<{ } }, [subscribeToSite.isError, subscribeToSite.data?.code, subscribeToSite]) + useEffect(() => { + if (unsubscribeFromSite.isLoading || subscribeToSite.isLoading) { + loadingStatusChange?.(true) + } else { + loadingStatusChange?.(false) + } + }, [ + unsubscribeFromSite.isLoading, + subscribeToSite.isLoading, + loadingStatusChange, + ]) + return (