Skip to content

Commit 03bb816

Browse files
committed
feat: Migrate to gRPC pictures.UserSummary(), flop, normalize, deleteSimilar
1 parent 7428d1a commit 03bb816

File tree

6 files changed

+630
-32
lines changed

6 files changed

+630
-32
lines changed

src/app/account/account.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class AccountComponent {
3838
shareReplay(1),
3939
),
4040
this.messageService.getSummary$(),
41-
this.pictureService.getSummary$(),
41+
this.pictureService.summary$,
4242
]).pipe(
4343
map(([user, forumSummary, messageSummary, picturesSummary]) => {
4444
if (!user) {
@@ -76,14 +76,14 @@ export class AccountComponent {
7676
routerLink: ['/account/accounts'],
7777
},
7878
{
79-
count: picturesSummary ? picturesSummary.acceptedCount : undefined,
79+
count: picturesSummary?.acceptedCount,
8080
icon: 'bi-grid-3x2-gap-fill',
8181
name: $localize`My pictures`,
8282
pageId: 130,
8383
routerLink: ['/users', user.identity ? user.identity : 'user' + user.id, 'pictures'],
8484
},
8585
{
86-
count: picturesSummary ? picturesSummary.inboxCount : undefined,
86+
count: picturesSummary?.inboxCount,
8787
icon: 'bi-grid-3x2-gap-fill',
8888
name: $localize`Unmoderated`,
8989
pageId: 94,

src/app/moder/pictures/item/item.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ <h3 *ngIf="picture.rights.normalize || picture.rights.flop || picture.rights.cro
434434
<div>
435435
<button
436436
class="btn btn-warning"
437-
(click)="normalizePicture(picture.id)"
437+
(click)="normalizePicture('' + picture.id)"
438438
*ngIf="picture.rights.normalize"
439439
[disabled]="repairLoading"
440440
>
@@ -443,7 +443,7 @@ <h3 *ngIf="picture.rights.normalize || picture.rights.flop || picture.rights.cro
443443
</button>
444444
<button
445445
class="btn btn-warning"
446-
(click)="flopPicture(picture.id)"
446+
(click)="flopPicture('' + picture.id)"
447447
*ngIf="picture.rights.flop"
448448
[disabled]="repairLoading"
449449
>

src/app/moder/pictures/item/item.component.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {Component} from '@angular/core';
22
import {ActivatedRoute, Router} from '@angular/router';
3-
import {APIIP, APIUser, ItemFields, ItemRequest, ItemType} from '@grpc/spec.pb';
3+
import {APIIP, APIUser, DeleteSimilarRequest, ItemFields, ItemRequest, ItemType, PictureIDRequest} from '@grpc/spec.pb';
44
import {APIItem} from '@grpc/spec.pb';
5-
import {ItemsClient} from '@grpc/spec.pbsc';
5+
import {ItemsClient, PicturesClient} from '@grpc/spec.pbsc';
66
import {GrpcStatusEvent} from '@ngx-grpc/common';
77
import {APIService} from '@services/api.service';
88
import {IpService} from '@services/ip';
@@ -172,6 +172,7 @@ export class ModerPicturesItemComponent {
172172
private readonly ipService: IpService,
173173
private readonly itemsClient: ItemsClient,
174174
private readonly userService: UserService,
175+
private readonly picturesClient: PicturesClient,
175176
) {
176177
this.monthOptions = [
177178
{
@@ -323,9 +324,9 @@ export class ModerPicturesItemComponent {
323324
this.setPictureStatus(id, 'inbox');
324325
}
325326

326-
protected normalizePicture(id: number) {
327+
protected normalizePicture(id: string) {
327328
this.repairLoading = true;
328-
this.api.request<void>('PUT', 'picture/' + id + '/normalize', {}).subscribe({
329+
this.picturesClient.normalize(new PictureIDRequest({id})).subscribe({
329330
error: () => {
330331
this.repairLoading = false;
331332
},
@@ -336,9 +337,9 @@ export class ModerPicturesItemComponent {
336337
});
337338
}
338339

339-
protected flopPicture(id: number) {
340+
protected flopPicture(id: string) {
340341
this.repairLoading = true;
341-
this.api.request<void>('PUT', 'picture/' + id + '/flop', {}).subscribe({
342+
this.picturesClient.flop(new PictureIDRequest({id})).subscribe({
342343
error: () => {
343344
this.repairLoading = false;
344345
},
@@ -377,15 +378,17 @@ export class ModerPicturesItemComponent {
377378

378379
protected cancelSimilar(picture: APIPicture) {
379380
this.similarLoading = true;
380-
this.api.request<void>('DELETE', 'picture/' + picture.id + '/similar/' + picture.similar.picture_id).subscribe({
381-
error: () => {
382-
this.similarLoading = false;
383-
},
384-
next: () => {
385-
this.change$.next();
386-
this.similarLoading = false;
387-
},
388-
});
381+
this.picturesClient
382+
.deleteSimilar(new DeleteSimilarRequest({id: '' + picture.id, similarPictureId: '' + picture.similar.picture_id}))
383+
.subscribe({
384+
error: () => {
385+
this.similarLoading = false;
386+
},
387+
next: () => {
388+
this.change$.next();
389+
this.similarLoading = false;
390+
},
391+
});
389392
}
390393

391394
protected deletePictureItem(item: APIPictureItem) {

src/app/services/picture.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {Injectable} from '@angular/core';
2-
import {PicturesVoteRequest, PicturesVoteSummary} from '@grpc/spec.pb';
2+
import {PicturesUserSummary, PicturesVoteRequest, PicturesVoteSummary} from '@grpc/spec.pb';
33
import {PicturesClient} from '@grpc/spec.pbsc';
4+
import {Empty} from '@ngx-grpc/well-known-types';
45
import {Observable, of} from 'rxjs';
56
import {map, shareReplay, switchMap} from 'rxjs/operators';
67

@@ -200,11 +201,6 @@ export interface APIGetPicturesOptions {
200201
status?: string;
201202
}
202203

203-
export interface APIPictureUserSummary {
204-
acceptedCount: number;
205-
inboxCount: number;
206-
}
207-
208204
function convertPictureOptions(options: APIGetPictureOptions): {[param: string]: string} {
209205
const params: {[param: string]: string} = {};
210206

@@ -352,12 +348,12 @@ function converPicturesOptions(options: APIGetPicturesOptions): {[param: string]
352348

353349
@Injectable()
354350
export class PictureService {
355-
private readonly summary$: Observable<APIPictureUserSummary | null> = this.auth.getUser$().pipe(
351+
public readonly summary$: Observable<PicturesUserSummary | null> = this.auth.getUser$().pipe(
356352
switchMap((user) => {
357353
if (!user) {
358354
return of(null);
359355
}
360-
return this.api.request<APIPictureUserSummary>('GET', 'picture/user-summary');
356+
return this.pictures.getUserSummary(new Empty());
361357
}),
362358
shareReplay(1),
363359
);
@@ -407,10 +403,6 @@ export class PictureService {
407403
});
408404
}
409405

410-
public getSummary$(): Observable<APIPictureUserSummary | null> {
411-
return this.summary$;
412-
}
413-
414406
public getInboxSize$(): Observable<null | number> {
415407
return this.inboxSize$;
416408
}

0 commit comments

Comments
 (0)