Skip to content

Commit a269817

Browse files
committed
Added platform detection for placeholder classes.
1 parent fbcaaf5 commit a269817

5 files changed

Lines changed: 49 additions & 32 deletions

File tree

src/app/item-page/simple/related-items/related-items-component.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, ElementRef, Inject, Input } from '@angular/core';
1+
import { Component, ElementRef, Inject, Input, PLATFORM_ID } from '@angular/core';
22
import { Item } from '../../../core/shared/item.model';
33
import { Observable } from 'rxjs';
44
import { RemoteData } from '../../../core/data/remote-data';
@@ -7,8 +7,9 @@ import { ViewMode } from '../../../core/shared/view-mode.model';
77
import { RelationshipDataService } from '../../../core/data/relationship-data.service';
88
import { AbstractIncrementalListComponent } from '../abstract-incremental-list/abstract-incremental-list.component';
99
import { FindListOptions } from '../../../core/data/find-list-options.model';
10-
import { setPlaceHolderFontSize } from '../../../shared/utils/object-list-utils';
10+
import { setPlaceHolderAttributes } from '../../../shared/utils/object-list-utils';
1111
import { APP_CONFIG, AppConfig } from '../../../../config/app-config.interface';
12+
import { isPlatformBrowser } from '@angular/common';
1213

1314
@Component({
1415
selector: 'ds-related-items',
@@ -63,15 +64,20 @@ export class RelatedItemsComponent extends AbstractIncrementalListComponent<Obse
6364

6465
constructor(public relationshipService: RelationshipDataService,
6566
protected elementRef: ElementRef,
66-
@Inject(APP_CONFIG) protected appConfig: AppConfig
67+
@Inject(APP_CONFIG) protected appConfig: AppConfig,
68+
@Inject(PLATFORM_ID) private platformId: Object
6769
) {
6870
super();
6971
this.fetchThumbnail = this.appConfig.browseBy.showThumbnails;
7072
}
7173

7274
ngOnInit(): void {
73-
const width = this.elementRef.nativeElement.offsetWidth;
74-
this.placeholderFontClass = setPlaceHolderFontSize(width);
75+
if (isPlatformBrowser(this.platformId)) {
76+
const width = this.elementRef.nativeElement.offsetWidth;
77+
this.placeholderFontClass = setPlaceHolderAttributes(width);
78+
} else {
79+
this.placeholderFontClass = 'hide-placeholder-text';
80+
}
7581
super.ngOnInit();
7682
}
7783

src/app/shared/object-collection/object-collection.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<ds-object-list [ngClass]="placeholderFontClass" #objectList [config]="config"
1+
<ds-object-list [ngClass]="placeholderFontClass" [config]="config"
22
[sortConfig]="sortConfig"
33
[objects]="objects"
44
[hasBorder]="hasBorder"

src/app/shared/object-collection/object-collection.component.ts

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import {
22
ChangeDetectorRef,
33
Component, ElementRef,
4-
EventEmitter,
4+
EventEmitter, Inject,
55
Input,
66
OnInit,
7-
Output,
7+
Output, PLATFORM_ID,
88
} from '@angular/core';
99
import { ActivatedRoute, Router } from '@angular/router';
1010

@@ -21,7 +21,8 @@ import { ViewMode } from '../../core/shared/view-mode.model';
2121
import { CollectionElementLinkType } from './collection-element-link.type';
2222
import { PaginatedList } from '../../core/data/paginated-list.model';
2323
import { Context } from '../../core/shared/context.model';
24-
import { setPlaceHolderFontSize } from '../utils/object-list-utils';
24+
import { setPlaceHolderAttributes } from '../utils/object-list-utils';
25+
import { isPlatformBrowser } from '@angular/common';
2526

2627
/**
2728
* Component that can render a list of listable objects in different view modes
@@ -161,17 +162,7 @@ export class ObjectCollectionComponent implements OnInit {
161162
placeholderFontClass: string;
162163

163164

164-
ngOnInit(): void {
165-
this.currentMode$ = this.route
166-
.queryParams
167-
.pipe(
168-
map((params) => isEmpty(params?.view) ? ViewMode.ListElement : params.view),
169-
distinctUntilChanged()
170-
);
171-
const width = this.elementRef.nativeElement.offsetWidth;
172-
this.placeholderFontClass = setPlaceHolderFontSize(width);
173165

174-
}
175166

176167
/**
177168
* @param cdRef
@@ -187,7 +178,23 @@ export class ObjectCollectionComponent implements OnInit {
187178
private cdRef: ChangeDetectorRef,
188179
private route: ActivatedRoute,
189180
private router: Router,
190-
private elementRef: ElementRef) {
181+
private elementRef: ElementRef,
182+
@Inject(PLATFORM_ID) private platformId: Object) {
183+
}
184+
185+
ngOnInit(): void {
186+
this.currentMode$ = this.route
187+
.queryParams
188+
.pipe(
189+
map((params) => isEmpty(params?.view) ? ViewMode.ListElement : params.view),
190+
distinctUntilChanged()
191+
);
192+
if (isPlatformBrowser(this.platformId)) {
193+
const width = this.elementRef.nativeElement.offsetWidth;
194+
this.placeholderFontClass = setPlaceHolderAttributes(width);
195+
} else {
196+
this.placeholderFontClass = 'hide-placeholder-text';
197+
}
191198
}
192199

193200
/**

src/app/shared/utils/object-list-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Sets the class to be used for the "no thumbnail"
33
* placeholder font size in lists.
44
*/
5-
export function setPlaceHolderFontSize(width: number): string {
5+
export function setPlaceHolderAttributes(width: number): string {
66
if (width < 400) {
77
return 'thumb-font-0';
88
} else if (width < 750) {

src/styles/_global-styles.scss

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -142,43 +142,47 @@ ds-dynamic-form-control-container.d-none {
142142
.thumb-font-0 {
143143
.thumbnail-placeholder {
144144
@media screen and (max-width: map-get($grid-breakpoints, lg)) {
145-
font-size: 0.7rem !important;
145+
font-size: 0.7rem;
146146
padding: 0.2rem;
147147
}
148148
@media screen and (max-width: map-get($grid-breakpoints, sm)) {
149-
font-size: 0.6rem !important;
149+
font-size: 0.6rem;
150150
padding: 0.1rem;
151151
}
152-
font-size: 0.4rem !important;
152+
font-size: 0.4rem;
153153
padding: 0.1rem;
154154
}
155155
}
156+
157+
.hide-placeholder-text {
158+
.thumbnail-placeholder {
159+
color: transparent !important;
160+
}
161+
}
162+
156163
.thumb-font-1 {
157164
.thumbnail-placeholder {
158165
@media screen and (max-width: map-get($grid-breakpoints, sm)) {
159-
font-size: 0.9rem !important;
166+
font-size: 0.9rem;
160167
padding: 0.1rem;
161168
}
162169
@media screen and (max-width: 950px) {
163-
font-size: 0.4rem !important;
170+
font-size: 0.4rem;
164171
padding: 0.1rem;
165172
}
166-
font-size: 0.6rem !important;
173+
font-size: 0.6rem;
167174
padding: 0.125rem;
168-
visibility: inherit;
169175
}
170176
}
171177
.thumb-font-2 {
172178
.thumbnail-placeholder {
173-
font-size: 0.9rem !important;
179+
font-size: 0.9rem;
174180
padding: 0.125rem;
175-
visibility: inherit;
176181
}
177182
}
178183
.thumb-font-3 {
179184
.thumbnail-placeholder {
180-
font-size: 1.25rem !important;
185+
font-size: 1.25rem;
181186
padding: 0.5rem;
182-
visibility: inherit;
183187
}
184188
}

0 commit comments

Comments
 (0)