Skip to content

Commit 0541fed

Browse files
committed
fix: upload page crop issue
1 parent 3e10952 commit 0541fed

File tree

3 files changed

+49
-42
lines changed

3 files changed

+49
-42
lines changed

src/app/thumbnail/thumbnail/thumbnail.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ interface ThumbnailAPIPicture extends Picture {
2020
}
2121

2222
@Component({
23-
changeDetection: ChangeDetectionStrategy.OnPush,
23+
changeDetection: ChangeDetectionStrategy.Default,
2424
imports: [RouterLink, UserComponent, FormsModule, AsyncPipe, DecimalPipe],
2525
selector: 'app-thumbnail',
2626
styleUrls: ['./thumbnail.component.scss'],

src/app/upload/crop/crop.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ interface JcropCrop {
2525
}
2626

2727
@Component({
28-
changeDetection: ChangeDetectionStrategy.OnPush,
28+
changeDetection: ChangeDetectionStrategy.Default,
2929
imports: [AsyncPipe],
3030
selector: 'app-upload-crop',
3131
templateUrl: './crop.component.html',

src/app/upload/index/index.component.ts

Lines changed: 47 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const cropTitle = (image: APIImage | undefined): string => {
6666
};
6767

6868
@Component({
69-
changeDetection: ChangeDetectionStrategy.OnPush,
69+
changeDetection: ChangeDetectionStrategy.Default,
7070
imports: [
7171
MarkdownComponent,
7272
FormsModule,
@@ -96,7 +96,7 @@ export class UploadIndexComponent implements OnInit {
9696
protected files: File[] | undefined;
9797
protected readonly note = new FormControl<string>('', {nonNullable: true});
9898
protected progress: UploadProgress[] = [];
99-
protected pictures: APIPictureUpload[] = [];
99+
protected readonly pictures: APIPictureUpload[] = [];
100100
protected readonly formHidden = signal(false);
101101
protected readonly authenticated$ = this.auth.authenticated$;
102102

@@ -255,6 +255,7 @@ export class UploadIndexComponent implements OnInit {
255255
progress.failed = true;
256256

257257
progress.invalidParams = response.error.invalid_params;
258+
this.#cdr.markForCheck();
258259
}
259260

260261
return EMPTY;
@@ -264,19 +265,24 @@ export class UploadIndexComponent implements OnInit {
264265
if (event.total) {
265266
progress.percentage = Math.round(50 + 25 * (event.loaded / event.total));
266267
}
268+
269+
this.#cdr.markForCheck();
267270
return EMPTY;
268271
}
269272

270273
if (event.type === HttpEventType.UploadProgress) {
271274
if (event.total) {
272275
progress.percentage = Math.round(50 * (event.loaded / event.total));
273276
}
277+
278+
this.#cdr.markForCheck();
274279
return EMPTY;
275280
}
276281

277282
if (event.type === HttpEventType.Response) {
278283
progress.percentage = 75;
279284
progress.success = true;
285+
this.#cdr.markForCheck();
280286

281287
if (!event.body) {
282288
return throwError(() => 'no response body');
@@ -342,46 +348,47 @@ export class UploadIndexComponent implements OnInit {
342348
const componentRef: ComponentRef<UploadCropComponent> = modalRef['_contentRef'].componentRef;
343349
componentRef.setInput('picture', picture.picture);
344350

345-
modalRef.componentInstance.changed
346-
.pipe(
347-
switchMap(() =>
348-
this.#picturesClient.setPictureCrop(
349-
new SetPictureCropRequest({
350-
cropHeight: picture.picture.image?.cropHeight ? Math.round(picture.picture.image.cropHeight) : undefined,
351-
cropLeft: picture.picture.image?.cropLeft ? Math.round(picture.picture.image.cropLeft) : undefined,
352-
cropTop: picture.picture.image?.cropTop ? Math.round(picture.picture.image.cropTop) : undefined,
353-
cropWidth: picture.picture.image?.cropWidth ? Math.round(picture.picture.image.cropWidth) : undefined,
354-
pictureId: picture.picture.id,
355-
}),
356-
),
357-
),
358-
catchError((response: unknown) => {
359-
this.#toastService.handleError(response);
360-
return EMPTY;
361-
}),
362-
switchMap(() =>
363-
this.#picturesClient.getPicture(
364-
new PicturesRequest({
365-
fields: new PictureFields({
366-
image: true,
367-
thumbMedium: true,
351+
componentRef.instance.changed.subscribe(() => {
352+
this.#picturesClient
353+
.setPictureCrop(
354+
new SetPictureCropRequest({
355+
cropHeight: picture.picture.image?.cropHeight ? Math.round(picture.picture.image.cropHeight) : undefined,
356+
cropLeft: picture.picture.image?.cropLeft ? Math.round(picture.picture.image.cropLeft) : undefined,
357+
cropTop: picture.picture.image?.cropTop ? Math.round(picture.picture.image.cropTop) : undefined,
358+
cropWidth: picture.picture.image?.cropWidth ? Math.round(picture.picture.image.cropWidth) : undefined,
359+
pictureId: picture.picture.id,
360+
}),
361+
)
362+
.pipe(
363+
catchError((response: unknown) => {
364+
this.#toastService.handleError(response);
365+
return EMPTY;
366+
}),
367+
switchMap(() =>
368+
this.#picturesClient.getPicture(
369+
new PicturesRequest({
370+
fields: new PictureFields({
371+
image: true,
372+
thumbMedium: true,
373+
}),
374+
language: this.#languageService.language,
375+
options: new PictureListOptions({id: picture.picture.id}),
368376
}),
369-
language: this.#languageService.language,
370-
options: new PictureListOptions({id: picture.picture.id}),
371-
}),
377+
),
372378
),
373-
),
374-
catchError((response: unknown) => {
375-
this.#toastService.handleError(response);
376-
return EMPTY;
377-
}),
378-
tap((response: Picture) => {
379-
picture.picture.image = response.image;
380-
picture.cropTitle = cropTitle(response.image);
381-
picture.picture.thumbMedium = response.thumbMedium;
382-
}),
383-
)
384-
.subscribe();
379+
catchError((response: unknown) => {
380+
this.#toastService.handleError(response);
381+
return EMPTY;
382+
}),
383+
tap((response: Picture) => {
384+
picture.picture.image = response.image;
385+
picture.cropTitle = cropTitle(response.image);
386+
picture.picture.thumbMedium = response.thumbMedium;
387+
this.#cdr.markForCheck();
388+
}),
389+
)
390+
.subscribe();
391+
});
385392

386393
return false;
387394
}

0 commit comments

Comments
 (0)