Skip to content

Commit 35b05ad

Browse files
authored
Merge pull request #3255 from numbersprotocol/feature-update-profile-name
feat(features/home): update profile name
2 parents 09df7c0 + 483b94c commit 35b05ad

31 files changed

+111
-1068
lines changed

src/app/app-routing.module.ts

-8
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,6 @@ const routes: Routes = [
2424
import('./features/home/home.module').then(m => m.HomePageModule),
2525
canActivate: [AuthGuard],
2626
},
27-
{
28-
path: 'profile',
29-
loadChildren: () =>
30-
import('./features/profile/profile.module').then(
31-
m => m.ProfilePageModule
32-
),
33-
canActivate: [AuthGuard],
34-
},
3527
{
3628
path: 'settings',
3729
loadChildren: () =>

src/app/features/contacts/contacts.page.html

+5-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@
1818
"
1919
/>
2020
</ion-avatar>
21-
<ion-label>{{ contact.contact_name || contact.contact_email }}</ion-label>
21+
<ion-label>{{
22+
contact.contact_profile_display_name ||
23+
contact.contact_name ||
24+
contact.contact_email
25+
}}</ion-label>
2226
<ion-button
2327
(click)="delete(contact)"
2428
color="dark"

src/app/features/home/capture-tab/capture-tab.component.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
<app-avatar mat-card-avatar [editable]="false"></app-avatar>
4040
<mat-card-header>
4141
<mat-card-title>
42-
{{ username$ | ngrxPush }}
42+
{{ profileName$ | ngrxPush }}
4343
<ion-icon
4444
src="assets/images/icons/edit.svg"
4545
*ngIf="networkConnected$ | async"

src/app/features/home/capture-tab/capture-tab.component.ts

+13-61
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
import { formatDate, KeyValue } from '@angular/common';
2-
import { HttpErrorResponse } from '@angular/common/http';
32
import { ChangeDetectorRef, Component, OnInit } from '@angular/core';
43
import { MatDialog } from '@angular/material/dialog';
54
import { Router } from '@angular/router';
65
import { Browser } from '@capacitor/browser';
7-
import {
8-
ActionSheetButton,
9-
ActionSheetController,
10-
AlertController,
11-
} from '@ionic/angular';
6+
import { ActionSheetButton, ActionSheetController } from '@ionic/angular';
127
import { TranslocoService } from '@ngneat/transloco';
138
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
149
import { groupBy } from 'lodash-es';
@@ -18,7 +13,6 @@ import {
1813
concatMap,
1914
concatMapTo,
2015
map,
21-
shareReplay,
2216
startWith,
2317
tap,
2418
} from 'rxjs/operators';
@@ -30,7 +24,6 @@ import {
3024
import { ConfirmAlert } from '../../../shared/confirm-alert/confirm-alert.service';
3125
import { Database } from '../../../shared/database/database.service';
3226
import { DiaBackendAssetRepository } from '../../../shared/dia-backend/asset/dia-backend-asset-repository.service';
33-
import { DiaBackendAsseRefreshingService } from '../../../shared/dia-backend/asset/refreshing/dia-backend-asset-refreshing.service';
3427
import { DiaBackendAssetUploadingService } from '../../../shared/dia-backend/asset/uploading/dia-backend-asset-uploading.service';
3528
import { DiaBackendAuthService } from '../../../shared/dia-backend/auth/dia-backend-auth.service';
3629
import { DiaBackendTransactionRepository } from '../../../shared/dia-backend/transaction/dia-backend-transaction-repository.service';
@@ -75,12 +68,15 @@ export class CaptureTabComponent implements OnInit {
7568

7669
readonly email$ = this.diaBackendAuthService.email$;
7770

78-
readonly profileDescription$ = this.diaBackendAuthService.profileDescription$;
71+
readonly profileName$ = this.diaBackendAuthService.profileName$;
7972

80-
readonly profileBackground$ =
81-
this.diaBackendAuthService.profileBackground$.pipe(
82-
shareReplay({ bufferSize: 1, refCount: true })
83-
);
73+
readonly profileDescription$ = this.diaBackendAuthService.profile$.pipe(
74+
map(profile => profile.description)
75+
);
76+
77+
readonly profileBackground$ = this.diaBackendAuthService.profile$.pipe(
78+
map(profile => profile.profile_background_thumbnail ?? '')
79+
);
8480

8581
private readonly proofs$ = this.proofRepository.all$;
8682

@@ -148,8 +144,6 @@ export class CaptureTabComponent implements OnInit {
148144
private readonly diaBackendAuthService: DiaBackendAuthService,
149145
private readonly diaBackendAssetRepository: DiaBackendAssetRepository,
150146
private readonly diaBackendTransactionRepository: DiaBackendTransactionRepository,
151-
private readonly diaBackendAssetRefreshingService: DiaBackendAsseRefreshingService,
152-
private readonly alertController: AlertController,
153147
private readonly networkService: NetworkService,
154148
private readonly translocoService: TranslocoService,
155149
private readonly errorService: ErrorService,
@@ -160,6 +154,10 @@ export class CaptureTabComponent implements OnInit {
160154
this.uploadService.pendingTasks$
161155
.pipe(untilDestroyed(this))
162156
.subscribe(value => (this.pendingUploadTasks = value));
157+
this.diaBackendAuthService
158+
.readProfile$()
159+
.pipe(untilDestroyed(this))
160+
.subscribe();
163161
}
164162

165163
static async openFaq() {
@@ -255,52 +253,6 @@ export class CaptureTabComponent implements OnInit {
255253
.subscribe();
256254
}
257255

258-
async editUsername() {
259-
const alert = await this.alertController.create({
260-
header: this.translocoService.translate('editUsername'),
261-
inputs: [
262-
{
263-
name: 'username',
264-
type: 'text',
265-
value: await this.diaBackendAuthService.getUsername(),
266-
},
267-
],
268-
buttons: [
269-
{
270-
text: this.translocoService.translate('cancel'),
271-
role: 'cancel',
272-
},
273-
{
274-
text: this.translocoService.translate('ok'),
275-
handler: value => this.updateUsername(value.username),
276-
},
277-
],
278-
});
279-
return alert.present();
280-
}
281-
282-
private updateUsername(username: string) {
283-
const action$ = this.diaBackendAuthService
284-
.updateUser$({ username })
285-
.pipe(catchError((err: unknown) => this.handleUpdateUsernameError$(err)));
286-
return this.blockingActionService
287-
.run$(action$)
288-
.pipe(untilDestroyed(this))
289-
.subscribe();
290-
}
291-
292-
private handleUpdateUsernameError$(err: unknown) {
293-
if (err instanceof HttpErrorResponse) {
294-
const errorType = err.error.error?.type;
295-
if (errorType === 'duplicate_username') {
296-
return this.errorService.toastError$(
297-
this.translocoService.translate(`error.diaBackend.${errorType}`)
298-
);
299-
}
300-
}
301-
return this.errorService.toastError$(err);
302-
}
303-
304256
// eslint-disable-next-line class-methods-use-this
305257
keyDescendingOrder(
306258
a: KeyValue<string, Proof[]>,

src/app/features/home/details/information/session/information-session.service.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ export class DetailedCapture {
8989

9090
readonly creator$ = defer(() => {
9191
if (this.proofOrDiaBackendAsset instanceof Proof)
92-
return this.diaBackendAuthService.username$;
93-
return of(this.proofOrDiaBackendAsset.creator_name);
92+
return this.diaBackendAuthService.profileName$;
93+
return of(this.proofOrDiaBackendAsset.creator_profile_display_name ?? '');
9494
});
9595

9696
readonly geolocation$ = defer(async () => {

src/app/features/home/edit-profile/edit-profile.page.ts

+28-77
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
1-
import { HttpErrorResponse } from '@angular/common/http';
21
import { Component } from '@angular/core';
32
import { FormControl, UntypedFormGroup } from '@angular/forms';
43
import { NavController } from '@ionic/angular';
54
import { TranslocoService } from '@ngneat/transloco';
65
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
76
import { FormlyFieldConfig } from '@ngx-formly/core';
8-
import { combineLatest, forkJoin } from 'rxjs';
9-
import {
10-
catchError,
11-
first,
12-
map,
13-
shareReplay,
14-
switchMap,
15-
tap,
16-
} from 'rxjs/operators';
7+
import { combineLatest } from 'rxjs';
8+
import { catchError, first, map, tap } from 'rxjs/operators';
179
import { BlockingActionService } from '../../../shared/blocking-action/blocking-action.service';
1810
import { DiaBackendAuthService } from '../../../shared/dia-backend/auth/dia-backend-auth.service';
1911
import { ErrorService } from '../../../shared/error/error.service';
@@ -27,22 +19,21 @@ import { NetworkService } from '../../../shared/network/network.service';
2719
})
2820
export class EditProfilePage {
2921
readonly networkConnected$ = this.networkService.connected$;
30-
readonly username$ = this.diaBackendAuthService.username$;
31-
readonly avatar$ = this.diaBackendAuthService.avatar$.pipe(
32-
shareReplay({ bufferSize: 1, refCount: true })
22+
readonly profileName$ = this.diaBackendAuthService.profile$.pipe(
23+
map(profile => profile.display_name)
3324
);
34-
readonly profile$ = this.diaBackendAuthService
35-
.readProfile$()
36-
.pipe(shareReplay({ bufferSize: 1, refCount: true }));
37-
readonly description$ = this.profile$.pipe(
25+
readonly description$ = this.diaBackendAuthService.profile$.pipe(
3826
map(profile => profile.description)
3927
);
40-
readonly background$ = this.profile$.pipe(
28+
readonly avatar$ = this.diaBackendAuthService.profile$.pipe(
29+
map(profile => profile.profile_picture_thumbnail)
30+
);
31+
readonly background$ = this.diaBackendAuthService.profile$.pipe(
4132
map(profile => profile.profile_background_thumbnail)
4233
);
4334
readonly form = new UntypedFormGroup({});
4435
model: EditProfileFormModel = {
45-
username: '',
36+
profileName: '',
4637
description: '',
4738
profilePicture: undefined,
4839
profileBackground: undefined,
@@ -67,27 +58,27 @@ export class EditProfilePage {
6758

6859
createFormFields() {
6960
combineLatest([
70-
this.translocoService.selectTranslate('home.editProfile.username'),
61+
this.translocoService.selectTranslate('home.editProfile.profileName'),
7162
this.translocoService.selectTranslate('home.editProfile.description'),
7263
])
7364
.pipe(
74-
tap(([usernameTranslation, descriptionTranslation]) => {
65+
tap(([profileNameTranslation, descriptionTranslation]) => {
7566
this.fields = [
7667
{
77-
key: 'username',
68+
key: 'profileName',
7869
type: 'input',
7970
templateOptions: {
80-
label: usernameTranslation,
81-
placeholder: usernameTranslation,
71+
label: profileNameTranslation,
72+
placeholder: profileNameTranslation,
8273
appearance: 'outline',
8374
},
8475
validators: {
85-
username: {
86-
expression: (c: FormControl) => /^.{1,21}$/.test(c.value),
76+
profileName: {
77+
expression: (c: FormControl) => /^.{1,15}$/.test(c.value),
8778
message: () =>
8879
this.translocoService.translate(
8980
'home.editProfile.error.mustBeBetween',
90-
{ min: 1, max: 21 }
81+
{ min: 1, max: 15 }
9182
),
9283
},
9384
},
@@ -102,12 +93,12 @@ export class EditProfilePage {
10293
rows: 4,
10394
},
10495
validators: {
105-
username: {
106-
expression: (c: FormControl) => /^.{0,255}$/.test(c.value),
96+
description: {
97+
expression: (c: FormControl) => /^.{0,125}$/.test(c.value),
10798
message: () =>
10899
this.translocoService.translate(
109100
'home.editProfile.error.mustBeBetween',
110-
{ min: 0, max: 255 }
101+
{ min: 0, max: 125 }
111102
),
112103
},
113104
},
@@ -130,11 +121,11 @@ export class EditProfilePage {
130121
}
131122

132123
populateFormFields() {
133-
combineLatest([this.username$, this.description$])
124+
combineLatest([this.profileName$, this.description$])
134125
.pipe(
135126
first(),
136-
tap(([username, description]) => {
137-
this.model = { ...this.model, username, description };
127+
tap(([profileName, description]) => {
128+
this.model = { ...this.model, profileName, description };
138129
})
139130
)
140131
.subscribe();
@@ -151,19 +142,11 @@ export class EditProfilePage {
151142
}
152143

153144
async onSubmit() {
154-
const updateUserNameAction$ = this.blockingActionService
155-
.run$(
156-
this.diaBackendAuthService
157-
.updateUser$({ username: this.model.username })
158-
.pipe(
159-
catchError((err: unknown) => this.handleUpdateUsernameError$(err))
160-
)
161-
)
162-
.pipe(untilDestroyed(this));
163-
const updateProfileAction$ = this.blockingActionService
145+
this.blockingActionService
164146
.run$(
165147
this.diaBackendAuthService
166148
.updateProfile$({
149+
profileName: this.model.profileName,
167150
description: this.model.description,
168151
profilePicture: this.model.profilePicture,
169152
profileBackground: this.model.profileBackground,
@@ -173,39 +156,7 @@ export class EditProfilePage {
173156
)
174157
)
175158
.pipe(
176-
switchMap(() => this.diaBackendAuthService.syncUser$()),
177-
untilDestroyed(this)
178-
);
179-
forkJoin([updateUserNameAction$, updateProfileAction$])
180-
.pipe(tap(() => this.navController.back()))
181-
.subscribe();
182-
}
183-
184-
private handleUpdateUsernameError$(err: unknown) {
185-
if (err instanceof HttpErrorResponse) {
186-
const errorType = err.error.error?.type;
187-
if (errorType === 'duplicate_username') {
188-
return this.errorService.toastError$(
189-
this.translocoService.translate(`error.diaBackend.${errorType}`)
190-
);
191-
}
192-
}
193-
return this.errorService.toastError$(err);
194-
}
195-
196-
private updateProfile() {
197-
const updateProfileAction$ = this.diaBackendAuthService
198-
.updateProfile$({
199-
description: this.model.description,
200-
profilePicture: this.model.profilePicture,
201-
profileBackground: this.model.profileBackground,
202-
})
203-
.pipe(catchError((err: unknown) => this.handleUpdateProfileError(err)));
204-
205-
this.blockingActionService
206-
.run$(updateProfileAction$)
207-
.pipe(
208-
switchMap(() => this.diaBackendAuthService.syncUser$()),
159+
tap(() => this.navController.back()),
209160
untilDestroyed(this)
210161
)
211162
.subscribe();
@@ -217,7 +168,7 @@ export class EditProfilePage {
217168
}
218169

219170
interface EditProfileFormModel {
220-
username: string;
171+
profileName: string;
221172
description: string;
222173
profilePicture: File | undefined;
223174
profileBackground: File | undefined;

src/app/features/home/home.page.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<button (click)="sidenav.toggle()" mat-icon-button>
55
<mat-icon>arrow_back</mat-icon>
66
</button>
7-
<span>{{ username$ | ngrxPush }}</span>
7+
<span>{{ profileName$ | ngrxPush }}</span>
88
</mat-toolbar>
99
<mat-nav-list>
1010
<mat-list-item>

src/app/features/home/home.page.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export class HomePage {
6767
private shouldReloadWallet = false;
6868
selectedTabIndex = this.initialTabIndex;
6969

70-
readonly username$ = this.diaBackendAuthService.username$;
70+
readonly profileName$ = this.diaBackendAuthService.profileName$;
7171

7272
readonly hasNewInbox$ = this.diaBackendTransactionRepository.inbox$.pipe(
7373
catchError((err: unknown) => this.errorService.toastError$(err)),

0 commit comments

Comments
 (0)