Skip to content

Commit

Permalink
update with useMemo
Browse files Browse the repository at this point in the history
  • Loading branch information
rschlaefli committed Dec 9, 2023
1 parent 09a091a commit 7b2b6de
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/components/ProposalMeta.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { format, parseISO } from 'date-fns'
import { useSession } from 'next-auth/react'
import Link from 'next/link'
import { useMemo } from 'react'
import { ProposalDetails } from 'src/types/app'

interface ProposalMetaProps {
Expand All @@ -15,17 +16,18 @@ const FileTypeIconMap: Record<string, IconDefinition> = {
export default function ProposalMeta({ proposalDetails }: ProposalMetaProps) {
const { data: session } = useSession()

if (!proposalDetails) return null

const getSupervisedBy = () => {
if (session?.user?.email && proposalDetails.supervisedBy.length > 0) {
const supervisedBy = useMemo(() => {
if (session?.user?.email && proposalDetails?.supervisedBy?.length > 0) {
return proposalDetails.supervisedBy[0].supervisor.name
} else if (proposalDetails.supervisedBy.name) {
} else if (proposalDetails?.supervisedBy.name) {
return proposalDetails.supervisedBy.name
} else {
return 'Unassigned'
}
}
}, [session, proposalDetails])

if (!proposalDetails) return null

return (
<div className="p-4">
<h1 className="text-base font-bold">{proposalDetails.title}</h1>
Expand Down Expand Up @@ -64,7 +66,7 @@ export default function ProposalMeta({ proposalDetails }: ProposalMetaProps) {
)}
<div className="text-base">
<div className="font-bold">Supervised By</div>
<div>{getSupervisedBy()}</div>
<div>{supervisedBy}</div>
</div>

{proposalDetails.typeKey === 'STUDENT' && (
Expand Down

0 comments on commit 7b2b6de

Please sign in to comment.