Skip to content

Commit 18c7f27

Browse files
committed
fix: picture gallery crop mode issue
1 parent 31e733f commit 18c7f27

File tree

4 files changed

+242
-191
lines changed

4 files changed

+242
-191
lines changed

src/app/gallery/area.component.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
.area {
77
position: absolute;
8-
border: 1px solid transparent;
8+
border: 2px dashed transparent;
99

1010
@include transition(
1111
0.6s ease-in-out width,

src/app/gallery/area.component.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {NgStyle} from '@angular/common';
2-
import {ChangeDetectionStrategy, Component, input} from '@angular/core';
2+
import {AfterViewInit, ChangeDetectionStrategy, Component, computed, HostListener, input, signal} from '@angular/core';
33
import {PictureItem} from '@grpc/spec.pb';
44
import {NgbTooltip} from '@ng-bootstrap/ng-bootstrap';
55

@@ -10,19 +10,29 @@ import {NgbTooltip} from '@ng-bootstrap/ng-bootstrap';
1010
styleUrls: ['./area.component.scss'],
1111
templateUrl: './area.component.html',
1212
})
13-
export class AreaComponent {
13+
export class AreaComponent implements AfterViewInit {
1414
readonly styles = input.required<Record<string, number> | undefined>({});
1515
readonly area = input.required<PictureItem>();
1616

17-
protected placement(): string {
18-
const winHeight = window.innerHeight;
17+
readonly #windowHeight = signal<number>(0);
18+
19+
protected readonly placement = computed<'bottom' | 'top'>(() => {
20+
const winHeight = this.#windowHeight();
1921
const styles = this.styles();
20-
const nodeOffset = styles?.['top.px'] ? styles['top.px'] : 0;
21-
const stylesValue = this.styles();
22-
const nodeHeight = stylesValue?.['height.px'] ? stylesValue['height.px'] : 0;
22+
const nodeOffset = styles?.['top.px'] || 0;
23+
const nodeHeight = styles?.['height.px'] || 0;
2324
const winCenter = winHeight == undefined ? 0 : winHeight / 2;
2425
const nodeCenter = nodeOffset == undefined || nodeHeight == undefined ? 0 : nodeOffset + nodeHeight / 2;
2526

2627
return winCenter > nodeCenter ? 'bottom' : 'top';
28+
});
29+
30+
ngAfterViewInit(): void {
31+
this.onResize();
32+
}
33+
34+
@HostListener('window:resize')
35+
protected onResize() {
36+
this.#windowHeight.set(window.innerHeight);
2737
}
2838
}

src/app/gallery/carousel-item.component.html

Lines changed: 45 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,64 @@
1-
@if (_item) {
2-
@if (_item.imageGalleryFull) {
3-
<img
4-
alt=""
5-
[src]="_item.imageGalleryFull.src"
6-
[class.crop-mode]="cropMode()"
7-
class="full"
8-
[ngStyle]="fullStyle"
9-
(load)="fullLoaded()"
10-
/>
1+
@if (item(); as item) {
2+
@if (item.imageGalleryFull) {
3+
@if (fullStyle(); as fullStyle) {
4+
<img
5+
alt=""
6+
[src]="item.imageGalleryFull.src"
7+
[class.crop-mode]="cropModeAvailable() && cropMode()"
8+
class="full"
9+
[ngStyle]="fullStyle"
10+
(load)="fullLoaded()"
11+
/>
12+
}
1113
}
12-
@if (_item.imageGallery) {
14+
@if (item.imageGallery) {
1315
<img
1416
alt=""
15-
[src]="_item.imageGallery.src"
16-
[class.crop-mode]="cropMode()"
17+
[src]="item.imageGallery.src"
18+
[class.crop-mode]="cropModeAvailable() && cropMode()"
1719
class="crop"
18-
[ngStyle]="cropStyle"
20+
[ngStyle]="cropStyle()"
1921
(load)="cropLoaded()"
2022
/>
2123
}
22-
@if (_item) {
23-
@for (area of areas; track area) {
24-
<app-gallery-carousel-item-area [area]="area.pictureItem" [styles]="area.styles" />
25-
}
26-
27-
<div class="carousel-caption">
28-
<h3 [innerHTML]="nameHtml"></h3>
29-
</div>
3024

31-
@if (_item.image) {
32-
<a class="download carousel-control" role="button" [href]="_item.image.src">
33-
<i class="bi bi-download" aria-hidden="true"></i>
34-
<div class="badge rounded-pill text-bg-info text-dark">{{ _item.image.filesize | bytes: 2 }}</div>
35-
</a>
36-
}
25+
@for (area of areas(); track area) {
26+
<app-gallery-carousel-item-area [area]="area.pictureItem" [styles]="area.styles" />
27+
}
3728

38-
<a class="comments carousel-control" role="button" [routerLink]="prefix().concat([_item.identity])">
39-
<i class="bi bi-chat-fill" aria-hidden="true"></i>
40-
@if (_item.commentsCountTotal) {
41-
<div class="badge rounded-pill text-bg-info text-dark">
42-
{{ _item.commentsCountTotal - _item.commentsCountNew }}
43-
@if (_item.commentsCountNew) {
44-
<span>+{{ _item.commentsCountNew }}</span>
45-
}
46-
</div>
47-
}
48-
</a>
29+
<div class="carousel-caption">
30+
<h3 [innerHTML]="nameHtml()"></h3>
31+
</div>
4932

50-
<a class="details carousel-control" role="button" [routerLink]="prefix().concat([_item.identity])">
51-
<i class="bi bi-card-image" aria-hidden="true"></i>
33+
@if (item.image) {
34+
<a class="download carousel-control" role="button" [href]="item.image.src">
35+
<i class="bi bi-download" aria-hidden="true"></i>
36+
<div class="badge rounded-pill text-bg-info text-dark">{{ item.image.filesize | bytes: 2 }}</div>
5237
</a>
5338
}
54-
@if (cropLoading() || fullLoading()) {
39+
40+
<a class="comments carousel-control" role="button" [routerLink]="prefix().concat([item.identity])">
41+
<i class="bi bi-chat-fill" aria-hidden="true"></i>
42+
@if (item.commentsCountTotal) {
43+
<div class="badge rounded-pill text-bg-info text-dark">
44+
{{ item.commentsCountTotal - item.commentsCountNew }}
45+
@if (item.commentsCountNew) {
46+
<span>+{{ item.commentsCountNew }}</span>
47+
}
48+
</div>
49+
}
50+
</a>
51+
52+
<a class="details carousel-control" role="button" [routerLink]="prefix().concat([item.identity])">
53+
<i class="bi bi-card-image" aria-hidden="true"></i>
54+
</a>
55+
56+
@if ((item.imageGallery && cropLoading()) || (item.imageGalleryFull && fullLoading())) {
5557
<div class="loading-icon">
5658
<div class="spinner-border" role="status"><span class="visually-hidden" i18n>Loading…</span></div>
5759
</div>
5860
}
59-
@if (_item && _item.imageGallery && !cropLoading() && !fullLoading()) {
61+
@if (item.imageGallery && !cropLoading() && !fullLoading()) {
6062
<span class="carousel-control-full" (click)="toggleCrop()" (keyup.enter)="toggleCrop()" tabindex="0"
6163
><i class="bi bi-arrows-fullscreen" aria-hidden="true"></i
6264
></span>

0 commit comments

Comments
 (0)