From 674d3702cb2835775d89fe88f8a14168acaef6af Mon Sep 17 00:00:00 2001 From: Mike Bifulco Date: Tue, 24 Dec 2024 10:24:52 -0500 Subject: [PATCH] feat: mentions to hook & lints --- src/components/Post/FullPost.tsx | 3 --- src/components/Post/mentionsSummary.tsx | 11 ++--------- src/hooks/useWebMentions.ts | 12 ++++++++++++ src/server/routers/webMentions.ts | 1 - 4 files changed, 14 insertions(+), 13 deletions(-) create mode 100644 src/hooks/useWebMentions.ts diff --git a/src/components/Post/FullPost.tsx b/src/components/Post/FullPost.tsx index b41cc9d7..a2cdfac7 100644 --- a/src/components/Post/FullPost.tsx +++ b/src/components/Post/FullPost.tsx @@ -1,4 +1,3 @@ -import { useRouter } from 'next/router'; import { MDXRemote } from 'next-mdx-remote'; import type { VideoObject, WithContext } from 'schema-dts'; @@ -31,8 +30,6 @@ const FullPost: React.FC = ({ post }) => { youTubeId, } = frontmatter; - const router = useRouter(); - let coverContainer: React.ReactNode = ( = () => { const router = useRouter(); - const { data: mentions } = trpc.webMentions.getMentionsForPath.useQuery( - { - path: router.asPath, - }, - { - staleTime: 1000 * 60 * 60, // 1 hour - } - ); + const { data: mentions } = useWebMentions(router.asPath); if (!mentions || mentions.length === 0) return null; diff --git a/src/hooks/useWebMentions.ts b/src/hooks/useWebMentions.ts new file mode 100644 index 00000000..c9b4f2f0 --- /dev/null +++ b/src/hooks/useWebMentions.ts @@ -0,0 +1,12 @@ +import { trpc } from '@utils/trpc'; + +export const useWebMentions = (path: string) => { + const webmentionsQuery = trpc.webMentions.getMentionsForPath.useQuery( + { path }, + { + staleTime: 1000 * 60 * 60, // 1 hour + } + ); + + return webmentionsQuery; +}; diff --git a/src/server/routers/webMentions.ts b/src/server/routers/webMentions.ts index 1f49437b..afca2155 100644 --- a/src/server/routers/webMentions.ts +++ b/src/server/routers/webMentions.ts @@ -1,7 +1,6 @@ import { TRPCError } from '@trpc/server'; import { z } from 'zod'; -import { getSubscriberCount, subscribe, subscribeSchema } from '@utils/resend'; import getMentions from '@utils/webmentions'; import { procedure, router } from '../trpc';