added shared state service, search bar is now active
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
import { Injectable, signal } from '@angular/core';
|
||||
import { Person } from '../../api';
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class SharedStateService {
|
||||
|
||||
searchValue = signal<string | null>(null);
|
||||
persons = signal<Person[]>([]);
|
||||
hasSearched = signal<boolean>(false);
|
||||
}
|
||||
@@ -29,7 +29,7 @@
|
||||
<mat-icon>menu</mat-icon>
|
||||
</button>
|
||||
}
|
||||
<button class="back-link" type="button">
|
||||
<button (click)="navigateBack()"class="back-link" type="button">
|
||||
<mat-icon>arrow_back</mat-icon>
|
||||
<span>Zurück zur Suche</span>
|
||||
</button>
|
||||
@@ -38,8 +38,10 @@
|
||||
<label class="search-box">
|
||||
<mat-icon>search</mat-icon>
|
||||
<input
|
||||
[formControl]="searchValue"
|
||||
type="search"
|
||||
placeholder="Suchen nach Personen, Themen, Projekten..."
|
||||
(keyup.enter)="startSearch()"
|
||||
/>
|
||||
</label>
|
||||
|
||||
|
||||
@@ -4,15 +4,18 @@ import { MatToolbarModule } from '@angular/material/toolbar';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatDrawer, MatSidenavModule } from '@angular/material/sidenav';
|
||||
import { Router, RouterLink } from '@angular/router';
|
||||
import { Router} from '@angular/router';
|
||||
import { MediaMatcher } from '@angular/cdk/layout';
|
||||
import { AppMenuComponent } from '../app-menu/app-menu.component';
|
||||
import { MatTooltipModule } from '@angular/material/tooltip';
|
||||
import { CredentialService } from '../../services/credential.service';
|
||||
import { FormControl,ReactiveFormsModule } from '@angular/forms';
|
||||
import { SharedStateService } from '../../services/shared-state.service';
|
||||
import { Location } from '@angular/common';
|
||||
|
||||
@Component({
|
||||
selector: 'app-layout',
|
||||
imports: [CommonModule, MatToolbarModule, MatSidenavModule, MatButtonModule, MatIconModule, RouterLink, AppMenuComponent, MatTooltipModule],
|
||||
imports: [CommonModule, MatToolbarModule, MatSidenavModule, MatButtonModule, MatIconModule, AppMenuComponent, MatTooltipModule,ReactiveFormsModule],
|
||||
templateUrl: './app-layout.component.html',
|
||||
styleUrl: './app-layout.component.scss',
|
||||
standalone: true,
|
||||
@@ -27,8 +30,10 @@ export class AppLayoutComponent implements OnInit, OnDestroy {
|
||||
mediaQueryListener: () => void;
|
||||
|
||||
sideNavOpen = false;
|
||||
|
||||
searchValue = new FormControl('');
|
||||
constructor(public credentialService: CredentialService, public router: Router,
|
||||
private location:Location,
|
||||
private state: SharedStateService,
|
||||
public changeDetector: ChangeDetectorRef, media: MediaMatcher) {
|
||||
this.mediaQuery = media.matchMedia('(max-width: 600px)');
|
||||
this.mediaQueryListener = () => {
|
||||
@@ -56,5 +61,15 @@ export class AppLayoutComponent implements OnInit, OnDestroy {
|
||||
this.credentialService.logoutAcount();
|
||||
this.router.navigate(['/'])
|
||||
}
|
||||
startSearch(){
|
||||
console.log("updated to", this.searchValue.value,this.router.url)
|
||||
|
||||
if (this.router.url.startsWith('/persons')) {
|
||||
this.router.navigate(['/persons']);
|
||||
}
|
||||
this.state.searchValue.set(this.searchValue.value);
|
||||
}
|
||||
navigateBack(){
|
||||
this.location.back()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import { CredentialService } from '../../services/credential.service';
|
||||
export class AppMenuComponent {
|
||||
navItems = [
|
||||
{ label: 'Dashboard', icon: 'dashboard', route: '/items', disabled: false },
|
||||
{ label: 'Personen', icon: 'groups', route: '/person/0', disabled: false },
|
||||
{ label: 'Personen', icon: 'groups', route: '/persons', disabled: false },
|
||||
];
|
||||
|
||||
constructor(public credentialService: CredentialService) {}
|
||||
|
||||
Reference in New Issue
Block a user