Skip to content

Commit

Permalink
refactor people page for RFC (#413)
Browse files Browse the repository at this point in the history
* refactor for RFC
  • Loading branch information
bklaing2 authored Nov 8, 2024
1 parent 1a7c321 commit 2a214c8
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 42 deletions.
4 changes: 3 additions & 1 deletion src/app/orcid.org/[orcid]/Content.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React from 'react'
import { Container, Row, Col } from 'react-bootstrap';
import Container from 'react-bootstrap/Container'
import Row from 'react-bootstrap/Row'
import Col from 'react-bootstrap/Col'

import { QueryVar, fetchPerson } from 'src/data/queries/personQuery'

Expand Down
20 changes: 14 additions & 6 deletions src/app/orcid.org/[orcid]/RelatedContent.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
'use client'

import React from 'react'
import { Col, Container, Row } from 'react-bootstrap'
import Container from 'react-bootstrap/Container'
import Row from 'react-bootstrap/Row'
import Col from 'react-bootstrap/Col'
import Loading from 'src/components/Loading/Loading'

import { QueryVar, usePersonRelatedContentQuery } from 'src/data/queries/personRelatedContentQuery'
import { usePersonRelatedContentQuery } from 'src/data/queries/personRelatedContentQuery'

import Error from 'src/components/Error/Error'
import WorksListing from 'src/components/WorksListing/WorksListing'
import { pluralize } from 'src/utils/helpers';
import { useParams, useSearchParams } from 'next/navigation'
import mapSearchparams from './mapSearchParams'

interface Props {
orcid: string
variables: QueryVar
isBot?: boolean
}

export default function RelatedContent(props: Props) {
const { orcid, variables, isBot = false } = props
const { isBot = false } = props
const orcid = useParams().orcid as string

const { loading, data, error } = usePersonRelatedContentQuery(variables)
const searchParams = useSearchParams()
const { variables } = mapSearchparams(Object.fromEntries(searchParams.entries()) as any)

const vars = { id: 'http://orcid.org/' + orcid, ...variables }

const { loading, data, error } = usePersonRelatedContentQuery(vars)

if (isBot) return null

Expand Down
31 changes: 31 additions & 0 deletions src/app/orcid.org/[orcid]/mapSearchParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
export interface SearchParams {
filterQuery?: string
cursor?: string
published?: string
"resource-type"?: string
language?: string
license?: string
"field-of-science"?: string
"registration-agency"?: string

isBot: string
}

export default function mapSearchparams(searchParams: SearchParams) {
return {
variables: {
filterQuery: searchParams.filterQuery,
cursor: searchParams.cursor,
published: searchParams.published,
resourceTypeId: searchParams['resource-type'],
language: searchParams.language,
license: searchParams.license,
fieldOfScience: searchParams['field-of-science'],
registrationAgency: searchParams['registration-agency'],
},

isBot: false
}
}


37 changes: 6 additions & 31 deletions src/app/orcid.org/[orcid]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,14 @@ import Content from './Content'
import { fetchPersonMetadata } from 'src/data/queries/personQuery'
import RelatedContent from './RelatedContent'
import Loading from 'src/components/Loading/Loading'
import mapSearchparams, { SearchParams } from './mapSearchParams'


interface Props {
params: {
orcid: string
},
searchParams: {
filterQuery?: string
cursor?: string
published?: string
"resource-type"?: string
language?: string
license?: string
"field-of-science"?: string
"registration-agency"?: string

isBot: string
}
searchParams: SearchParams
}


Expand Down Expand Up @@ -88,25 +78,10 @@ export async function generateMetadata({ params }: Props): Promise<Metadata> {
}
}

function mapSearchparams(searchParams: Props['searchParams']) {
return {
filterQuery: searchParams.filterQuery,
cursor: searchParams.cursor,
published: searchParams.published,
resourceTypeId: searchParams['resource-type'],
language: searchParams.language,
license: searchParams.license,
fieldOfScience: searchParams['field-of-science'],
registrationAgency: searchParams['registration-agency'],
isBot: false
}
}


export default async function Page({ params, searchParams }: Props) {
const orcid = 'http://orcid.org/' + params.orcid
const { isBot, ...vars } = mapSearchparams(searchParams)
const variables = { id: orcid, ...vars }
const { variables } = mapSearchparams(searchParams)
const vars = { id: orcid, ...variables }


// Fetch Person metadata
Expand All @@ -117,9 +92,9 @@ export default async function Page({ params, searchParams }: Props) {

return <>
<Suspense fallback={<Loading />}>
<Content variables={variables} isBot={isBot} />
<Content variables={vars} />
</Suspense>
<RelatedContent orcid={params.orcid} variables={variables} isBot={isBot} />
<RelatedContent />
</>
}

Expand Down
6 changes: 3 additions & 3 deletions src/components/Person/Person.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use client'

import React from 'react'
import Row from 'react-bootstrap/Row'
import Col from 'react-bootstrap/Col'
import Alert from 'react-bootstrap/Alert'
import Image from 'next/image'
import heroImage from '../../../public/images/hero.svg'
import unlockImage from '../../../public/images/unlock.svg'
import scienceImage from '../../../public/images/science.svg'
import { Alert, Row, Col } from 'react-bootstrap'

import { Person as PersonType } from 'src/data/types'
import PersonMetadata from 'src/components/PersonMetadata/PersonMetadata'
Expand Down
5 changes: 4 additions & 1 deletion src/components/PersonMetadata/PersonMetadata.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import React from 'react'
import { Alert, Row, Col, Badge } from 'react-bootstrap'
import Row from 'react-bootstrap/Row'
import Col from 'react-bootstrap/Col'
import Alert from 'react-bootstrap/Alert'
import Badge from 'react-bootstrap/Badge'
import { Person } from 'src/data/types'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { faOrcid } from '@fortawesome/free-brands-svg-icons'
Expand Down

0 comments on commit 2a214c8

Please sign in to comment.