Skip to content

Commit

Permalink
Fixed clear search issue fossasia#1230
Browse files Browse the repository at this point in the history
Fixed double quotes to single quotes

Fixed reference for navbar html

Fixed spacing issues in constructor scope

Fixed clear search issue fossasia#1230
  • Loading branch information
reeversedev committed Dec 24, 2018
1 parent c4cf69e commit 6fe943f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 30 deletions.
31 changes: 14 additions & 17 deletions src/app/navbar/navbar.component.html
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
<nav class="top-nav navbar navbar-static-top navbar-default" [style.background-color]="themeService.navbarbgColor">
<div class="container-fluid">
<div class="navbar-header" id="navcontainer">
<a routerLink="/">
<img class="navbar-brand" src="assets/images/susper.svg" alt="brand">
</a>

<div id="navbar-search">
<div id="search-bar">
<app-search-bar></app-search-bar>
</div>
</div>

<div id="navbar-dropdown-box">
<app-dropdown></app-dropdown>
</div>
</div>
<nav
class="top-nav navbar navbar-static-top navbar-default"
[style.background-color]="themeService.navbarbgColor"
>
<div class="container-fluid">
<div class="navbar-header" id="navcontainer">
<a routerLink="/" (click)="clearSearch()">
<img class="navbar-brand" src="assets/images/susper.svg" alt="brand" />
</a>
<div id="navbar-search">
<div id="search-bar"><app-search-bar></app-search-bar></div>
</div>
<div id="navbar-dropdown-box"><app-dropdown></app-dropdown></div>
</div>
</div>
</nav>
15 changes: 9 additions & 6 deletions src/app/navbar/navbar.component.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { Component, OnInit } from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router';
import { Component, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { ThemeService } from '../services/theme.service';
import { SearchBarComponent } from 'app/search-bar/search-bar.component';

@Component({
selector: 'app-navbar',
templateUrl: './navbar.component.html',
styleUrls: ['./navbar.component.css']
})
export class NavbarComponent implements OnInit {

@ViewChild(SearchBarComponent) searchComponent: SearchBarComponent;
searchdata = {
query: '',
verify: false,
Expand All @@ -26,14 +27,16 @@ export class NavbarComponent implements OnInit {
private route: ActivatedRoute,
private router: Router,
public themeService: ThemeService
) { }
) {}

ngOnInit() {
this.searchdata.timezoneOffset = new Date().getTimezoneOffset();
}

clearSearch() {
this.searchComponent.clearSearch();
}
submit() {
this.router.navigate(['/search'], {queryParams: this.searchdata});
this.router.navigate(['/search'], { queryParams: this.searchdata });
}

}
21 changes: 14 additions & 7 deletions src/app/search-bar/search-bar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
ViewChild,
ViewChildren,
ElementRef,
HostListener,
HostListener
} from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { Store } from '@ngrx/store';
Expand All @@ -25,7 +25,7 @@ import { ThemeService } from '../services/theme.service';
@Component({
selector: 'app-search-bar',
templateUrl: './search-bar.component.html',
styleUrls: ['./search-bar.component.css'],
styleUrls: ['./search-bar.component.css']
})
export class SearchBarComponent implements OnInit, AfterViewInit {
@ViewChildren('input')
Expand All @@ -38,7 +38,7 @@ export class SearchBarComponent implements OnInit, AfterViewInit {
rows: 10,
start: 0,
fq: '',
mode: 'text',
mode: 'text'
};

showspeech: boolean = false;
Expand Down Expand Up @@ -84,7 +84,7 @@ export class SearchBarComponent implements OnInit, AfterViewInit {
start: 0,
rows: this.searchdata.rows,
fq: this.searchdata.fq,
mode: this.searchdata.mode,
mode: this.searchdata.mode
})
);
} else {
Expand All @@ -93,7 +93,7 @@ export class SearchBarComponent implements OnInit, AfterViewInit {
query: event.target.value,
start: 0,
rows: this.searchdata.rows,
mode: this.searchdata.mode,
mode: this.searchdata.mode
})
);
}
Expand All @@ -120,7 +120,7 @@ export class SearchBarComponent implements OnInit, AfterViewInit {
start: 0,
rows: this.searchdata.rows,
fq: this.searchdata.fq,
mode: this.searchdata.mode,
mode: this.searchdata.mode
})
);
} else {
Expand All @@ -129,7 +129,7 @@ export class SearchBarComponent implements OnInit, AfterViewInit {
query: this.searchdata.query,
start: 0,
rows: this.searchdata.rows,
mode: this.searchdata.mode,
mode: this.searchdata.mode
})
);
}
Expand All @@ -149,6 +149,13 @@ export class SearchBarComponent implements OnInit, AfterViewInit {
ngAfterViewInit() {
this.vc.first.nativeElement.focus();
}
clearSearch() {
this.store.dispatch(
new queryactions.QueryServerAction({
query: ''
})
);
}

submit() {
if (this.searchdata.query.toString().length !== 0) {
Expand Down

0 comments on commit 6fe943f

Please sign in to comment.