@@ -2,16 +2,23 @@ import { Component } from '@angular/core';
2
2
import { RouterModule } from '@angular/router' ;
3
3
import { AuthService } from '../../service/auth.service' ;
4
4
import { CommonModule } from '@angular/common' ;
5
+ import { FormsModule } from '@angular/forms' ;
5
6
6
7
@Component ( {
7
8
selector : 'app-home' ,
8
9
standalone : true ,
9
- imports : [ RouterModule , CommonModule ] ,
10
+ imports : [ RouterModule , CommonModule , FormsModule ] ,
10
11
templateUrl : './home.component.html' ,
11
- styleUrl : './home.component.css'
12
+ styleUrls : [ './home.component.css' ]
12
13
} )
13
14
export class HomeComponent {
14
- title = "Home" ;
15
+ showTitlePrompt = false ;
16
+ showNoteEditor = false ;
17
+ newNoteTitle = '' ;
18
+ newNoteContent = '' ;
19
+ editingNote : any = null ;
20
+
21
+ notes : any [ ] = [ ] ;
15
22
16
23
constructor ( private authService : AuthService ) { }
17
24
@@ -21,6 +28,56 @@ export class HomeComponent {
21
28
22
29
logout ( ) : void {
23
30
this . authService . logout ( ) ;
24
- location . reload ( ) ; // Atualiza a página para refletir o logout
31
+ location . reload ( ) ;
32
+ }
33
+
34
+ openNoteTitlePrompt ( ) {
35
+ this . showTitlePrompt = true ;
36
+ this . newNoteTitle = '' ;
37
+ }
38
+
39
+ confirmTitle ( ) {
40
+ if ( this . newNoteTitle . trim ( ) ) {
41
+ this . showTitlePrompt = false ;
42
+ this . showNoteEditor = true ;
43
+ this . newNoteContent = '' ;
44
+ }
45
+ }
46
+
47
+ createNote ( ) {
48
+ if ( this . newNoteTitle . trim ( ) && this . newNoteContent . trim ( ) ) {
49
+ this . notes . push ( {
50
+ title : this . newNoteTitle ,
51
+ content : this . newNoteContent
52
+ } ) ;
53
+ this . resetNoteForm ( ) ;
54
+ }
55
+ }
56
+
57
+ editNote ( note : any ) {
58
+ this . editingNote = note ;
59
+ this . newNoteTitle = note . title ;
60
+ this . newNoteContent = note . content ;
61
+ this . showNoteEditor = true ;
62
+ }
63
+
64
+ saveEdit ( ) {
65
+ if ( this . editingNote ) {
66
+ this . editingNote . title = this . newNoteTitle ;
67
+ this . editingNote . content = this . newNoteContent ;
68
+ }
69
+ this . resetNoteForm ( ) ;
70
+ }
71
+
72
+ cancelEdit ( ) {
73
+ this . resetNoteForm ( ) ;
74
+ }
75
+
76
+ private resetNoteForm ( ) {
77
+ this . showNoteEditor = false ;
78
+ this . showTitlePrompt = false ;
79
+ this . newNoteTitle = '' ;
80
+ this . newNoteContent = '' ;
81
+ this . editingNote = null ;
25
82
}
26
83
}
0 commit comments