Skip to content

Commit

Permalink
Merge pull request #1695 from DSD-DBS/projects-sort-search
Browse files Browse the repository at this point in the history
feat: Make project view searchable and sorted
  • Loading branch information
MoritzWeber0 authored Aug 12, 2024
2 parents ed27e12 + 7f9d1e7 commit b02371a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@
~ SPDX-License-Identifier: Apache-2.0
-->

<div class="px-2.5">
<mat-form-field id="search" appearance="outline" class="w-full">
<mat-label>Search</mat-label>
<input
autocomplete="off"
matInput
placeholder="Project Name"
type="text"
[formControl]="searchControl"
/>
<mat-icon matSuffix>search</mat-icon>
</mat-form-field>
</div>

<div class="flex flex-wrap">
<a routerLink="/projects/create" class="m-2.5">
<div matRipple class="mat-card-overview new collab-card !m-0">
Expand All @@ -15,12 +29,12 @@
</div>
</a>
<app-mat-card-overview-skeleton-loader
[loading]="(projectService.projects$ | async) === undefined"
[loading]="(filteredProjects$ | async) === undefined"
></app-mat-card-overview-skeleton-loader>
<ng-container *ngIf="projectService.projects$ | async">
<ng-container *ngIf="filteredProjects$ | async">
<a
class="m-2.5"
*ngFor="let project of (projectService.projects$ | async)!"
*ngFor="let project of (filteredProjects$ | async)!"
[routerLink]="['/project', project.slug]"
>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,18 @@

import { NgIf, NgFor, NgClass, AsyncPipe } from '@angular/common';
import { Component, OnInit } from '@angular/core';
import { FormControl, FormsModule, ReactiveFormsModule } from '@angular/forms';
import { MatRipple } from '@angular/material/core';
import {
MatFormField,
MatLabel,
MatSuffix,
} from '@angular/material/form-field';
import { MatIcon } from '@angular/material/icon';
import { MatInput } from '@angular/material/input';
import { RouterLink } from '@angular/router';
import { map, startWith } from 'rxjs';
import { switchMap } from 'rxjs/operators';
import { MatIconComponent } from '../../helpers/mat-icon/mat-icon.component';
import { MatCardOverviewSkeletonLoaderComponent } from '../../helpers/skeleton-loaders/mat-card-overview-skeleton-loader/mat-card-overview-skeleton-loader.component';
import { ProjectWrapperService } from '../service/project.service';
Expand All @@ -27,9 +36,32 @@ import { ProjectWrapperService } from '../service/project.service';
NgClass,
MatIcon,
AsyncPipe,
MatFormField,
MatInput,
MatLabel,
MatSuffix,
ReactiveFormsModule,
FormsModule,
],
})
export class ProjectOverviewComponent implements OnInit {
searchControl = new FormControl('');
public readonly filteredProjects$ = this.searchControl.valueChanges.pipe(
startWith(''),
switchMap((query) => this.searchAndSortProjects(query!)),
);

searchAndSortProjects(query: string) {
return this.projectService.projects$.pipe(
map((projects) =>
projects?.filter((project) =>
project.name.toLocaleLowerCase().includes(query.toLocaleLowerCase()),
),
),
map((projects) => projects?.sort((a, b) => a.name.localeCompare(b.name))),
);
}

constructor(public projectService: ProjectWrapperService) {}

ngOnInit() {
Expand Down

0 comments on commit b02371a

Please sign in to comment.