Skip to content

Commit 147475c

Browse files
committed
✨ show used space
1 parent c8af0e2 commit 147475c

File tree

6 files changed

+99
-3
lines changed

6 files changed

+99
-3
lines changed

src/app/core/components/components.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 { PipesModule } from '@pipes/pipes.module';
6+
57
import { HeaderComponent } from './header/header.component';
68
import { SidebarComponent } from './sidebar/sidebar.component';
79

@@ -12,7 +14,8 @@ import { SidebarComponent } from './sidebar/sidebar.component';
1214
],
1315
imports: [
1416
CommonModule,
15-
RouterModule
17+
RouterModule,
18+
PipesModule
1619
],
1720
exports: [
1821
SidebarComponent,

src/app/core/components/sidebar/sidebar.component.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,21 @@
2323
<span class="name">Deleted</span>
2424
</a>
2525
</li>
26+
<li class="item space">
27+
<div class="used-space">
28+
<span class="name">Espacio utilizado</span>
29+
<div class="progress-bar">
30+
<div class="progress"
31+
#progress
32+
[ngStyle]="{'width': getProgress() }">
33+
</div>
34+
</div>
35+
<div class="percentage">
36+
<span class="used">{{ userActive.usedSpace | fileSize }}</span>
37+
<span class="slash">/</span>
38+
<span class="remaining">{{ userActive.totalSpace | fileSize }}</span>
39+
</div>
40+
</div>
41+
</li>
2642
</ul>
2743
</nav>

src/app/core/components/sidebar/sidebar.component.scss

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,48 @@ nav {
6565
}
6666
}
6767
}
68+
69+
.space {
70+
margin-top: 1.5rem;
71+
72+
& .used-space {
73+
padding: 0 0.5rem;
74+
display: flex;
75+
flex-direction: column;
76+
77+
& .name {
78+
@include fs-5;
79+
@include fw-500;
80+
color: var(--fc-primary);
81+
text-align: center;
82+
margin-bottom: 0.8rem;
83+
}
84+
85+
& .progress-bar {
86+
width: 100%;
87+
height: 10px;
88+
border-radius: 1rem;
89+
background: var(--bg-hover-2);
90+
overflow: hidden;
91+
92+
& .progress {
93+
height: 100%;
94+
background: var(--fc-purple);
95+
width: 0%;
96+
border-radius: 1rem;
97+
}
98+
}
99+
100+
& .percentage {
101+
@include fs-6;
102+
@include fw-500;
103+
color: var(--fc-primary);
104+
margin-top: 0.5rem;
105+
display: flex;
106+
align-items: center;
107+
justify-content: center;
108+
gap: 0.2rem;
109+
}
110+
}
111+
}
112+
Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,35 @@
1-
import { Component } from '@angular/core';
1+
import { Component, OnDestroy, OnInit } from '@angular/core';
2+
3+
import { Subscription } from 'rxjs';
4+
5+
import { AuthService } from '@services/auth.service';
6+
import { FileService } from '@services/file.service';
27

38
@Component({
49
selector: 'app-sidebar',
510
templateUrl: './sidebar.component.html',
611
styleUrls: ['./sidebar.component.scss']
712
})
8-
export class SidebarComponent {}
13+
export class SidebarComponent implements OnDestroy, OnInit {
14+
userActive = this.authService.userActive;
15+
private totalSizeSubscription: Subscription;
16+
constructor(
17+
private authService: AuthService,
18+
private fileService: FileService
19+
) { }
20+
ngOnInit(): void {
21+
this.totalSizeSubscription = this.fileService.updateTotalSize
22+
.subscribe((totalSize) => {
23+
this.userActive.usedSpace += totalSize;
24+
});
25+
}
26+
27+
ngOnDestroy(): void {
28+
this.totalSizeSubscription.unsubscribe();
29+
}
30+
31+
getProgress(): string {
32+
const percentage = this.userActive.usedSpace / this.userActive.totalSpace * 100;
33+
return `${percentage}%`;
34+
}
35+
}

src/app/core/models/user.model.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,7 @@ export class User {
1111
createdAt: Date;
1212
updatedAt: Date;
1313
rootFolder: Folder;
14+
totalSpace: number;
15+
usedSpace: number;
1416
_id?: string;
1517
}

src/app/core/services/file.service.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const base_url = environment.base_url;
1717
})
1818
export class FileService {
1919
filesCreated: EventEmitter<FileModel[]> = new EventEmitter();
20+
updateTotalSize: EventEmitter<number> = new EventEmitter();
2021

2122
get headers() {
2223
return {
@@ -36,6 +37,8 @@ export class FileService {
3637
files.forEach((file) => formData.append('file', file));
3738
return this.http.post<IFileResponse>(url, formData, this.headers).pipe(map(resp => {
3839
this.filesCreated.emit(resp.files);
40+
const total = resp.files.reduce((acc, file) => acc + file.size, 0);
41+
this.updateTotalSize.emit(total);
3942
return resp.ok;
4043
}));
4144
}

0 commit comments

Comments
 (0)