|
1 | | -import { getRemoteDataPayload } from './../../../core/shared/operators'; |
2 | | -import { SEARCH_CONFIG_SERVICE } from './../../../my-dspace-page/my-dspace-page.component'; |
3 | | -import { SearchConfigurationService } from './../../../core/shared/search/search-configuration.service'; |
4 | | -import { SearchService } from './../../../core/shared/search/search.service'; |
5 | | -import { Component, Inject, Input, OnInit } from '@angular/core'; |
| 1 | +import { isPlatformBrowser } from '@angular/common'; |
| 2 | +import { ChangeDetectorRef, Component, Inject, Input, OnInit, PLATFORM_ID } from '@angular/core'; |
6 | 3 |
|
7 | 4 | import { BehaviorSubject, Observable, of } from 'rxjs'; |
8 | | -import { filter, map, switchMap, take, tap, mergeMap } from 'rxjs/operators'; |
| 5 | +import { filter, map, mergeMap, switchMap, take, tap } from 'rxjs/operators'; |
| 6 | + |
9 | 7 | import { RemoteData } from '../../../core/data/remote-data'; |
10 | 8 | import { SearchFilterConfig } from '../models/search-filter-config.model'; |
11 | 9 | import { shrinkInOut } from '../../animations/shrink'; |
12 | 10 | import { hasValue, isNotEmpty } from '../../empty.util'; |
| 11 | +import { getRemoteDataPayload } from '../../../core/shared/operators'; |
| 12 | +import { SEARCH_CONFIG_SERVICE } from '../../../my-dspace-page/my-dspace-page.component'; |
| 13 | +import { SearchConfigurationService } from '../../../core/shared/search/search-configuration.service'; |
| 14 | +import { SearchService } from '../../../core/shared/search/search.service'; |
13 | 15 |
|
14 | 16 | @Component({ |
15 | 17 | selector: 'ds-search-charts', |
@@ -57,25 +59,37 @@ export class SearchChartsComponent implements OnInit { |
57 | 59 | */ |
58 | 60 | selectedFilter: SearchFilterConfig; |
59 | 61 |
|
| 62 | + /** |
| 63 | + * Whether a platform id represents a browser platform. |
| 64 | + */ |
| 65 | + isPlatformBrowser: boolean; |
60 | 66 |
|
61 | | - constructor(private searchService: SearchService, |
| 67 | + constructor( |
| 68 | + private cdr: ChangeDetectorRef, |
| 69 | + private searchService: SearchService, |
| 70 | + @Inject(PLATFORM_ID) protected platformId: Object, |
62 | 71 | @Inject(SEARCH_CONFIG_SERVICE) private searchConfigService: SearchConfigurationService) { |
63 | 72 | } |
64 | 73 |
|
65 | 74 | ngOnInit(): void { |
66 | | - this.filters.pipe( |
67 | | - filter((rd: RemoteData<SearchFilterConfig[]>) => isNotEmpty(rd)), |
68 | | - take(1), |
69 | | - mergeMap((rd: RemoteData<SearchFilterConfig[]>) => { |
70 | | - return this.hasFacetValues(rd.payload[0]).pipe( |
71 | | - tap((hasValues) => { |
72 | | - this.selectedFilter = this.selectedFilter |
73 | | - ? this.selectedFilter |
74 | | - : rd.hasSucceeded && hasValues ? rd.payload[0] : null; |
75 | | - }) |
76 | | - ); |
77 | | - }), |
78 | | - ).subscribe(); |
| 75 | + this.isPlatformBrowser = isPlatformBrowser(this.platformId); |
| 76 | + |
| 77 | + if (isPlatformBrowser(this.platformId)) { |
| 78 | + this.filters.pipe( |
| 79 | + filter((rd: RemoteData<SearchFilterConfig[]>) => isNotEmpty(rd)), |
| 80 | + take(1), |
| 81 | + mergeMap((rd: RemoteData<SearchFilterConfig[]>) => { |
| 82 | + return this.hasFacetValues(rd.payload[0]).pipe( |
| 83 | + tap((hasValues) => { |
| 84 | + this.selectedFilter = this.selectedFilter |
| 85 | + ? this.selectedFilter |
| 86 | + : rd.hasSucceeded && hasValues ? rd.payload[0] : null; |
| 87 | + this.cdr.detectChanges(); |
| 88 | + }) |
| 89 | + ); |
| 90 | + }), |
| 91 | + ).subscribe(); |
| 92 | + } |
79 | 93 | } |
80 | 94 |
|
81 | 95 | /** |
|
0 commit comments