Skip to content

Commit 0ef1824

Browse files
committed
💄 add alert notification
1 parent 83aaa85 commit 0ef1824

13 files changed

+257
-5
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export interface IAlert {
2+
message: string;
3+
type: 'success' | 'error';
4+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { TestBed } from '@angular/core/testing';
2+
3+
import { AlertService } from './alert.service';
4+
5+
describe('AlertService', () => {
6+
let service: AlertService;
7+
8+
beforeEach(() => {
9+
TestBed.configureTestingModule({});
10+
service = TestBed.inject(AlertService);
11+
});
12+
13+
it('should be created', () => {
14+
expect(service).toBeTruthy();
15+
});
16+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { EventEmitter, Injectable } from '@angular/core';
2+
3+
import { IAlert } from '@interfaces/alert.interface';
4+
5+
@Injectable({
6+
providedIn: 'root'
7+
})
8+
export class AlertService {
9+
10+
alert: EventEmitter<IAlert> = new EventEmitter();
11+
12+
emitAlert(alert: IAlert): void {
13+
this.alert.emit(alert);
14+
}
15+
16+
}

src/app/features/features.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<div class="container">
55
<div class="content">
66
<router-outlet></router-outlet>
7+
<app-alert></app-alert>
78
</div>
89
</div>
910
</div>

src/app/features/features.component.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
.content {
44
padding-top: 75px;
55
height: 100%;
6+
position: relative;
67

78
@include width-medium {
89
padding-top: 70px;

src/app/features/features.module.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { CommonModule } from '@angular/common';
22
import { NgModule } from '@angular/core';
33
import { RouterModule } from '@angular/router';
44

5+
import { AlertsModule } from '@shared/alerts/alerts.module';
6+
57
import { ComponentsModule } from '@components/components.module';
68

79
import { FeaturesComponent } from './features.component';
@@ -19,7 +21,8 @@ import { SearchModule } from './search/search.module';
1921
ComponentsModule,
2022
HomeModule,
2123
FolderModule,
22-
SearchModule
24+
SearchModule,
25+
AlertsModule,
2326
]
2427
})
2528
export class FeaturesModule { }

src/app/features/folder/folder.component.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ActivatedRoute } from '@angular/router';
33

44
import { Subscription } from 'rxjs';
55

6+
import { AlertService } from '@services/alert.service';
67
import { FileService } from '@services/file.service';
78
import { FolderService } from '@services/folder.service';
89

@@ -28,6 +29,7 @@ export class FolderComponent implements OnInit, OnDestroy {
2829
private folderService: FolderService,
2930
private fileService: FileService,
3031
private activadedRoute: ActivatedRoute,
32+
private alertService: AlertService,
3133
) { }
3234

3335
ngOnDestroy(): void {
@@ -40,19 +42,39 @@ export class FolderComponent implements OnInit, OnDestroy {
4042
ngOnInit(): void {
4143
this.folderCreatedSubscripion = this.folderService
4244
.folderCreated.subscribe(({ folder, isNew }) => {
43-
if (isNew) this.folder.folders.push(folder);
44-
else this.folder.folders = this.folder.folders.map((f) => f._id === folder._id ? folder : f);
45+
if (isNew) {
46+
this.folder.folders.push(folder);
47+
this.alertService.emitAlert({
48+
type: 'success',
49+
message: 'Carpeta creada correctamente',
50+
});
51+
}
52+
else {
53+
this.folder.folders = this.folder.folders.map((f) => f._id === folder._id ? folder : f);
54+
this.alertService.emitAlert({
55+
type: 'success',
56+
message: 'Carpeta actualizada correctamente',
57+
});
58+
}
4559
this.orderFolders();
4660
this.mixFilesAndFolders();
4761
});
4862
this.filesUploadedSubscription = this.fileService.filesCreated.subscribe((files: File[]) => {
4963
this.folder.files.push(...files);
5064
this.mixFilesAndFolders();
65+
this.alertService.emitAlert({
66+
type: 'success',
67+
message: 'Archivos subidos correctamente',
68+
});
5169
});
5270
this.routerSubscription = this.activadedRoute.params.subscribe(() => this.getFolder());
5371
this.fileDeletedSubscription = this.fileService.fileDeleted.subscribe((file) => {
5472
this.folder.files = this.folder.files.filter((f) => f._id !== file._id);
5573
this.mixFilesAndFolders();
74+
this.alertService.emitAlert({
75+
type: 'success',
76+
message: 'Archivo eliminado correctamente',
77+
});
5678
});
5779
}
5880

src/app/features/home/home.component.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Component, OnDestroy, OnInit } from '@angular/core';
22

33
import { Subscription } from 'rxjs';
44

5+
import { AlertService } from '@services/alert.service';
56
import { AuthService } from '@services/auth.service';
67
import { FileService } from '@services/file.service';
78
import { FolderService } from '@services/folder.service';
@@ -24,6 +25,7 @@ export class HomeComponent implements OnInit, OnDestroy {
2425
private authService: AuthService,
2526
private folderService: FolderService,
2627
private fileService: FileService,
28+
private alertService: AlertService,
2729
) { }
2830

2931
ngOnDestroy(): void {
@@ -43,16 +45,35 @@ export class HomeComponent implements OnInit, OnDestroy {
4345
];
4446
this.folderCreatedSubscription = this.folderService
4547
.folderCreated.subscribe(({folder, isNew}) => {
46-
if (isNew) this.root.folders.push(folder);
47-
else this.root.folders = this.root.folders.map((f) => f._id === folder._id ? folder : f);
48+
if (isNew) {
49+
this.root.folders.push(folder);
50+
this.alertService.emitAlert({
51+
type: 'success',
52+
message: 'Carpeta creada correctamente',
53+
});
54+
} else {
55+
this.root.folders = this.root.folders.map((f) => f._id === folder._id ? folder : f);
56+
this.alertService.emitAlert({
57+
type: 'success',
58+
message: 'Carpeta actualizada correctamente',
59+
});
60+
}
4861
this.orderFolders();
4962
});
5063
this.filesCreatedSubscription = this.fileService.filesCreated.subscribe((files) => {
5164
this.root.files.push(...files);
5265
this.orderFiles();
66+
this.alertService.emitAlert({
67+
type: 'success',
68+
message: 'Archivos subidos correctamente',
69+
});
5370
});
5471
this.fileDeletedSubscription = this.fileService.fileDeleted.subscribe((file) => {
5572
this.root.files = this.root.files.filter((f) => f._id !== file._id);
73+
this.alertService.emitAlert({
74+
type: 'success',
75+
message: 'Archivo eliminado correctamente',
76+
});
5677
});
5778
this.isLoading = false;
5879
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<div class="alert" #alert [ngClass]="alertOptions.type">
2+
<div class="alert-content">
3+
<span class="title">{{ alertOptions.message }}</span>
4+
<div class="icon" (click)="hideAlert()">
5+
<i class="bx bx-x"></i>
6+
</div>
7+
</div>
8+
</div>
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
@import 'settings/_colors.scss';
2+
@import 'settings/_typography.scss';
3+
4+
.alert {
5+
position: fixed;
6+
bottom: 20px;
7+
right: 20px;
8+
width: 75%;
9+
border-radius: 1rem;
10+
padding: 0.6rem 0.8rem;
11+
box-shadow: rgb(149 157 165 / 50%) 0px 8px 24px;
12+
-webkit-box-shadow: rgb(149 157 165 / 50%) 0px 8px 24px;
13+
-moz-box-shadow: rgb(149 157 165 / 50%) 0px 8px 24px;
14+
pointer-events: none;
15+
transform: translateY(100px);
16+
transition: transform 0.5s ease-in;
17+
max-width: 25rem;
18+
19+
&.success {
20+
background-color: $green;
21+
22+
& .icon {
23+
&:hover {
24+
background-color: #36b158;
25+
}
26+
}
27+
}
28+
29+
&.error {
30+
background-color: $red;
31+
32+
& .icon {
33+
&:hover {
34+
background-color: #e74c3c;
35+
}
36+
}
37+
}
38+
39+
&.show {
40+
pointer-events: auto;
41+
transform: translateY(0);
42+
transition: transform 0.3s ease-in;
43+
}
44+
45+
& .alert-content {
46+
height: 100%;
47+
display: flex;
48+
justify-content: space-between;
49+
align-items: center;
50+
gap: 10px;
51+
@include fs-6;
52+
@include fw-500;
53+
color: var(--fc-white);
54+
55+
& .title {
56+
width: 100%;
57+
}
58+
59+
& .icon {
60+
@include fs-5;
61+
width: 25px;
62+
height: 25px;
63+
display: flex;
64+
justify-content: center;
65+
align-items: center;
66+
border-radius: 50%;
67+
padding: 5px;
68+
transition: 0.3s ease-in;
69+
70+
&:hover {
71+
cursor: pointer;
72+
}
73+
}
74+
}
75+
}

0 commit comments

Comments
 (0)