change service to openai-generated service
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
<aside class="interest-card">
|
||||
<h3>Interessant für</h3>
|
||||
<div class="interest-tags">
|
||||
@if (tags.length > 0) {
|
||||
@for (tag of tags; track tag.label) {
|
||||
<span>{{ tag.label }}</span>
|
||||
@if (tags().length > 0) {
|
||||
@for (tag of tags(); track tag.label) {
|
||||
<button type="button" class="interest-tag-button">{{ tag.label }}</button>
|
||||
}
|
||||
} @else {
|
||||
<span class="interest-empty">Keine Themen gefunden</span>
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.interest-tags span {
|
||||
.interest-tag-button {
|
||||
padding: 9px 16px;
|
||||
border: 1px solid #a8c0ff;
|
||||
border-radius: 7px;
|
||||
@@ -30,9 +30,30 @@
|
||||
color: var(--sg-primary);
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
outline: none;
|
||||
transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.1s ease, box-shadow 0.2s ease;
|
||||
|
||||
&:hover {
|
||||
background-color: var(--sg-primary-light, #f0f4ff);
|
||||
border-color: var(--sg-primary);
|
||||
}
|
||||
|
||||
&:active {
|
||||
transform: scale(0.96);
|
||||
}
|
||||
|
||||
&:focus-visible {
|
||||
box-shadow: 0 0 0 2px var(--sg-primary-light, #f0f4ff), 0 0 0 4px var(--sg-primary);
|
||||
}
|
||||
}
|
||||
|
||||
.interest-tags .interest-empty {
|
||||
padding: 9px 16px;
|
||||
border: 1px solid #e2e8f0;
|
||||
border-style: dashed;
|
||||
border-radius: 7px;
|
||||
color: var(--sg-text-muted);
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Component, Input } from '@angular/core';
|
||||
import { Component, input, computed } from '@angular/core';
|
||||
|
||||
import { Topic } from '../../api';
|
||||
|
||||
@@ -14,23 +14,13 @@ interface InterestTag {
|
||||
styleUrl: './person-interesting.component.scss',
|
||||
})
|
||||
export class PersonInterestingComponent {
|
||||
private _topics: Topic[] = [];
|
||||
tags: InterestTag[] = [];
|
||||
readonly topics = input<Topic[] | null>(null);
|
||||
|
||||
@Input()
|
||||
set topics(value: Topic[] | null) {
|
||||
this._topics = value ?? [];
|
||||
this.tags = this.buildTags(this._topics);
|
||||
}
|
||||
|
||||
get topics(): Topic[] {
|
||||
return this._topics;
|
||||
}
|
||||
|
||||
private buildTags(topics: Topic[]): InterestTag[] {
|
||||
readonly tags = computed<InterestTag[]>(() => {
|
||||
const topicsList = this.topics() ?? [];
|
||||
const grouped = new Map<string, number>();
|
||||
|
||||
for (const topic of topics) {
|
||||
for (const topic of topicsList) {
|
||||
const label = (topic.subfield?.display_name ?? '').trim();
|
||||
if (!label) continue;
|
||||
|
||||
@@ -42,5 +32,5 @@ export class PersonInterestingComponent {
|
||||
.map(([label, score]) => ({ label, score }))
|
||||
.sort((a, b) => b.score - a.score)
|
||||
.slice(0, 8);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
import { Component, OnDestroy, OnInit, computed, inject } from '@angular/core';
|
||||
import { Component, OnDestroy, OnInit, computed, inject, signal } from '@angular/core';
|
||||
import { toSignal, toObservable } from '@angular/core/rxjs-interop';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatTabsModule } from '@angular/material/tabs';
|
||||
import { ActivatedRoute, RouterModule, RouterOutlet } from '@angular/router';
|
||||
import { Subscription } from 'rxjs';
|
||||
import { Subscription, map, of, switchMap } from 'rxjs';
|
||||
|
||||
import { Topic } from '../../api';
|
||||
import { PersonStore } from '../../shared/services/person-store.service';
|
||||
import { Person, PersonsOpenApiService, Topic } from '../../api';
|
||||
import { PersonInterestingComponent } from '../person-interesting/person-interesting.component';
|
||||
|
||||
const PERSON_INCLUDE_TAGS =
|
||||
'topics_full,topic_share,summary_stats,ids,last_known_institutions,' +
|
||||
'sources,counts_by_year,works_api_url,dates,cited_by_count_boost';
|
||||
|
||||
@Component({
|
||||
selector: 'app-person',
|
||||
imports: [
|
||||
@@ -22,10 +26,25 @@ import { PersonInterestingComponent } from '../person-interesting/person-interes
|
||||
})
|
||||
export class PersonComponent implements OnInit, OnDestroy {
|
||||
private route = inject(ActivatedRoute);
|
||||
readonly personStore = inject(PersonStore);
|
||||
private readonly personsApi = inject(PersonsOpenApiService);
|
||||
private routeSub?: Subscription;
|
||||
|
||||
readonly person = computed(() => this.personStore.person());
|
||||
private readonly authorId = signal<string | null>(null);
|
||||
|
||||
readonly person = toSignal(
|
||||
toObservable(this.authorId).pipe(
|
||||
switchMap((id) => {
|
||||
if (!id) {
|
||||
return of(null);
|
||||
}
|
||||
|
||||
return this.personsApi.searchPersons(id, undefined, PERSON_INCLUDE_TAGS).pipe(
|
||||
map((result) => result.persons?.[0] ?? null),
|
||||
);
|
||||
}),
|
||||
),
|
||||
{ initialValue: null },
|
||||
);
|
||||
readonly displayName = computed(
|
||||
() => this.person()?.name ?? 'Unbekannte Person',
|
||||
);
|
||||
@@ -49,7 +68,7 @@ export class PersonComponent implements OnInit, OnDestroy {
|
||||
readonly openAlexId = computed(() => this.person()?.id ?? null);
|
||||
|
||||
readonly topicsFull = computed(
|
||||
() => (this.personStore.person()?.topics_full ?? []) as Topic[],
|
||||
() => (this.person()?.topics_full ?? []) as Topic[],
|
||||
);
|
||||
|
||||
links = [
|
||||
@@ -63,7 +82,7 @@ export class PersonComponent implements OnInit, OnDestroy {
|
||||
ngOnInit(): void {
|
||||
this.routeSub = this.route.paramMap.subscribe((params) => {
|
||||
const authorId = params.get('id') ?? '';
|
||||
this.personStore.loadPerson(authorId);
|
||||
this.authorId.set(authorId ? authorId : null);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
import { Injectable, computed, signal } from '@angular/core';
|
||||
import { rxResource } from '@angular/core/rxjs-interop';
|
||||
import { map, of } from 'rxjs';
|
||||
|
||||
import { Person, PersonsOpenApiService } from '../../api';
|
||||
|
||||
const PERSON_INCLUDE_TAGS = //hardcoded for now to get all values for the person page
|
||||
'topics_full,topic_share,summary_stats,ids,last_known_institutions,' +
|
||||
'sources,counts_by_year,works_api_url,dates,cited_by_count_boost';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class PersonStore {
|
||||
private readonly authorId = signal<string | null>(null);
|
||||
|
||||
private readonly personResource = rxResource<Person | null, string | null>({
|
||||
params: () => this.authorId(),
|
||||
stream: ({ params }) => {
|
||||
if (!params) {
|
||||
return of(null);
|
||||
}
|
||||
|
||||
return this.personsApi.searchPersons(params, undefined, PERSON_INCLUDE_TAGS).pipe(
|
||||
map((result) => result.persons?.[0] ?? null),
|
||||
);
|
||||
},
|
||||
defaultValue: null,
|
||||
});
|
||||
|
||||
readonly person = computed(() => this.personResource.value());
|
||||
readonly loading = this.personResource.isLoading;
|
||||
readonly error = this.personResource.error;
|
||||
|
||||
constructor(private personsApi: PersonsOpenApiService) {}
|
||||
|
||||
loadPerson(authorId: string): void {
|
||||
this.authorId.set(authorId ? authorId : null);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user