diff options
author | Rigel Kent <sendmemail@rigelk.eu> | 2020-02-03 15:19:43 +0100 |
---|---|---|
committer | Rigel Kent <sendmemail@rigelk.eu> | 2020-02-13 16:32:58 +0100 |
commit | 9677fca772349248925da6c5f34f600e9a2abbe6 (patch) | |
tree | 635c9aba8c4966eb9fd77355a47bcb83dff9df71 /client/src/app/header/search-typeahead.component.ts | |
parent | 52cc0d54850e0acf069d2f95d063826f16ff5238 (diff) | |
download | PeerTube-9677fca772349248925da6c5f34f600e9a2abbe6.tar.gz PeerTube-9677fca772349248925da6c5f34f600e9a2abbe6.tar.zst PeerTube-9677fca772349248925da6c5f34f600e9a2abbe6.zip |
Make the search helper change based on the server config
Diffstat (limited to 'client/src/app/header/search-typeahead.component.ts')
-rw-r--r-- | client/src/app/header/search-typeahead.component.ts | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/client/src/app/header/search-typeahead.component.ts b/client/src/app/header/search-typeahead.component.ts index 514c04704..9b414bc56 100644 --- a/client/src/app/header/search-typeahead.component.ts +++ b/client/src/app/header/search-typeahead.component.ts | |||
@@ -8,14 +8,15 @@ import { | |||
8 | QueryList | 8 | QueryList |
9 | } from '@angular/core' | 9 | } from '@angular/core' |
10 | import { Router, NavigationEnd, Params, ActivatedRoute } from '@angular/router' | 10 | import { Router, NavigationEnd, Params, ActivatedRoute } from '@angular/router' |
11 | import { AuthService } from '@app/core' | 11 | import { AuthService, ServerService } from '@app/core' |
12 | import { I18n } from '@ngx-translate/i18n-polyfill' | 12 | import { I18n } from '@ngx-translate/i18n-polyfill' |
13 | import { filter, first, tap, map } from 'rxjs/operators' | 13 | import { filter, first, tap, map } from 'rxjs/operators' |
14 | import { ListKeyManager } from '@angular/cdk/a11y' | 14 | import { ListKeyManager } from '@angular/cdk/a11y' |
15 | import { UP_ARROW, DOWN_ARROW, ENTER, TAB } from '@angular/cdk/keycodes' | 15 | import { UP_ARROW, DOWN_ARROW, ENTER } from '@angular/cdk/keycodes' |
16 | import { SuggestionComponent, Result } from './suggestion.component' | 16 | import { SuggestionComponent, Result } from './suggestion.component' |
17 | import { of } from 'rxjs' | 17 | import { of } from 'rxjs' |
18 | import { getParameterByName } from '@app/shared/misc/utils' | 18 | import { getParameterByName } from '@app/shared/misc/utils' |
19 | import { ServerConfig } from '@shared/models' | ||
19 | 20 | ||
20 | @Component({ | 21 | @Component({ |
21 | selector: 'my-search-typeahead', | 22 | selector: 'my-search-typeahead', |
@@ -30,7 +31,7 @@ export class SearchTypeaheadComponent implements OnInit, OnDestroy, AfterViewIni | |||
30 | newSearch = true | 31 | newSearch = true |
31 | 32 | ||
32 | searchInput: HTMLInputElement | 33 | searchInput: HTMLInputElement |
33 | URIPolicy: 'only-followed' | 'any' = 'any' | 34 | serverConfig: ServerConfig |
34 | 35 | ||
35 | URIPolicyText: string | 36 | URIPolicyText: string |
36 | inAllText: string | 37 | inAllText: string |
@@ -44,6 +45,7 @@ export class SearchTypeaheadComponent implements OnInit, OnDestroy, AfterViewIni | |||
44 | private authService: AuthService, | 45 | private authService: AuthService, |
45 | private router: Router, | 46 | private router: Router, |
46 | private route: ActivatedRoute, | 47 | private route: ActivatedRoute, |
48 | private serverService: ServerService, | ||
47 | private i18n: I18n | 49 | private i18n: I18n |
48 | ) { | 50 | ) { |
49 | this.URIPolicyText = this.i18n('Determines whether you can resolve any distant content, or if your instance only allows doing so for instances it follows.') | 51 | this.URIPolicyText = this.i18n('Determines whether you can resolve any distant content, or if your instance only allows doing so for instances it follows.') |
@@ -66,6 +68,9 @@ export class SearchTypeaheadComponent implements OnInit, OnDestroy, AfterViewIni | |||
66 | map(() => getParameterByName('search', window.location.href)) | 68 | map(() => getParameterByName('search', window.location.href)) |
67 | ) | 69 | ) |
68 | .subscribe(searchQuery => this.searchInput.value = searchQuery || '') | 70 | .subscribe(searchQuery => this.searchInput.value = searchQuery || '') |
71 | |||
72 | this.serverService.getConfig() | ||
73 | .subscribe(config => this.serverConfig = config) | ||
69 | } | 74 | } |
70 | 75 | ||
71 | ngOnDestroy () { | 76 | ngOnDestroy () { |
@@ -90,6 +95,16 @@ export class SearchTypeaheadComponent implements OnInit, OnDestroy, AfterViewIni | |||
90 | return this.hasSearch && this.newSearch && this.activeResult && this.activeResult.type === 'search-global' || false | 95 | return this.hasSearch && this.newSearch && this.activeResult && this.activeResult.type === 'search-global' || false |
91 | } | 96 | } |
92 | 97 | ||
98 | get URIPolicy (): 'only-followed' | 'any' { | ||
99 | return ( | ||
100 | this.authService.isLoggedIn() | ||
101 | ? this.serverConfig.search.remoteUri.users | ||
102 | : this.serverConfig.search.remoteUri.anonymous | ||
103 | ) | ||
104 | ? 'any' | ||
105 | : 'only-followed' | ||
106 | } | ||
107 | |||
93 | computeResults () { | 108 | computeResults () { |
94 | this.newSearch = true | 109 | this.newSearch = true |
95 | let results: Result[] = [] | 110 | let results: Result[] = [] |
@@ -151,10 +166,6 @@ export class SearchTypeaheadComponent implements OnInit, OnDestroy, AfterViewIni | |||
151 | ) | 166 | ) |
152 | } | 167 | } |
153 | 168 | ||
154 | isUserLoggedIn () { | ||
155 | return this.authService.isLoggedIn() | ||
156 | } | ||
157 | |||
158 | handleKeyUp (event: KeyboardEvent, indexSelected?: number) { | 169 | handleKeyUp (event: KeyboardEvent, indexSelected?: number) { |
159 | event.stopImmediatePropagation() | 170 | event.stopImmediatePropagation() |
160 | if (this.keyboardEventsManager) { | 171 | if (this.keyboardEventsManager) { |