fix(publication-card): stop card clicks navigating to /topic, wire chips to search filters
This commit is contained in:
@@ -16,7 +16,10 @@
|
||||
</div>
|
||||
|
||||
<ng-template #cardTmp let-work>
|
||||
<app-publication-card [work]="work" />
|
||||
<app-publication-card
|
||||
[work]="work"
|
||||
(topicChipClick)="filterByTopic($event)"
|
||||
(authorChipClick)="filterByAuthor($event)" />
|
||||
</ng-template>
|
||||
|
||||
<ng-template #additionalFiltersTmp>
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import { Component, computed, input } from '@angular/core';
|
||||
import { Component, computed, inject, input } from '@angular/core';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import {
|
||||
Author,
|
||||
AuthorPage,
|
||||
InstitutionPageV2,
|
||||
SortDirection,
|
||||
Topic,
|
||||
TopicPageV2,
|
||||
WorkPageV2,
|
||||
WorkSortBy,
|
||||
@@ -15,6 +18,7 @@ import { MatDivider } from '@angular/material/divider';
|
||||
import { AppPublicationCardComponent } from '../../shared/ui/app-publication-card/app-publication-card.component';
|
||||
import { PublicationFilterComponent } from '../../shared/ui/publication-filters/publication-filters.component';
|
||||
import { SelectorOption } from '../../shared/ui/query-param-selector/query-param-selector.component';
|
||||
import { workQueryParamKeys } from '../../resolvers/work-page.resolver';
|
||||
|
||||
@Component({
|
||||
selector: 'app-publications',
|
||||
@@ -28,6 +32,9 @@ import { SelectorOption } from '../../shared/ui/query-param-selector/query-param
|
||||
styleUrl: './publications.component.scss',
|
||||
})
|
||||
export class PublicationsComponent {
|
||||
private readonly route = inject(ActivatedRoute);
|
||||
private readonly router = inject(Router);
|
||||
|
||||
workPage = input.required<WorkPageV2>();
|
||||
selectedAuthorsPage = input.required<AuthorPage>();
|
||||
selectedInstitutionsPage = input.required<InstitutionPageV2>();
|
||||
@@ -48,4 +55,42 @@ export class PublicationsComponent {
|
||||
{ value: SortDirection.Asc, display_name: 'Aufsteigend' },
|
||||
{ value: SortDirection.Desc, display_name: 'Absteigend' },
|
||||
];
|
||||
|
||||
filterByTopic(topic: Topic): void {
|
||||
if (!topic.id) return;
|
||||
|
||||
const selectedTopicIds = this.route.snapshot.queryParamMap.getAll(
|
||||
workQueryParamKeys.topicId,
|
||||
);
|
||||
const nextTopicIds = selectedTopicIds.includes(topic.id)
|
||||
? selectedTopicIds.filter((id) => id !== topic.id)
|
||||
: [...selectedTopicIds, topic.id];
|
||||
|
||||
this.router.navigate([], {
|
||||
queryParams: {
|
||||
[workQueryParamKeys.topicId]: nextTopicIds,
|
||||
[workQueryParamKeys.page]: 0,
|
||||
},
|
||||
queryParamsHandling: 'merge',
|
||||
});
|
||||
}
|
||||
|
||||
filterByAuthor(author: Author): void {
|
||||
if (!author.id) return;
|
||||
|
||||
const selectedAuthorIds = this.route.snapshot.queryParamMap.getAll(
|
||||
workQueryParamKeys.authorId,
|
||||
);
|
||||
const nextAuthorIds = selectedAuthorIds.includes(author.id)
|
||||
? selectedAuthorIds.filter((id) => id !== author.id)
|
||||
: [...selectedAuthorIds, author.id];
|
||||
|
||||
this.router.navigate([], {
|
||||
queryParams: {
|
||||
[workQueryParamKeys.authorId]: nextAuthorIds,
|
||||
[workQueryParamKeys.page]: 0,
|
||||
},
|
||||
queryParamsHandling: 'merge',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,8 +77,6 @@ export class AppAuthorChipComponent {
|
||||
if (this.handleChipClick && author) {
|
||||
this.handleChipClick.emit(author);
|
||||
}
|
||||
|
||||
console.log('Chip clicked:', event);
|
||||
}
|
||||
|
||||
stripOpenAlexId(id: string | null | undefined): string | undefined {
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
@let work = this.work();
|
||||
|
||||
<mat-card
|
||||
class="card-content popup"
|
||||
appearance="outlined"
|
||||
[routerLink]="work.id ? ['/topic', stripOpenAlexId(work.id)] : null">
|
||||
<mat-card class="card-content popup" appearance="outlined">
|
||||
<mat-card-header>
|
||||
<mat-card-title>{{ work.title }}</mat-card-title>
|
||||
<mat-card-subtitle class="subtitle">
|
||||
@@ -22,7 +19,11 @@
|
||||
</div>
|
||||
<div class="chips chips-column">
|
||||
@for (topic of visibleTopics(); track topic.id) {
|
||||
<app-topic-chip-2 [topic]="topic" />
|
||||
<app-topic-chip-2
|
||||
[topic]="topic"
|
||||
[isClickable]="true"
|
||||
(handleChipClick)="topicChipClick.emit($event)"
|
||||
(click)="$event.stopPropagation()" />
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
@@ -35,7 +36,11 @@
|
||||
</div>
|
||||
<div class="chips chips-authors">
|
||||
@for (author of visibleAuthors(); track author.id) {
|
||||
<app-author-chip [author]="author" />
|
||||
<app-author-chip
|
||||
[author]="author"
|
||||
[isClickable]="true"
|
||||
(handleChipClick)="authorChipClick.emit($event)"
|
||||
(click)="$event.stopPropagation()" />
|
||||
}
|
||||
@if (hiddenAuthorCount() > 0) {
|
||||
<span class="chip-overflow">+{{ hiddenAuthorCount() }}</span>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Component, computed, input } from '@angular/core';
|
||||
import { DehydratedAuthor, Work } from '../../../api';
|
||||
import { Component, computed, input, output } from '@angular/core';
|
||||
import { Author, DehydratedAuthor, Topic, Work } from '../../../api';
|
||||
import { MatCardModule } from '@angular/material/card';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
@@ -34,6 +34,9 @@ const MAX_VISIBLE_AUTHORS = 3;
|
||||
export class AppPublicationCardComponent {
|
||||
work = input.required<Work>();
|
||||
|
||||
topicChipClick = output<Topic>();
|
||||
authorChipClick = output<Author>();
|
||||
|
||||
stripOpenAlexId(id: string | null | undefined): string | undefined {
|
||||
if (!id) {
|
||||
return undefined;
|
||||
|
||||
Reference in New Issue
Block a user