Fixed the search bar

pull/3539/head
Jamie Rees 5 years ago
parent 4cd4a1ef50
commit 3ca0aebfd6

@ -18,7 +18,8 @@ import {
} from "primeng/primeng";
import {
MatButtonModule, MatNativeDateModule, MatIconModule, MatSidenavModule, MatListModule, MatToolbarModule, MatAutocompleteModule, MatCheckboxModule, MatSnackBarModule
MatButtonModule, MatNativeDateModule, MatIconModule, MatSidenavModule, MatListModule, MatToolbarModule, MatAutocompleteModule, MatCheckboxModule, MatSnackBarModule,
MatProgressSpinnerModule
} from '@angular/material';
import { MatCardModule, MatInputModule, MatTabsModule, MatSlideToggleModule } from "@angular/material";
@ -129,6 +130,7 @@ export function JwtTokenGetter() {
CardsFreeModule,
OverlayModule,
MatCheckboxModule,
MatProgressSpinnerModule,
MDBBootstrapModule.forRoot(),
JwtModule.forRoot({
config: {

@ -1,7 +1,5 @@
<mat-sidenav-container *ngIf="showNav" class="sidenav-container">
<mat-sidenav #drawer class="sidenav" fixedInViewport="true"
[attr.role]="(isHandset$ | async) ? 'dialog' : 'navigation'" [mode]="(isHandset$ | async) ? 'over' : 'side'"
[opened]="!(isHandset$ | async)">
<mat-sidenav #drawer class="sidenav" fixedInViewport="true" [attr.role]="(isHandset$ | async) ? 'dialog' : 'navigation'" [mode]="(isHandset$ | async) ? 'over' : 'side'" [opened]="!(isHandset$ | async)">
<mat-toolbar>{{applicationName}}</mat-toolbar>
<mat-nav-list>
<span *ngFor="let nav of navItems">
@ -11,9 +9,7 @@
&nbsp;{{nav.name | translate}}
</a> </span>
<a class="bottom-nav-link" mat-list-item
[routerLinkActive]="theme === 'dark' ? 'active-list-item-dark' : 'active-list-item'" aria-label="Toggle sidenav"
(click)="logOut();">
<a class="bottom-nav-link" mat-list-item [routerLinkActive]="theme === 'dark' ? 'active-list-item-dark' : 'active-list-item'" aria-label="Toggle sidenav" (click)="logOut();">
<mat-icon aria-label="Side nav toggle icon">exit_to_app</mat-icon>
{{ 'NavigationBar.Logout' | translate }}
</a>
@ -23,15 +19,16 @@
</mat-sidenav>
<mat-sidenav-content>
<mat-toolbar color="primary">
<button type="button" aria-label="Toggle sidenav" mat-icon-button (click)="drawer.toggle()"
*ngIf="isHandset$ | async">
<button type="button" aria-label="Toggle sidenav" mat-icon-button (click)="drawer.toggle()" *ngIf="isHandset$ | async">
<mat-icon aria-label="Side nav toggle icon">menu</mat-icon>
</button>
<div class="col-md-10 offset-md-1 col-10">
<span class="middle justify-content-center align-items-center">
<!-- Search Bar -->
<div style="width: 50%;">
<app-nav-search></app-nav-search>
</div>
</span>

@ -1,13 +1,24 @@
<input class="form-control quater-width search-bar" type="text" [(ngModel)]="selectedItem"
placeholder="{{'NavigationBar.Search' | translate}}" aria-label="Search" [ngbTypeahead]="searchModel"
[resultFormatter]="formatter" [inputFormatter]="formatter" [resultTemplate]="template" (selectItem)="selected($event)">
<!-- <input class="form-control quater-width search-bar" type="text" [(ngModel)]="selectedItem" placeholder="{{'NavigationBar.Search' | translate}}"
aria-label="Search" [ngbTypeahead]="searchModel" [resultFormatter]="formatter" [inputFormatter]="formatter" [resultTemplate]="template" (selectItem)="selected($event)">
<ng-template #template let-result="result">
</ng-template> -->
<ng-template #template let-result="result">
<form [formGroup]='searchForm'>
<mat-form-field floatLabel="never" style="width: 100%;">
<input matInput placeholder="{{'NavigationBar.Search' | translate}}" [matAutocomplete]="auto" formControlName='input'>
</mat-form-field>
<mat-autocomplete #auto="matAutocomplete" (optionSelected)="selected($event)" [displayWith]="displayFn">
<mat-option *ngIf="searching" color="accent">
<mat-spinner diameter="50"></mat-spinner>
</mat-option>
<ng-container *ngIf="!searching">
<mat-option *ngFor="let result of results" [value]="result">
<div *ngIf="result.mediaType === 'movie'">
<i class="fa fa-film"></i> &nbsp;
<span >{{result.title}}</span>
<span>{{result.title}}</span>
</div>
<div *ngIf="result.mediaType === 'tv'">
<i class="fa fa-tv"></i> &nbsp;
@ -23,8 +34,9 @@
<div *ngIf="result.mediaType === 'person'">
<i class="fa fa-user"></i> &nbsp;
<span >{{result.title}}</span>
</div>
<!-- Collection -->
<!-- <i class="fa fa-file-video-o" aria-hidden="true"></i> -->
</ng-template>
<span>{{result.title}}</span>
</div>
</mat-option>
</ng-container>
</mat-autocomplete>
</form>

@ -1,7 +1,6 @@
$ombi-primary:#3f3f3f;
$ombi-primary-darker:#2b2b2b;
$ombi-accent: #258a6d;
@media (max-width: 767px) {
.quater-width {
width: 15em !important;
@ -23,22 +22,6 @@ $ombi-accent: #258a6d;
padding: 0px 5px;
}
::ng-deep ngb-typeahead-window.dropdown-menu {
background-color: $ombi-primary;
overflow: auto;
height: 33em;
}
::ng-deep ngb-typeahead-window button.dropdown-item {
color: white;
}
::ng-deep ngb-typeahead-window .dropdown-item.active,
.dropdown-item:active {
text-decoration: none;
background-color: $ombi-accent;
}
.search-bar {
background-color: $ombi-primary-darker;
border: solid 1px $ombi-primary-darker;

@ -1,56 +1,78 @@
import { Component } from '@angular/core';
import { Observable } from 'rxjs';
import { debounceTime, distinctUntilChanged, switchMap } from 'rxjs/operators';
import { Component, OnInit } from "@angular/core";
import { Observable } from "rxjs";
import {
debounceTime,
distinctUntilChanged,
switchMap,
tap,
finalize,
} from "rxjs/operators";
import { SearchV2Service } from '../services/searchV2.service';
import { IMultiSearchResult } from '../interfaces';
import { Router } from '@angular/router';
import { NgbTypeaheadSelectItemEvent } from '@ng-bootstrap/ng-bootstrap';
import { empty, of } from "rxjs";
import { SearchV2Service } from "../services/searchV2.service";
import { IMultiSearchResult } from "../interfaces";
import { Router } from "@angular/router";
import { NgbTypeaheadSelectItemEvent } from "@ng-bootstrap/ng-bootstrap";
import { FormGroup, FormBuilder } from "@angular/forms";
import { MatAutocompleteSelectedEvent } from "@angular/material";
@Component({
selector: 'app-nav-search',
templateUrl: './nav-search.component.html',
styleUrls: ['./nav-search.component.scss']
selector: "app-nav-search",
templateUrl: "./nav-search.component.html",
styleUrls: ["./nav-search.component.scss"],
})
export class NavSearchComponent {
export class NavSearchComponent implements OnInit {
public selectedItem: string;
public results: IMultiSearchResult[];
public searching = false;
public searchFailed = false;
public formatter = (result: IMultiSearchResult) => {
return result.title;
}
public searchForm: FormGroup;
public searchModel = (text$: Observable<string>) =>
text$.pipe(
debounceTime(600),
distinctUntilChanged(),
switchMap(term => term.length < 2 ? []
: this.searchService.multiSearch(term)
)
)
constructor(
private searchService: SearchV2Service,
private router: Router,
private fb: FormBuilder
) {}
constructor(private searchService: SearchV2Service, private router: Router) {
public async ngOnInit() {
this.searchForm = this.fb.group({
input: null,
});
this.searchForm
.get("input")
.valueChanges.pipe(
debounceTime(600),
tap(() => (this.searching = true)),
switchMap((value: string) => {
if (value) {
return this.searchService
.multiSearch(value)
.pipe(finalize(() => (this.searching = false)));
}
return empty().pipe(finalize(() => (this.searching = false)));
})
)
.subscribe((r) => (this.results = r));
}
public selected(event: NgbTypeaheadSelectItemEvent) {
if (event.item.mediaType == "movie") {
this.router.navigate([`details/movie/${event.item.id}`]);
public selected(event: MatAutocompleteSelectedEvent) {
const val = event.option.value as IMultiSearchResult;
if (val.mediaType == "movie") {
this.router.navigate([`details/movie/${val.id}`]);
return;
} else if (event.item.mediaType == "tv") {
this.router.navigate([`details/tv/${event.item.id}/true`]);
} else if (val.mediaType == "tv") {
this.router.navigate([`details/tv/${val.id}/true`]);
return;
} else if (event.item.mediaType == "person") {
this.router.navigate([`discover/actor/${event.item.id}`]);
} else if (val.mediaType == "person") {
this.router.navigate([`discover/actor/${val.id}`]);
return;
} else if (event.item.mediaType == "Artist") {
this.router.navigate([`details/artist/${event.item.id}`]);
} else if (val.mediaType == "Artist") {
this.router.navigate([`details/artist/${val.id}`]);
return;
}
}
displayFn(result: IMultiSearchResult) {
if (result) { return result.title; }
}
}

Loading…
Cancel
Save