Skip to content

Commit

Permalink
feat: categories path via gRPC API
Browse files Browse the repository at this point in the history
  • Loading branch information
autowp committed Feb 16, 2025
1 parent 2308533 commit 97719c5
Show file tree
Hide file tree
Showing 83 changed files with 1,486 additions and 977 deletions.
4 changes: 2 additions & 2 deletions src/app/account/access/access.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import {PageEnvService} from '@services/page-env.service';
templateUrl: './access.component.html',
})
export class AccountAccessComponent implements OnInit {
private readonly pageEnv = inject(PageEnvService);
readonly #pageEnv = inject(PageEnvService);

protected readonly changePasswordUrl =
environment.keycloak.url + '/realms/' + environment.keycloak.realm + '/account/#/security/device-activity';

ngOnInit(): void {
setTimeout(() => this.pageEnv.set({pageId: 133}), 0);
setTimeout(() => this.#pageEnv.set({pageId: 133}), 0);
}
}
26 changes: 13 additions & 13 deletions src/app/account/account.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,26 @@ interface SidebarItem {
templateUrl: './account.component.html',
})
export class AccountComponent {
private readonly messageService = inject(MessageService);
private readonly auth = inject(AuthService);
private readonly pictureService = inject(PictureService);
private readonly pageEnv = inject(PageEnvService);
private readonly toastService = inject(ToastsService);
private readonly forumsClient = inject(ForumsClient);
readonly #messageService = inject(MessageService);
readonly #auth = inject(AuthService);
readonly #pictureService = inject(PictureService);
readonly #pageEnv = inject(PageEnvService);
readonly #toastService = inject(ToastsService);
readonly #forumsClient = inject(ForumsClient);

protected readonly items$: Observable<SidebarItem[]> = combineLatest([
this.auth.getUser$(),
this.auth.getUser$().pipe(
this.#auth.getUser$(),
this.#auth.getUser$().pipe(
switchMap((user) => {
if (!user) {
return of(null);
}
return this.forumsClient.getUserSummary(new Empty());
return this.#forumsClient.getUserSummary(new Empty());
}),
shareReplay({bufferSize: 1, refCount: false}),
),
this.messageService.getSummary$(),
this.pictureService.summary$,
this.#messageService.getSummary$(),
this.#pictureService.summary$,
]).pipe(
map(([user, forumSummary, messageSummary, picturesSummary]) => {
if (!user) {
Expand Down Expand Up @@ -147,8 +147,8 @@ export class AccountComponent {

for (const item of items) {
if (item.pageId) {
this.pageEnv.isActive$(item.pageId).subscribe({
error: (response: unknown) => this.toastService.handleError(response),
this.#pageEnv.isActive$(item.pageId).subscribe({
error: (response: unknown) => this.#toastService.handleError(response),
next: (active) => {
item.active = active;
},
Expand Down
24 changes: 12 additions & 12 deletions src/app/account/accounts/accounts.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ import {ToastsService} from '../../toasts/toasts.service';
templateUrl: './accounts.component.html',
})
export class AccountAccountsComponent implements OnInit {
private readonly pageEnv = inject(PageEnvService);
private readonly toastService = inject(ToastsService);
private readonly usersClient = inject(UsersClient);
readonly #pageEnv = inject(PageEnvService);
readonly #toastService = inject(ToastsService);
readonly #usersClient = inject(UsersClient);

private readonly reload$ = new BehaviorSubject<void>(void 0);
readonly #reload$ = new BehaviorSubject<void>(void 0);
protected readonly accounts$: Observable<APIAccountsAccount[]> = combineLatest([
this.usersClient.getAccounts(new Empty()),
this.reload$,
this.#usersClient.getAccounts(new Empty()),
this.#reload$,
]).pipe(
catchError((error: unknown) => {
this.toastService.handleError(error);
this.#toastService.handleError(error);
return EMPTY;
}),
map(([response]) => response.items || []),
Expand All @@ -35,19 +35,19 @@ export class AccountAccountsComponent implements OnInit {
protected disconnectFailed = false;

ngOnInit(): void {
setTimeout(() => this.pageEnv.set({pageId: 123}), 0);
setTimeout(() => this.#pageEnv.set({pageId: 123}), 0);
}

protected remove(account: APIAccountsAccount) {
this.usersClient.deleteUserAccount(new DeleteUserAccountRequest({id: account.id})).subscribe({
this.#usersClient.deleteUserAccount(new DeleteUserAccountRequest({id: account.id})).subscribe({
error: (response: unknown) => {
this.disconnectFailed = true;
this.toastService.handleError(response);
this.#toastService.handleError(response);
},
next: () => {
this.toastService.success($localize`Account removed`);
this.#toastService.success($localize`Account removed`);

this.reload$.next();
this.#reload$.next();
},
});
}
Expand Down
36 changes: 18 additions & 18 deletions src/app/account/contacts/contacts.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,45 +22,45 @@ import {UserComponent} from '../../user/user/user.component';
templateUrl: './contacts.component.html',
})
export class AccountContactsComponent implements OnInit {
private readonly contactsService = inject(ContactsService);
private readonly pageEnv = inject(PageEnvService);
private readonly toastService = inject(ToastsService);
private readonly auth = inject(AuthService);
private readonly contacts = inject(ContactsClient);
private readonly languageService = inject(LanguageService);
private readonly keycloak = inject(Keycloak);
readonly #contactsService = inject(ContactsService);
readonly #pageEnv = inject(PageEnvService);
readonly #toastService = inject(ToastsService);
readonly #auth = inject(AuthService);
readonly #contacts = inject(ContactsClient);
readonly #languageService = inject(LanguageService);
readonly #keycloak = inject(Keycloak);

private readonly reload$ = new BehaviorSubject<void>(void 0);
readonly #reload$ = new BehaviorSubject<void>(void 0);

protected readonly items$: Observable<Contact[]> = this.auth.getUser$().pipe(
protected readonly items$: Observable<Contact[]> = this.#auth.getUser$().pipe(
map((user) => {
if (!user) {
this.keycloak.login({
locale: this.languageService.language,
this.#keycloak.login({
locale: this.#languageService.language,
redirectUri: window.location.href,
});
return EMPTY;
}
return user;
}),
switchMap(() => this.reload$),
switchMap(() => this.contactsService.getContacts$()),
switchMap(() => this.#reload$),
switchMap(() => this.#contactsService.getContacts$()),
catchError((error: unknown) => {
this.toastService.handleError(error);
this.#toastService.handleError(error);
return EMPTY;
}),
map((response) => response.items || []),
);

ngOnInit(): void {
setTimeout(() => this.pageEnv.set({pageId: 198}), 0);
setTimeout(() => this.#pageEnv.set({pageId: 198}), 0);
}

protected deleteContact(id: string) {
this.contacts.deleteContact(new DeleteContactRequest({userId: id})).subscribe({
error: (response: unknown) => this.toastService.handleError(response),
this.#contacts.deleteContact(new DeleteContactRequest({userId: id})).subscribe({
error: (response: unknown) => this.#toastService.handleError(response),
next: () => {
this.reload$.next(void 0);
this.#reload$.next(void 0);
},
});
return false;
Expand Down
22 changes: 11 additions & 11 deletions src/app/account/delete/delete.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,28 @@ import {ToastsService} from '../../toasts/toasts.service';
templateUrl: './delete.component.html',
})
export class AccountDeleteComponent implements OnInit {
private readonly router = inject(Router);
private readonly auth = inject(AuthService);
private readonly pageEnv = inject(PageEnvService);
private readonly toastService = inject(ToastsService);
private readonly usersGrpc = inject(UsersClient);
readonly #router = inject(Router);
readonly #auth = inject(AuthService);
readonly #pageEnv = inject(PageEnvService);
readonly #toastService = inject(ToastsService);
readonly #usersGrpc = inject(UsersClient);

protected readonly form = {
password_old: '',
};
protected invalidParams?: InvalidParams;

ngOnInit(): void {
setTimeout(() => this.pageEnv.set({pageId: 137}), 0);
setTimeout(() => this.#pageEnv.set({pageId: 137}), 0);
}

protected submit() {
this.auth
this.#auth
.getUser$()
.pipe(
switchMap((user) =>
user
? this.usersGrpc.deleteUser(
? this.#usersGrpc.deleteUser(
new APIDeleteUserRequest({
password: this.form.password_old,
userId: user.id,
Expand All @@ -52,15 +52,15 @@ export class AccountDeleteComponent implements OnInit {
)
.subscribe({
error: (response: unknown) => {
this.toastService.handleError(response);
this.#toastService.handleError(response);
if (response instanceof GrpcStatusEvent && response.statusCode === 3) {
const fieldViolations = extractFieldViolations(response);
this.invalidParams = fieldViolations2InvalidParams(fieldViolations);
}
},
next: () => {
this.auth.signOut$();
this.router.navigate(['/account/delete/deleted']);
this.#auth.signOut$();
this.#router.navigate(['/account/delete/deleted']);
},
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/account/delete/deleted/deleted.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import {MarkdownComponent} from '@utils/markdown/markdown.component';
templateUrl: './deleted.component.html',
})
export class AccountDeletedComponent implements OnInit {
private readonly pageEnv = inject(PageEnvService);
readonly #pageEnv = inject(PageEnvService);

ngOnInit(): void {
setTimeout(() => this.pageEnv.set({pageId: 93}), 0);
setTimeout(() => this.#pageEnv.set({pageId: 93}), 0);
}
}
12 changes: 6 additions & 6 deletions src/app/account/email/email.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ import {ToastsService} from '../../toasts/toasts.service';
templateUrl: './email.component.html',
})
export class AccountEmailComponent implements OnInit {
private readonly pageEnv = inject(PageEnvService);
private readonly toastService = inject(ToastsService);
private readonly usersClient = inject(UsersClient);
readonly #pageEnv = inject(PageEnvService);
readonly #toastService = inject(ToastsService);
readonly #usersClient = inject(UsersClient);

protected readonly email$: Observable<null | string> = this.usersClient
protected readonly email$: Observable<null | string> = this.#usersClient
.me(new APIMeRequest({fields: new UserFields({email: true})}))
.pipe(
catchError((error: unknown) => {
this.toastService.handleError(error);
this.#toastService.handleError(error);
return EMPTY;
}),
map((response) => response.email),
Expand All @@ -33,6 +33,6 @@ export class AccountEmailComponent implements OnInit {
environment.keycloak.url + '/realms/' + environment.keycloak.realm + '/account/#/personal-info';

ngOnInit(): void {
setTimeout(() => this.pageEnv.set({pageId: 55}), 0);
setTimeout(() => this.#pageEnv.set({pageId: 55}), 0);
}
}
12 changes: 6 additions & 6 deletions src/app/account/inbox-pictures/inbox-pictures.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ import {ToastsService} from '../../toasts/toasts.service';
templateUrl: './inbox-pictures.component.html',
})
export class AccountInboxPicturesComponent implements OnInit {
private readonly auth = inject(AuthService);
private readonly route = inject(ActivatedRoute);
private readonly pageEnv = inject(PageEnvService);
readonly #auth = inject(AuthService);
readonly #route = inject(ActivatedRoute);
readonly #pageEnv = inject(PageEnvService);
readonly #toastService = inject(ToastsService);
readonly #picturesClient = inject(PicturesClient);
readonly #languageService = inject(LanguageService);

protected readonly data$: Observable<PicturesList> = combineLatest([
this.route.queryParamMap.pipe(
this.#route.queryParamMap.pipe(
map((params) => parseInt(params.get('page') ?? '', 10)),
distinctUntilChanged(),
debounceTime(10),
),
this.auth.getUser$(),
this.#auth.getUser$(),
]).pipe(
switchMap(([page, user]) =>
user
Expand Down Expand Up @@ -67,6 +67,6 @@ export class AccountInboxPicturesComponent implements OnInit {
);

ngOnInit(): void {
setTimeout(() => this.pageEnv.set({pageId: 94}), 0);
setTimeout(() => this.#pageEnv.set({pageId: 94}), 0);
}
}
Loading

0 comments on commit 97719c5

Please sign in to comment.