diff --git a/src/components/common/ReactionComment.tsx b/src/components/common/ReactionComment.tsx new file mode 100644 index 00000000..634257ee --- /dev/null +++ b/src/components/common/ReactionComment.tsx @@ -0,0 +1,69 @@ +"use client" + +import { Tooltip } from "~/components/ui/Tooltip" +import { useTranslation } from "~/lib/i18n/client" +import { calculateElementTop, cn } from "~/lib/utils" +import { useCheckComment, useGetComments } from "~/queries/page" + +import { Button } from "../ui/Button" + +export const ReactionComment: React.FC<{ + characterId?: number + noteId?: number +}> = ({ characterId, noteId }) => { + const { t } = useTranslation("common") + + const comments = useGetComments({ + characterId: characterId, + noteId: noteId, + }) + + const isCommented = useCheckComment({ + noteCharacterId: characterId, + noteId: noteId, + }) + + const comment = () => { + const targetElement = document.querySelector("#comments") as HTMLElement + window.scrollTo({ + top: calculateElementTop(targetElement) - 20, + behavior: "smooth", + }) + } + + return ( + <> +
+ +
+ + ) +} diff --git a/src/components/common/ReactionLike.tsx b/src/components/common/ReactionLike.tsx index db47bef1..b90d4c98 100644 --- a/src/components/common/ReactionLike.tsx +++ b/src/components/common/ReactionLike.tsx @@ -115,6 +115,7 @@ export const ReactionLike: React.FC<{
) diff --git a/src/components/ui/Button.tsx b/src/components/ui/Button.tsx index f3ac97cf..1d9fd566 100644 --- a/src/components/ui/Button.tsx +++ b/src/components/ui/Button.tsx @@ -19,8 +19,15 @@ export type Variant = | "crossbell" | "outline" | "tip" + | "comment" -export type VariantColor = "green" | "red" | "gray" | "gradient" | "black" +export type VariantColor = + | "green" + | "red" + | "gray" + | "gradient" + | "black" + | "light" type ButtonProps = { isLoading?: boolean diff --git a/src/css/tailwind.css b/src/css/tailwind.css index 8fbce19d..bf022e19 100644 --- a/src/css/tailwind.css +++ b/src/css/tailwind.css @@ -168,43 +168,52 @@ a { @apply fill-black; } -.button.is-like { +.button.is-like, +.button.is-collect, +.button.is-tip, +.button.is-comment { @apply shadow-none p-0; - @apply text-gray-500 fill-gray-500; + @apply text-gray-500; } +.button.is-like.is-light, +.button.is-collect.is-light, +.button.is-tip.is-light, +.button.is-comment.is-light { + @apply text-gray-400; +} +.button.is-like.is-light.is-loading:before, +.button.is-collect.is-light.is-loading:before, +.button.is-tip.is-light.is-loading:before, +.button.is-comment.is-light.is-loading:before { + margin-right: 0; +} + .button.is-like:hover { color: #f91880; - fill: #f91880; } .button.is-like.active { color: #f91880; - fill: #f91880; } -.button.is-collect { - @apply shadow-none p-0; - @apply text-gray-500 fill-gray-500; -} .button.is-collect:hover { color: #ffcf55; - fill: #ffcf55; } .button.is-collect.active { color: #ffcf55; - fill: #ffcf55; } -.button.is-tip { - @apply shadow-none p-0; - @apply text-gray-500 fill-gray-500; -} .button.is-tip:hover { color: #ef4444; - fill: #ef4444; } .button.is-tip.active { color: #ef4444; - fill: #ef4444; +} + +.button.is-comment:hover { + @apply text-green-500; +} +.button.is-comment.active { + @apply text-green-500; } .button.is-crossbell { diff --git a/src/models/page.model.ts b/src/models/page.model.ts index bef7d981..ffa81d72 100644 --- a/src/models/page.model.ts +++ b/src/models/page.model.ts @@ -571,6 +571,23 @@ export async function checkMint({ }) } +export async function checkComment({ + characterId, + noteCharacterId, + noteId, +}: { + characterId: number + noteCharacterId: number + noteId: number +}) { + return indexer.note.getMany({ + characterId: characterId, + toCharacterId: noteCharacterId, + toNoteId: noteId, + limit: 0, + }) +} + export async function getComments({ characterId, noteId, diff --git a/src/queries/page.ts b/src/queries/page.ts index 994e5f89..17b21c9e 100644 --- a/src/queries/page.ts +++ b/src/queries/page.ts @@ -177,6 +177,31 @@ export const useCheckMint = ({ }) } +export const useCheckComment = ({ + noteCharacterId, + noteId, +}: { + noteCharacterId?: number + noteId?: number +}) => { + const account = useAccountState((s) => s.computed.account) + + return useQuery( + ["checkMint", noteCharacterId, noteId, account?.characterId], + async () => { + if (!noteCharacterId || !noteId || !account?.characterId) { + return { count: 0, list: [] } + } + + return pageModel.checkComment({ + characterId: account?.characterId, + noteCharacterId: noteCharacterId, + noteId: noteId, + }) + }, + ) +} + export function useCreateOrUpdatePage() { const newbieToken = useAccountState((s) => s.email?.token) const unidata = useUnidata()