1
- import { Component , OnInit } from '@angular/core' ;
1
+ import { Component , OnInit } from '@angular/core' ;
2
2
import { FormBuilder , FormGroup , Validators } from '@angular/forms' ;
3
3
import { createPasswordStrengthValidator } from '../../validators/password-strength.validator' ;
4
4
import { createPromoRangeValidator } from '../../validators/date-range.validator' ;
5
5
import { CoursesService } from '../../services/courses.service' ;
6
6
import { Observable } from 'rxjs' ;
7
7
import { courseTitleValidator } from '../../validators/course-title.validator' ;
8
+ import { filter } from 'rxjs/operators' ;
8
9
9
10
@Component ( {
10
11
selector : 'create-course-step-1' ,
@@ -21,18 +22,18 @@ export class CreateCourseStep1Component implements OnInit {
21
22
constructor ( private fb : FormBuilder , private courses : CoursesService ) {
22
23
this . form = fb . group ( {
23
24
title : [
24
- "" , {
25
+ '' , {
25
26
validators : [ Validators . required , Validators . minLength ( 3 ) , Validators . maxLength ( 60 ) ] ,
26
27
asyncValidators : [ courseTitleValidator ( this . courses ) ] ,
27
- updateOn : " blur"
28
+ updateOn : ' blur'
28
29
}
29
30
] ,
30
- adminPassword : [ "" , [ Validators . required , Validators . minLength ( 8 ) , createPasswordStrengthValidator ( ) ] ] ,
31
- supportEmail : [ "" , [ Validators . required , Validators . email ] ] ,
32
- category : [ " BEGINNER" , Validators . required ] ,
31
+ adminPassword : [ '' , [ Validators . required , Validators . minLength ( 8 ) , createPasswordStrengthValidator ( ) ] ] ,
32
+ supportEmail : [ '' , [ Validators . required , Validators . email ] ] ,
33
+ category : [ ' BEGINNER' , Validators . required ] ,
33
34
downloadsAllowed : [ false , Validators . requiredTrue ] ,
34
35
releasedAt : [ new Date ( ) , Validators . required ] ,
35
- longDescription : [ "" , [ Validators . required , Validators . minLength ( 3 ) ] ] ,
36
+ longDescription : [ '' , [ Validators . required , Validators . minLength ( 3 ) ] ] ,
36
37
address : [ null ]
37
38
} ) ;
38
39
}
@@ -41,6 +42,24 @@ export class CreateCourseStep1Component implements OnInit {
41
42
42
43
this . courseCategories$ = this . courses . findCourseCategories ( ) ;
43
44
45
+ const draftValue = localStorage . getItem ( "STEP_1" ) ;
46
+
47
+ if ( draftValue ) {
48
+ this . form . setValue ( JSON . parse ( draftValue ) ) ;
49
+ }
50
+
51
+ this . form . valueChanges
52
+ . pipe (
53
+ filter ( val => this . form . valid )
54
+ )
55
+ . subscribe (
56
+ val => {
57
+
58
+ localStorage . setItem ( "STEP_1" , JSON . stringify ( val ) ) ;
59
+
60
+ }
61
+ ) ;
62
+
44
63
}
45
64
46
65
}
0 commit comments