diff --git a/apps/portal/src/components/resumes/browse/ResumeListItem.tsx b/apps/portal/src/components/resumes/browse/ResumeListItem.tsx index c7f7677a..0d0a2756 100644 --- a/apps/portal/src/components/resumes/browse/ResumeListItem.tsx +++ b/apps/portal/src/components/resumes/browse/ResumeListItem.tsx @@ -1,9 +1,17 @@ import formatDistanceToNow from 'date-fns/formatDistanceToNow'; import Link from 'next/link'; +import { useSession } from 'next-auth/react'; import type { UrlObject } from 'url'; import { ChevronRightIcon } from '@heroicons/react/20/solid'; +import { + AcademicCapIcon, + BriefcaseIcon, + StarIcon as ColouredStarIcon, +} from '@heroicons/react/20/solid'; import { ChatBubbleLeftIcon, StarIcon } from '@heroicons/react/24/outline'; +import { trpc } from '~/utils/trpc'; + import type { Resume } from '~/types/resume'; type Props = Readonly<{ @@ -12,24 +20,47 @@ type Props = Readonly<{ }>; export default function BrowseListItem({ href, resumeInfo }: Props) { + const { data: sessionData } = useSession(); + + // Find out if user has starred this particular resume + const resumeId = resumeInfo.id; + const isStarredQuery = trpc.useQuery([ + 'resumes.resume.user.isResumeStarred', + { resumeId }, + ]); + return ( -
+
{resumeInfo.title}
- {resumeInfo.role} -
+
+
+
+
-
-
+
+
{resumeInfo.numComments} comments
- + {isStarredQuery.data && sessionData?.user ? ( + + ) : ( + + )} {resumeInfo.numStars} stars
diff --git a/apps/portal/src/server/router/resumes/resumes-resume-user-router.ts b/apps/portal/src/server/router/resumes/resumes-resume-user-router.ts index 3b0b5a0b..b443c3e2 100644 --- a/apps/portal/src/server/router/resumes/resumes-resume-user-router.ts +++ b/apps/portal/src/server/router/resumes/resumes-resume-user-router.ts @@ -112,4 +112,18 @@ export const resumesResumeUserRouter = createProtectedRouter() return resume; }); }, + }) + .query('isResumeStarred', { + input: z.object({ + resumeId: z.string(), + }), + async resolve({ ctx, input }) { + const userId = ctx.session?.user?.id; + const { resumeId } = input; + return await ctx.prisma.resumesStar.findUnique({ + where: { + userId_resumeId: { resumeId, userId }, + }, + }); + }, });