65 lines
2.1 KiB
TypeScript
65 lines
2.1 KiB
TypeScript
import EvidenceDetails from './evidence-details';
|
|
import { publicReference, publicSourceHref } from '@/lib/public-presentation';
|
|
type Source = {
|
|
title?: string | null;
|
|
url?: string | null;
|
|
source_date?: string | null;
|
|
supports?: string | null;
|
|
};
|
|
export default function PublicSourceList({ sources }: { sources?: Source[] }) {
|
|
const rows = new Map<
|
|
string,
|
|
{
|
|
title: string;
|
|
url?: string;
|
|
date?: string | null;
|
|
supports: string[];
|
|
}
|
|
>();
|
|
for (const source of sources ?? []) {
|
|
const url = publicSourceHref(source.url),
|
|
title =
|
|
publicReference(source.title) ||
|
|
(url ? new URL(url).hostname : null);
|
|
if (!title) continue;
|
|
const key = JSON.stringify([url || title, source.source_date || '']);
|
|
const row = rows.get(key) ?? {
|
|
title,
|
|
url,
|
|
date: source.source_date,
|
|
supports: [],
|
|
};
|
|
const support = publicReference(source.supports);
|
|
if (support && !row.supports.includes(support))
|
|
row.supports.push(support);
|
|
rows.set(key, row);
|
|
}
|
|
if (!rows.size) return null;
|
|
return (
|
|
<EvidenceDetails title="Fontes e datas">
|
|
<ul className="space-y-2">
|
|
{[...rows.entries()].map(([key, row]) => (
|
|
<li key={key}>
|
|
{row.url ? (
|
|
<a
|
|
className="underline"
|
|
href={row.url}
|
|
target="_blank"
|
|
rel="noreferrer"
|
|
>
|
|
{row.title}
|
|
</a>
|
|
) : (
|
|
<span>{row.title}</span>
|
|
)}
|
|
{row.date && <> · {row.date}</>}
|
|
{row.supports.map((text) => (
|
|
<p key={text}>{text}</p>
|
|
))}
|
|
</li>
|
|
))}
|
|
</ul>
|
|
</EvidenceDetails>
|
|
);
|
|
}
|