standartized "goBack" button

This commit is contained in:
2026-11-12 23:01:38 +01:00
parent faa22e0a8f
commit 9535bfedf5
17 changed files with 141 additions and 158 deletions
@@ -4,10 +4,6 @@
[subtitle]="unavailable()?.body ?? null"
[titleTooltip]="unavailable() ? null : pageTooltip">
<div pageMeta class="meta-block">
<a class="back-link" routerLink="/multipliers">
<mat-icon>{{ ARROW_BACK_ICON }}</mat-icon>
Zurück zur Multiplikatoren-Übersicht
</a>
@if (!unavailable()) {
<div class="meta-line">
@if (careerBucket()) {
@@ -147,8 +143,8 @@
</mat-icon>
</h2>
<p class="metrics-caption">
Rang 0–100 im Vergleich zu Personen derselben Karrierestufe.
Ab 85 % wird ein Rollen-Badge vergeben.
Rang 0–100 im Vergleich zu Personen derselben Karrierestufe. Ab
85 % wird ein Rollen-Badge vergeben.
</p>
@for (group of metricGroups(); track group.key) {
<div class="metric-group">
@@ -3,26 +3,6 @@
min-width: 0;
}
.back-link {
display: inline-flex;
align-items: center;
gap: 4px;
margin-bottom: 6px;
color: var(--sg-text-muted);
font-size: 13px;
text-decoration: none;
mat-icon {
font-size: 18px;
width: 18px;
height: 18px;
}
&:hover {
color: var(--sg-blue-highlight);
}
}
.meta-block {
margin-top: 8px;
}
@@ -1,14 +1,5 @@
<app-page-container>
<div class="detail-page">
<button
type="button"
class="back-link"
(click)="navigateBack()"
aria-label="Zurück zu den Nachrichten">
<mat-icon>{{ ARROW_BACK_ICON }}</mat-icon>
Alle Nachrichten
</button>
@if (loading) {
<app-loading
text="Nachricht wird geladen..."
@@ -3,29 +3,6 @@
min-width: 0;
}
.back-link {
display: inline-flex;
align-items: center;
gap: 6px;
background: none;
border: none;
cursor: pointer;
font-size: 14px;
color: var(--sg-text-muted);
padding: 0;
margin-bottom: 32px;
&:hover {
color: var(--sg-text);
}
mat-icon {
font-size: 18px;
width: 18px;
height: 18px;
}
}
.state {
display: flex;
flex-direction: column;
@@ -20,7 +20,6 @@ import { WorksService } from '../../api';
import { topicHierarchyColor } from '../../resolvers/utils/topic-colors';
import { LoadingComponent } from '../../shared/ui/loading/loading.component';
import {
ARROW_BACK_ICON,
CANCEL_ICON,
CHECK_CIRCLE_ICON,
CHEVRON_LEFT_ICON,
@@ -80,7 +79,6 @@ interface NewsArticleDetail {
styleUrl: './news-detail.component.scss',
})
export class NewsDetailComponent implements OnInit {
readonly ARROW_BACK_ICON = ARROW_BACK_ICON;
readonly NEWS_ICON = NEWS_ICON;
readonly SEARCH_OFF_ICON = SEARCH_OFF_ICON;
readonly CHECK_CIRCLE_ICON = CHECK_CIRCLE_ICON;
@@ -182,10 +180,6 @@ export class NewsDetailComponent implements OnInit {
});
}
navigateBack(): void {
this.router.navigate(['/news']);
}
formatDate(dateStr?: string | null): string {
if (!dateStr) return '-';
const date = new Date(dateStr);
@@ -1,14 +1,5 @@
<app-page-container>
<div class="detail-page">
<button
type="button"
class="back-link"
(click)="navigateBack()"
aria-label="Zurück zu den Patenten">
<mat-icon>{{ ARROW_BACK_ICON }}</mat-icon>
Alle Patente
</button>
@if (loading) {
<app-loading
text="Patent wird geladen..."
@@ -8,27 +8,6 @@
min-width: 0;
}
.back-link {
display: inline-flex;
align-items: center;
gap: 7px;
margin-bottom: 22px;
padding: 0;
border: 0;
background: transparent;
color: var(--sg-text-muted);
font-size: 13px;
font-weight: 600;
text-decoration: none;
cursor: pointer;
}
.back-link mat-icon {
width: 18px;
height: 18px;
font-size: 18px;
}
.hero {
display: grid;
grid-template-columns: minmax(0, 1fr) 420px;
@@ -1,4 +1,3 @@
import { Location } from '@angular/common';
import { Component, DestroyRef, OnInit, inject } from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { MatButtonModule } from '@angular/material/button';
@@ -16,7 +15,6 @@ import {
} from '../../resolvers/utils/topic-colors';
import { LoadingComponent } from '../../shared/ui/loading/loading.component';
import {
ARROW_BACK_ICON,
BUSINESS_ICON,
CATEGORY_ICON,
ENGINEERING_ICON,
@@ -58,7 +56,6 @@ import { PageContainerComponent } from '../../shared/ui/page-container/page-cont
styleUrl: './patent-detail.component.scss',
})
export class PatentDetailComponent implements OnInit {
readonly ARROW_BACK_ICON = ARROW_BACK_ICON;
readonly PATENT_ICON = PATENT_ICON;
readonly SEARCH_OFF_ICON = SEARCH_OFF_ICON;
readonly OPEN_IN_NEW_ICON = OPEN_IN_NEW_ICON;
@@ -76,7 +73,6 @@ export class PatentDetailComponent implements OnInit {
private readonly destroyRef = inject(DestroyRef);
private readonly route = inject(ActivatedRoute);
private readonly patentsService = inject(PatentsService);
private readonly location = inject(Location);
patent: PatentEntry | null = null;
loading = true;
@@ -104,10 +100,6 @@ export class PatentDetailComponent implements OnInit {
});
}
navigateBack(): void {
this.location.back();
}
formatDate(date: string | null | undefined): string {
return formatPatentDate(date);
}
@@ -10,17 +10,6 @@
? null
: 'Suche Patente aus EPO und USPTO und filtere nach Zeitraum, Themen und Klassifikationen.'
">
@if (showDetail && selectedPatent) {
<button
pageActions
mat-stroked-button
color="primary"
type="button"
(click)="closeDetail()">
← Zurück zu den Patenten
</button>
}
@if (error) {
<p class="state-message error">Fehler beim Laden der Patente.</p>
} @else if (showDetail && selectedPatent) {
@@ -24,6 +24,7 @@ import {
import { FilterCardComponent } from '../../shared/ui/filter-card/filter-card.component';
import { HELP_ICON, PATENT_ICON } from '../../shared/ui/icons';
import { PageContainerComponent } from '../../shared/ui/page-container/page-container.component';
import { BackNavigationService } from '../../shared/services/back-navigation.service';
type PatentSource = 'EPO' | 'USPTO';
@@ -69,6 +70,8 @@ export class PatentsComponent {
private route = inject(ActivatedRoute);
private patentsApi = inject(PatentsService);
private destroyRef = inject(DestroyRef);
private backNavigation = inject(BackNavigationService);
private unregisterLocalBack: (() => void) | null = null;
patents: PatentEntry[] = [];
total = 0;
@@ -92,6 +95,8 @@ export class PatentsComponent {
readonly expandedClassificationKeys = new Set<string>();
constructor() {
this.destroyRef.onDestroy(() => this.unregisterLocalBack?.());
this.route.queryParams
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((qp) => {
@@ -181,12 +186,20 @@ export class PatentsComponent {
}
selectPatent(patent: PatentEntry): void {
this.unregisterLocalBack?.();
this.unregisterLocalBack = this.backNavigation.registerLocalBack(() =>
this.closeDetail(),
);
this.selectedPatent = patent;
this.showDetail = true;
this.expandedClassificationKeys.clear();
}
closeDetail(): void {
this.unregisterLocalBack?.();
this.unregisterLocalBack = null;
this.showDetail = false;
this.selectedPatent = null;
this.expandedClassificationKeys.clear();
@@ -172,7 +172,4 @@ export class BundDetailsComponent implements OnInit {
return 'var(--sg-text-muted)';
}
}
goBack(): void {
window.history.back();
}
}
@@ -279,8 +279,4 @@ export class DfgDetailsComponent implements OnInit {
queryParams: { search: institutionName },
});
}
goBack(): void {
window.history.back();
}
}
@@ -1,14 +1,5 @@
<app-page-container>
<div class="detail-page">
<button
type="button"
class="back-link"
(click)="navigateBack()"
[attr.aria-label]="returnAriaLabel">
<mat-icon>{{ ARROW_BACK_ICON }}</mat-icon>
{{ returnLabel }}
</button>
@if (loading) {
<app-loading
text="Publikation wird geladen..."
@@ -8,27 +8,6 @@
min-width: 0;
}
.back-link {
display: inline-flex;
align-items: center;
gap: 7px;
margin-bottom: 22px;
padding: 0;
border: 0;
background: transparent;
color: var(--sg-text-muted);
font-size: 13px;
font-weight: 600;
text-decoration: none;
cursor: pointer;
}
.back-link mat-icon {
width: 18px;
height: 18px;
font-size: 18px;
}
.hero {
display: grid;
grid-template-columns: minmax(0, 1fr) 420px;
@@ -24,8 +24,8 @@ import { LanguageCodePipe } from '../../shared/pipes/language-code.pipe';
import { WorkPrimaryCategoryPipe } from '../../shared/pipes/work-primary-category.pipe';
import { ResearchProfileComponent } from './research-profile/research-profile.component';
import { PageContainerComponent } from '../../shared/ui/page-container/page-container.component';
import { BackNavigationService } from '../../shared/services/back-navigation.service';
import {
ARROW_BACK_ICON,
CHEVRON_LEFT_ICON,
CHEVRON_RIGHT_ICON,
CITATION_ICON,
@@ -82,7 +82,6 @@ interface InstitutionDetail {
styleUrl: './publication-detail.component.scss',
})
export class PublicationDetailComponent implements OnInit {
readonly ARROW_BACK_ICON = ARROW_BACK_ICON;
readonly PUBLICATION_ICON = PUBLICATION_ICON;
readonly SEARCH_OFF_ICON = SEARCH_OFF_ICON;
readonly OPEN_IN_NEW_ICON = OPEN_IN_NEW_ICON;
@@ -109,6 +108,7 @@ export class PublicationDetailComponent implements OnInit {
private readonly httpClient = inject(HttpClient);
private readonly location = inject(Location);
private readonly router = inject(Router);
private readonly backNavigation = inject(BackNavigationService);
private readonly worksService = inject(WorksService);
workClassification = input.required<WorkClassification | null>();
@@ -130,20 +130,22 @@ export class PublicationDetailComponent implements OnInit {
readonly institutionsPageSize = 5;
returnUrl: string | null = null;
returnLabel = 'Alle Publikationen';
returnAriaLabel = 'Zurück zu den Publikationen';
ngOnInit(): void {
this.loading = true;
const navigationState = this.location.getState() as {
returnUrl?: string;
returnLabel?: string;
} | null;
if (navigationState?.returnUrl) {
this.returnUrl = navigationState.returnUrl;
this.returnLabel = navigationState.returnLabel ?? 'Zurück';
this.returnAriaLabel = `Zurück zu ${this.returnLabel}`;
// The topbar back button should return to the page the user came from,
// not to an unrelated history entry.
const unregister = this.backNavigation.registerLocalBack(() =>
this.navigateBack(),
);
this.destroyRef.onDestroy(unregister);
}
this.route.data.pipe(takeUntilDestroyed(this.destroyRef)).subscribe({
@@ -0,0 +1,114 @@
import { Location } from '@angular/common';
import { Injectable, computed, inject, signal } from '@angular/core';
import { Router } from '@angular/router';
type BackHandler = () => void;
const ROOT_PATHS = new Set([
'/dashboard',
'/compare',
'/multipliers',
'/founders',
'/bookmarks',
'/persons',
'/keywords',
'/hierarchy',
'/news',
'/account',
'/accounts',
'/organizations',
'/jobs',
'/publications',
'/topics',
'/projects',
'/patents',
'/institutions',
'/login',
'/forgot-password',
'/reset-password',
'/icons',
'/error',
]);
const FALLBACKS: ReadonlyArray<{ prefix: string; target: string }> = [
{ prefix: '/person/', target: '/persons' },
{ prefix: '/publication/', target: '/publications' },
{ prefix: '/patent/', target: '/patents' },
{ prefix: '/news/', target: '/news' },
{ prefix: '/institution/', target: '/institutions' },
{ prefix: '/topic/', target: '/topics' },
{ prefix: '/projects/', target: '/projects' },
{ prefix: '/founders/', target: '/multipliers' },
{ prefix: '/keywords/', target: '/keywords' },
{ prefix: '/error', target: '/dashboard' },
];
@Injectable({ providedIn: 'root' })
export class BackNavigationService {
private readonly router = inject(Router);
private readonly location = inject(Location);
// In-page detail views (e.g. the inline patent detail) own the back action
// while they are open. The topbar button executes the newest handler.
private readonly localHandlers = signal<readonly BackHandler[]>([]);
readonly hasLocalHandler = computed(() => this.localHandlers().length > 0);
/**
* Registers a back action for an in-page detail view. Returns an unregister
* function that the component calls when the view closes or is destroyed.
*/
registerLocalBack(handler: BackHandler): () => void {
this.localHandlers.update((handlers) => [...handlers, handler]);
return () => {
this.localHandlers.update((handlers) =>
handlers.filter((candidate) => candidate !== handler),
);
};
}
/** True when this tab has at least one earlier in-app navigation. */
canGoBack(): boolean {
const state = history.state as { navigationId?: number } | null;
return (state?.navigationId ?? 0) > 1;
}
/**
* Goes back in history when that is safe, otherwise navigates to the
* section that owns the current detail page.
*/
back(fallback?: string): void {
const handlers = this.localHandlers();
const localHandler = handlers[handlers.length - 1];
if (localHandler) {
localHandler();
return;
}
if (this.canGoBack()) {
this.location.back();
return;
}
void this.router.navigateByUrl(
fallback ?? this.fallbackFor(this.router.url),
);
}
/** Whether the current URL is a top-level section. */
isRoot(url: string): boolean {
return ROOT_PATHS.has(this.pathOf(url));
}
fallbackFor(url: string): string {
const path = this.pathOf(url);
const match = FALLBACKS.find(({ prefix }) => path.startsWith(prefix));
return match?.target ?? '/dashboard';
}
private pathOf(url: string): string {
return url.split('?')[0].split('#')[0] || '/';
}
}
@@ -93,7 +93,9 @@ export class AppLayoutComponent implements OnInit, OnDestroy {
private readonly currentPath = signal('/');
readonly showBack = computed(
() => !this.backNavigation.isRoot(this.currentPath()),
() =>
this.backNavigation.hasLocalHandler() ||
!this.backNavigation.isRoot(this.currentPath()),
);
private readonly sidebarCollapsedStorageKey = 'inse.sidebar.collapsed';