Skip to content

Commit

Permalink
feat: mentions to hook & lints
Browse files Browse the repository at this point in the history
  • Loading branch information
mbifulco committed Dec 24, 2024
1 parent ee76d50 commit 674d370
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
3 changes: 0 additions & 3 deletions src/components/Post/FullPost.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { useRouter } from 'next/router';
import { MDXRemote } from 'next-mdx-remote';
import type { VideoObject, WithContext } from 'schema-dts';

Expand Down Expand Up @@ -31,8 +30,6 @@ const FullPost: React.FC<FullPostProps> = ({ post }) => {
youTubeId,
} = frontmatter;

const router = useRouter();

let coverContainer: React.ReactNode = (
<Image
className={'mb-4 ml-0 rounded-lg object-cover object-center shadow'}
Expand Down
11 changes: 2 additions & 9 deletions src/components/Post/mentionsSummary.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useRouter } from 'next/router';
import { useWebMentions } from '@hooks/useWebMentions';
import pluralize from 'pluralize';

import formatDate from '@utils/format-date';
import { trpc } from '@utils/trpc';
import type { WebMention } from '@utils/webmentions';
import { Avatar, AvatarGroup } from '../Avatar';

Expand All @@ -20,14 +20,7 @@ const mySocialHandleUrls = [

const MentionsSummary: React.FC<MentionsSummaryProps> = () => {
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;

Expand Down
12 changes: 12 additions & 0 deletions src/hooks/useWebMentions.ts
Original file line number Diff line number Diff line change
@@ -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;
};
1 change: 0 additions & 1 deletion src/server/routers/webMentions.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down

0 comments on commit 674d370

Please sign in to comment.