@@ -2,6 +2,7 @@ import { SelectFileComponent } from '@devmx/shared-ui-global/image';
2
2
import { takeUntilDestroyed } from '@angular/core/rxjs-interop' ;
3
3
import { ProfileComponent } from './profile/profile.component' ;
4
4
import { ContactComponent } from './contact/contact.component' ;
5
+ import { debounceTime , filter , skip , take , timer } from 'rxjs' ;
5
6
import { SkillsComponent } from './skills/skills.component' ;
6
7
import { SocialComponent } from './social/social.component' ;
7
8
import { UserPhoto , provideUserPhoto } from '../../dialogs' ;
@@ -11,7 +12,6 @@ import { UpdatePhoto } from '@devmx/account-data-access';
11
12
import { UserComponent } from './user/user.component' ;
12
13
import { ReactiveFormsModule } from '@angular/forms' ;
13
14
import { UserForm } from '../../forms/user' ;
14
- import { filter , take } from 'rxjs' ;
15
15
import {
16
16
inject ,
17
17
signal ,
@@ -24,7 +24,6 @@ import {
24
24
AuthenticationFacade ,
25
25
} from '@devmx/account-data-access' ;
26
26
27
-
28
27
@Component ( {
29
28
selector : 'devmx-account' ,
30
29
templateUrl : './account.container.html' ,
@@ -53,6 +52,10 @@ export class AccountContainer {
53
52
54
53
photo = signal ( '' ) ;
55
54
55
+ state = signal < string | null > ( null ) ;
56
+
57
+ i = 0 ;
58
+
56
59
constructor ( ) {
57
60
this . userFacade . selected$
58
61
. pipe (
@@ -65,6 +68,8 @@ export class AccountContainer {
65
68
}
66
69
67
70
this . form . patch ( user ) ;
71
+
72
+ console . log ( ( this . i += 1 ) ) ;
68
73
} ) ;
69
74
70
75
this . authFacade . auth$
@@ -73,6 +78,10 @@ export class AccountContainer {
73
78
takeUntilDestroyed ( )
74
79
)
75
80
. subscribe ( ( auth ) => this . userFacade . loadOne ( auth . id ) ) ;
81
+
82
+ this . form . valueChanges
83
+ . pipe ( takeUntilDestroyed ( ) , debounceTime ( 4000 ) , skip ( 1 ) )
84
+ . subscribe ( ( ) => this . onSubmit ( ) ) ;
76
85
}
77
86
78
87
changePhoto ( file : File ) {
@@ -88,11 +97,17 @@ export class AccountContainer {
88
97
}
89
98
90
99
onSubmit ( ) {
100
+ const timer$ = timer ( 1000 ) . pipe ( take ( 1 ) ) ;
101
+
91
102
if ( this . form . valid ) {
92
103
const value = this . form . getRawValue ( ) as UpdateUser ;
93
- return this . userFacade . update ( value ) ;
104
+ this . state . set ( 'Salvando...' ) ;
105
+ this . userFacade . update ( value ) ;
106
+
107
+ return timer$ . subscribe ( ( ) => this . state . set ( null ) ) ;
94
108
}
95
109
96
- return this . form . markAllAsTouched ( ) ;
110
+ this . form . markAllAsTouched ( ) ;
111
+ return timer$ . subscribe ( ( ) => this . state . set ( null ) ) ;
97
112
}
98
113
}
0 commit comments