Skip to content

Commit a419181

Browse files
authored
Merge pull request #6 from marcode24/dev
✨ add delete files
2 parents 721aadb + 25aa717 commit a419181

22 files changed

+339
-32
lines changed

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

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,31 @@
33
<div class="burger" (click)="changeVisibilitySidebar()">
44
<i class="bx bx-menu"></i>
55
</div>
6-
<div class="search">
6+
<div class="search" #inputSearch>
77
<div class="input-group">
88
<input type="text" class="icon" #txtSearch
9-
placeholder="Search...">
9+
placeholder="Search..." (focus)="focusInputSearch()" (blur)="focusInputSearch()">
1010
<i class="bx bx-search"></i>
1111
</div>
1212
</div>
13-
<div class="user">
14-
here's user
13+
<div class="profile">
14+
<div class="user">
15+
<div class="user-data" (click)="changeVisibilityOptions()">
16+
<div class="user-img">
17+
<img [src]="userActive.image" alt="user-image">
18+
</div>
19+
<span class="name">{{ userActive.name }} {{ userActive.surname }}</span>
20+
<div class="icon">
21+
<i class="bx bx-chevron-down"></i>
22+
</div>
23+
</div>
24+
<ul class="dropdown-user" #dropdownUser>
25+
<li class="item" (click)="logout()">
26+
<i class="bx bx-log-out"></i>
27+
<span>Cerrar sesión</span>
28+
</li>
29+
</ul>
30+
</div>
1531
</div>
1632
</div>
1733
</header>

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

Lines changed: 153 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ header {
99
width: -webkit-fill-available;
1010
background: var(--bg);
1111
border-bottom: 2px solid #e0e0e0;
12-
z-index: 90;
12+
z-index: 95;
1313

1414
@include width-medium {
1515
margin-left: 0;
@@ -23,13 +23,27 @@ header {
2323
gap: 1rem;
2424
padding: 0 1rem;
2525
height: 100%;
26+
position: relative;
2627

2728
& .search {
2829
flex: 1;
2930
display: flex;
3031
align-items: center;
3132
justify-content: space-between;
3233
gap: 1rem;
34+
35+
@include width-medium {
36+
flex: auto;
37+
}
38+
39+
@include width-small {
40+
&.focus {
41+
position: absolute;
42+
left: 1rem;
43+
right: 1rem;
44+
z-index: 100;
45+
}
46+
}
3347
}
3448
}
3549

@@ -98,9 +112,146 @@ header {
98112
}
99113
}
100114

101-
.user {
115+
.profile {
102116
flex: 1;
103117
display: flex;
104118
align-items: center;
105119
justify-content: flex-end;
120+
position: relative;
121+
122+
& .user {
123+
padding: 0.35rem 0.5rem;
124+
border-radius: 1rem;
125+
transition: 0.3s ease-in-out;
126+
127+
&:hover {
128+
background: var(--bg-hover-3);
129+
cursor: pointer;
130+
}
131+
132+
& .user-data {
133+
display: flex;
134+
align-items: center;
135+
justify-content: flex-end;
136+
gap: 0.5rem;
137+
138+
& .user-img {
139+
width: 38px;
140+
height: 38px;
141+
border-radius: 50%;
142+
display: flex;
143+
align-items: center;
144+
justify-content: center;
145+
overflow: hidden;
146+
147+
& img {
148+
width: 100%;
149+
height: 100%;
150+
object-fit: cover;
151+
}
152+
}
153+
154+
& .name {
155+
@include fs-6;
156+
@include fw-500;
157+
color: var(--fc-primary);
158+
text-overflow: ellipsis;
159+
overflow: hidden;
160+
white-space: nowrap;
161+
162+
@include width-small {
163+
display: none;
164+
}
165+
}
166+
167+
& .icon {
168+
display: flex;
169+
align-items: center;
170+
justify-content: center;
171+
color: var(--fc-primary);
172+
transition: 0.5s;
173+
border-radius: 50%;
174+
width: 35px;
175+
height: 35px;
176+
177+
@include width-small {
178+
display: none;
179+
}
180+
181+
& i {
182+
@include fs-1;
183+
}
184+
}
185+
}
186+
}
187+
}
188+
189+
.dropdown-user {
190+
display: none;
191+
z-index: 2;
192+
list-style-type: none;
193+
position: absolute;
194+
opacity: 0;
195+
top: 55px;
196+
right: 0;
197+
background-color: #f7f7f7;
198+
padding: 0;
199+
font-size: 16px;
200+
border-radius: 10px;
201+
box-shadow: none;
202+
visibility: hidden;
203+
height: fit-content;
204+
transition: visibility 0.2s, opacity 0.2s linear, bottom 0.2s linear,
205+
box-shadow 0.2s linear;
206+
min-width: 14rem;
207+
208+
&.active {
209+
opacity: 1;
210+
bottom: 0;
211+
display: block;
212+
visibility: visible;
213+
box-shadow: 0px 3px 12px 0px rgba(0, 0, 0, 0.25);
214+
}
215+
216+
.item {
217+
display: flex;
218+
align-items: center;
219+
list-style: none;
220+
height: 45px;
221+
transition: 0.3s ease;
222+
padding: 0 1rem;
223+
gap: 1rem;
224+
225+
&:hover {
226+
background: var(--bg-hover-3);
227+
cursor: pointer;
228+
}
229+
230+
&:first-child {
231+
border-radius: 10px 10px 0 0;
232+
}
233+
234+
&:last-child {
235+
border-radius: 0 0 10px 10px;
236+
}
237+
238+
&:first-of-type {
239+
border-radius: 10px;
240+
}
241+
242+
& span {
243+
@include fs-5;
244+
@include fw-400;
245+
color: var(--fc-primary);
246+
text-overflow: ellipsis;
247+
overflow: hidden;
248+
white-space: nowrap;
249+
}
250+
251+
& i {
252+
@include fs-4;
253+
@include fw-500;
254+
color: var(--fc-primary);
255+
}
256+
}
106257
}
Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,37 @@
1-
import { Component } from '@angular/core';
1+
import { Component, ElementRef, ViewChild } from '@angular/core';
2+
3+
import { AuthService } from '@services/auth.service';
24

35
@Component({
46
selector: 'app-header',
57
templateUrl: './header.component.html',
68
styleUrls: ['./header.component.scss']
79
})
810
export class HeaderComponent {
11+
@ViewChild('dropdownUser') dropdownUser: ElementRef;
12+
@ViewChild('inputSearch') inputSearch: ElementRef;
13+
userActive = this.authService.userActive;
14+
15+
constructor(
16+
private authService: AuthService
17+
) { }
18+
919
changeVisibilitySidebar(): void {
1020
const sidebarElement = document.querySelector('.sidebar') as HTMLElement;
1121
sidebarElement.classList.toggle('closed');
22+
const overlayElement = document.querySelector('.overlay') as HTMLElement;
23+
overlayElement.classList.toggle('opened');
24+
}
25+
26+
changeVisibilityOptions(): void {
27+
this.dropdownUser.nativeElement.classList.toggle('active');
28+
}
29+
30+
logout(): void {
31+
this.authService.logout();
32+
}
33+
34+
focusInputSearch(): void {
35+
this.inputSearch.nativeElement.classList.toggle('focus');
1236
}
1337
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,5 @@
3030
</li>
3131
</ul>
3232
</nav>
33+
34+
<div class="overlay" #overlay (click)="changeVisibilitySidebar()"></div>

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,25 @@ nav {
144144
justify-content: center;
145145
}
146146
}
147+
148+
.overlay {
149+
background-color: rgba(71, 80, 87, 0.4);
150+
top: 0;
151+
right: 0;
152+
bottom: 0;
153+
left: 0;
154+
width: 100%;
155+
z-index: 99;
156+
transition: left 0.3s ease-in-out;
157+
158+
&.opened {
159+
position: fixed;
160+
opacity: 1;
161+
left: 250px;
162+
transition: left 0.3s ease-in-out;
163+
}
164+
165+
@media (min-width: 769px) {
166+
display: none;
167+
}
168+
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, OnDestroy, OnInit } from '@angular/core';
1+
import { Component, ElementRef, OnDestroy, OnInit, ViewChild } from '@angular/core';
22

33
import { Subscription } from 'rxjs';
44

@@ -13,6 +13,8 @@ import { FileService } from '@services/file.service';
1313
export class SidebarComponent implements OnDestroy, OnInit {
1414
userActive = this.authService.userActive;
1515
private totalSizeSubscription: Subscription;
16+
@ViewChild('overlay') overlay: ElementRef;
17+
1618
constructor(
1719
private authService: AuthService,
1820
private fileService: FileService
@@ -36,5 +38,6 @@ export class SidebarComponent implements OnDestroy, OnInit {
3638
changeVisibilitySidebar(): void {
3739
const sidebarElement = document.querySelector('.sidebar') as HTMLElement;
3840
sidebarElement.classList.toggle('closed');
41+
this.overlay.nativeElement.classList.toggle('opened');
3942
}
4043
}

src/app/core/interfaces/response.interface.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@ export interface IFolderResponse {
2828
export interface IFileResponse {
2929
ok: boolean,
3030
msg: string,
31-
files: File[]
31+
files: File[],
32+
file: File,
3233
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,9 @@ export class AuthService {
6060
return true;
6161
}), catchError(() => of(false)));
6262
}
63+
64+
logout(): void {
65+
Storage.removeLocalStorage('token');
66+
this.router.navigateByUrl('/login');
67+
}
6368
}

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

Lines changed: 11 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+
fileDeleted: EventEmitter<FileModel> = new EventEmitter();
2021
updateTotalSize: EventEmitter<number> = new EventEmitter();
2122

2223
get headers() {
@@ -47,4 +48,14 @@ export class FileService {
4748
const url = `${base_url}/file/download/${fileID}`;
4849
return this.http.get(url, { responseType: 'blob', ...this.headers });
4950
}
51+
52+
deleteFile(fileID: string): Observable<boolean> {
53+
const url = `${base_url}/file/${fileID}`;
54+
return this.http.delete<IFileResponse>(url, this.headers).pipe(map(resp => {
55+
this.fileDeleted.emit(resp.file);
56+
this.updateTotalSize.emit(-resp.file.size);
57+
return resp.ok;
58+
}));
59+
}
60+
5061
}

src/app/features/folder/folder.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
<app-actions [folder]="folder"></app-actions>
12
<div class="fluid-container" *ngIf="!loading && folder">
2-
<app-actions [folder]="folder"></app-actions>
33
<div class="not-items" *ngIf="!allFiles.length">
44
<img src="assets/images/no-files.svg" alt="no-files-image">
55
<span class="description">Agrega tu primer archivo o carpeta</span>

0 commit comments

Comments
 (0)