Skip to content

Commit

Permalink
fix(authors): fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihoub2 committed Sep 17, 2024
1 parent ea1ae25 commit 701ab1e
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 46 deletions.
110 changes: 65 additions & 45 deletions client/src/pages/authors/[id]/components/recent-affiliations/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,64 +6,84 @@ import { useQueryClient } from "@tanstack/react-query";
import LinkCard from "../../../../../components/link-card";
import { useIntl } from "react-intl";

export default function RecentAffiliations({ data }: { data: RecentAffiliation[] }) {
export default function RecentAffiliations({
data,
}: {
data: RecentAffiliation[];
}) {
const intl = useIntl();
const queryClient = useQueryClient();
const { locale } = useDSFRConfig();


function prefetch(id: string) {
if (!id) return;
queryClient.prefetchQuery({
queryKey: ['organization', id],
queryKey: ["organization", id],
queryFn: () => getOrganizationById(id),
})
});
}

const recents = data?.reduce((acc, { structure, sources }) => {
const years = sources?.map(source => source.year).filter(Boolean).map(year => parseInt(year, 10)) || [];
const minYear = Math.min(...years);
const maxYear = Math.max(...years);
const recents = data
?.reduce((acc, { structure, sources }) => {
const years =
sources
?.map((source) => source.year)
.filter(Boolean)
.map((year) => parseInt(year, 10)) || [];
const minYear = Math.min(...years);
const maxYear = Math.max(...years);

acc.push({
id: structure.id,
label: structure.label,
city: structure.mainAddress.city,
publicationCount: sources.length,
minYear,
maxYear,

});
acc.push({
id: structure.id,
label: structure.label,
city: structure.mainAddress?.city,
publicationCount: sources.length,
minYear,
maxYear,
});

return acc;
}, []).sort((a, b) => b.maxYear - a.maxYear);
return acc;
}, [])
.sort((a, b) => b.maxYear - a.maxYear);

return (
<Row gutters>
{recents?.map(({ id, label, city, publicationCount, minYear, maxYear }) => (
<Col key={id} xs="12">
<LinkCard prefetch={() => prefetch(id)} type="organization" icon="building-line">
{city && (
<Text className="fr-text-mention--grey fr-mb-0" size="sm">
<em>
{city}
</em>
</Text>
)}
<Link className="fr-text--bold" href={`/organizations/${id}`}>
{getLangFieldValue(locale)(label)}
</Link>
{publicationCount && <Text className="fr-text-mention--grey fr-mb-0" size="sm">
{intl.formatMessage({ id: "authors.section.recent-affiliations.publication-count" }, { count: publicationCount })}
{' '}
{(minYear !== maxYear)
? intl.formatMessage({ id: "authors.section.recent-affiliations.between" }, { min: minYear, max: maxYear })
: minYear
}
</Text>}
</LinkCard>
</Col>
))}
{recents?.map(
({ id, label, city, publicationCount, minYear, maxYear }) => (
<Col key={id} xs="12">
<LinkCard
prefetch={() => prefetch(id)}
type="organization"
icon="building-line"
>
{city && (
<Text className="fr-text-mention--grey fr-mb-0" size="sm">
<em>{city}</em>
</Text>
)}
<Link className="fr-text--bold" href={`/organizations/${id}`}>
{getLangFieldValue(locale)(label)}
</Link>
{publicationCount && (
<Text className="fr-text-mention--grey fr-mb-0" size="sm">
{intl.formatMessage(
{
id: "authors.section.recent-affiliations.publication-count",
},
{ count: publicationCount }
)}{" "}
{minYear !== maxYear
? intl.formatMessage(
{ id: "authors.section.recent-affiliations.between" },
{ min: minYear, max: maxYear }
)
: minYear}
</Text>
)}
</LinkCard>
</Col>
)
)}
</Row>
)
}
);
}
3 changes: 2 additions & 1 deletion client/src/pages/authors/[id]/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@
"search.publications.other": "Other",
"search.section.author.badge": "Author",
"search.publication.thesis.directed": " under the supervision of ",
"search.publications.thesis.and": " and "
"search.publications.thesis.and": " and ",
"search.publications.thesis.by": " by "
}

0 comments on commit 701ab1e

Please sign in to comment.