diff options
author | Rigel Kent <sendmemail@rigelk.eu> | 2020-02-03 14:04:42 +0100 |
---|---|---|
committer | Rigel Kent <sendmemail@rigelk.eu> | 2020-02-13 16:32:58 +0100 |
commit | 52cc0d54850e0acf069d2f95d063826f16ff5238 (patch) | |
tree | fb7450bc09fc5aa34c480bd197407c4881b85299 /client/src/app/header/header.component.ts | |
parent | 6af662a5961b48ac12682df2b8b971060a2cc67d (diff) | |
download | PeerTube-52cc0d54850e0acf069d2f95d063826f16ff5238.tar.gz PeerTube-52cc0d54850e0acf069d2f95d063826f16ff5238.tar.zst PeerTube-52cc0d54850e0acf069d2f95d063826f16ff5238.zip |
Gracefully downsize search bar for mobile devices
Diffstat (limited to 'client/src/app/header/header.component.ts')
-rw-r--r-- | client/src/app/header/header.component.ts | 41 |
1 files changed, 0 insertions, 41 deletions
diff --git a/client/src/app/header/header.component.ts b/client/src/app/header/header.component.ts index ca4a32cbc..d9311c554 100644 --- a/client/src/app/header/header.component.ts +++ b/client/src/app/header/header.component.ts | |||
@@ -1,9 +1,4 @@ | |||
1 | import { filter, first, map, tap } from 'rxjs/operators' | ||
2 | import { Component, OnInit } from '@angular/core' | 1 | import { Component, OnInit } from '@angular/core' |
3 | import { ActivatedRoute, NavigationEnd, Params, Router } from '@angular/router' | ||
4 | import { getParameterByName } from '../shared/misc/utils' | ||
5 | import { AuthService } from '@app/core' | ||
6 | import { of } from 'rxjs' | ||
7 | import { I18n } from '@ngx-translate/i18n-polyfill' | 2 | import { I18n } from '@ngx-translate/i18n-polyfill' |
8 | 3 | ||
9 | @Component({ | 4 | @Component({ |
@@ -17,46 +12,10 @@ export class HeaderComponent implements OnInit { | |||
17 | ariaLabelTextForSearch = '' | 12 | ariaLabelTextForSearch = '' |
18 | 13 | ||
19 | constructor ( | 14 | constructor ( |
20 | private router: Router, | ||
21 | private route: ActivatedRoute, | ||
22 | private auth: AuthService, | ||
23 | private i18n: I18n | 15 | private i18n: I18n |
24 | ) {} | 16 | ) {} |
25 | 17 | ||
26 | ngOnInit () { | 18 | ngOnInit () { |
27 | this.ariaLabelTextForSearch = this.i18n('Search videos, channels') | 19 | this.ariaLabelTextForSearch = this.i18n('Search videos, channels') |
28 | |||
29 | this.router.events | ||
30 | .pipe( | ||
31 | filter(e => e instanceof NavigationEnd), | ||
32 | map(() => getParameterByName('search', window.location.href)) | ||
33 | ) | ||
34 | .subscribe(searchQuery => this.searchValue = searchQuery || '') | ||
35 | } | ||
36 | |||
37 | doSearch () { | ||
38 | const queryParams: Params = {} | ||
39 | |||
40 | if (window.location.pathname === '/search' && this.route.snapshot.queryParams) { | ||
41 | Object.assign(queryParams, this.route.snapshot.queryParams) | ||
42 | } | ||
43 | |||
44 | Object.assign(queryParams, { search: this.searchValue }) | ||
45 | |||
46 | const o = this.auth.isLoggedIn() | ||
47 | ? this.loadUserLanguagesIfNeeded(queryParams) | ||
48 | : of(true) | ||
49 | |||
50 | o.subscribe(() => this.router.navigate([ '/search' ], { queryParams })) | ||
51 | } | ||
52 | |||
53 | private loadUserLanguagesIfNeeded (queryParams: any) { | ||
54 | if (queryParams && queryParams.languageOneOf) return of(queryParams) | ||
55 | |||
56 | return this.auth.userInformationLoaded | ||
57 | .pipe( | ||
58 | first(), | ||
59 | tap(() => Object.assign(queryParams, { languageOneOf: this.auth.getUser().videoLanguages })) | ||
60 | ) | ||
61 | } | 20 | } |
62 | } | 21 | } |