diff --git a/webapp/src/app/modules/person-card/person-card.component.ts b/webapp/src/app/modules/person-card/person-card.component.ts index 89f0440c..6502b9c5 100644 --- a/webapp/src/app/modules/person-card/person-card.component.ts +++ b/webapp/src/app/modules/person-card/person-card.component.ts @@ -36,11 +36,25 @@ export class PersonCardComponent { } institution(person: CustomAuthor): DehydratedInstitution | undefined { - return ( - person.last_known_institutions?.[0] || - person.affiliations?.[person.affiliations.length - 1]?.institution || - undefined - ); + if (person.last_known_institutions?.[0]) { + return person.last_known_institutions[0]; + } + + const affiliations = person.affiliations ?? []; + let newestInstitution: DehydratedInstitution | undefined = + affiliations[0]?.institution ?? undefined; + let newestYear = -1; + + for (const affiliation of affiliations) { + for (const jahr of affiliation.years ?? []) { + if (jahr > newestYear) { + newestYear = jahr; + newestInstitution = affiliation.institution ?? undefined; + } + } + } + + return newestInstitution; } topics(person: CustomAuthor): WorkTopic[] { diff --git a/webapp/src/app/modules/person/person.component.ts b/webapp/src/app/modules/person/person.component.ts index a74be3fe..13b866bd 100644 --- a/webapp/src/app/modules/person/person.component.ts +++ b/webapp/src/app/modules/person/person.component.ts @@ -119,15 +119,20 @@ export class PersonComponent { () => this.person()?.affiliations?.[0] ?? null, ); readonly lastAffiliation = computed(() => { - let lastAffiliation: number | undefined = 0; - if (this.person()?.affiliations?.length != undefined) { - lastAffiliation = this.person()?.affiliations?.length; + const affiliations = this.person()?.affiliations ?? []; + let newestAffiliation = affiliations[0] ?? null; + let newestYear = -1; + + for (const affiliation of affiliations) { + for (const jahr of affiliation.years ?? []) { + if (jahr > newestYear) { + newestYear = jahr; + newestAffiliation = affiliation; + } + } } - return ( - (lastAffiliation - ? this.person()?.affiliations?.[lastAffiliation - 1] - : this.person()?.affiliations?.[0]) ?? null - ); + + return newestAffiliation; }); readonly institution = computed( () =>