Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions pages/findings/[id].js
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,33 @@ import NotFound from 'components/NotFound'
import FindingDisplay from 'components/findings/FindingDisplay'
import StructuredData from 'components/StructuredData'
import { getFindingStructuredData } from 'lib/findingStructuredData'
import { useMemo } from 'react'
import { useIntl } from 'react-intl'

export const getServerSideProps = async ({ query, req }) => {
const data = await fetcher(
apiEndpoints.SHOW_INCIDENT.replace(':id', query.id),
).catch(() => null)

const canonicalUrl = `${process.env.NEXT_PUBLIC_EXPLORER_URL}/findings/${query.id}`

return {
props: {
data,
canonicalUrl: `${process.env.NEXT_PUBLIC_EXPLORER_URL}/findings/${query.id}`,
canonicalUrl,
structuredData: data?.incident
? getFindingStructuredData(data.incident, canonicalUrl)
: null,
isEmbeddedView: !!req.headers['enable-embedded-view'] || !!query?.webview,
},
}
}

const ReportView = ({ data, canonicalUrl }) => {
const ReportView = ({ data, canonicalUrl, structuredData }) => {
const intl = useIntl()

const metaTitle = `${!!data?.incident?.title && `${data?.incident?.title} | `}${intl.formatMessage({ id: 'General.OoniExplorer' })}`
const metaDescription = data?.incident?.short_description

const findingStructuredData = useMemo(() => {
if (!data?.incident) {
return null
}

return getFindingStructuredData(data.incident, canonicalUrl)
}, [canonicalUrl, data?.incident])

return (
<>
<Head>
Expand All @@ -54,8 +50,8 @@ const ReportView = ({ data, canonicalUrl }) => {
content={metaDescription}
/>
<link rel="canonical" key="canonical" href={canonicalUrl} />
{findingStructuredData && (
<StructuredData data={findingStructuredData} />
{structuredData && (
<StructuredData data={structuredData} />
)}
</Head>
<div className="container">
Expand Down