Skip to content

Commit 0280046

Browse files
committed
✨ add search files
1 parent 8e4bba0 commit 0280046

23 files changed

+226
-17
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,15 @@
55
</div>
66
<div class="search" #inputSearch>
77
<div class="input-group">
8-
<input type="text" class="icon" #txtSearch
9-
placeholder="Search..." (focus)="focusInputSearch()" (blur)="focusInputSearch()">
8+
<input
9+
type="text"
10+
class="icon"
11+
placeholder="Search..."
12+
#txtSearch
13+
(focus)="focusInputSearch()"
14+
(blur)="focusInputSearch()"
15+
(keyup.enter)="goToSearch(txtSearch.value)"
16+
[value]="currentValueSearch">
1017
<i class="bx bx-search"></i>
1118
</div>
1219
</div>

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { Component, ElementRef, ViewChild } from '@angular/core';
1+
import { Component, ElementRef, OnInit, ViewChild } from '@angular/core';
2+
import { ActivatedRoute, Router } from '@angular/router';
23

34
import { AuthService } from '@services/auth.service';
45

@@ -7,15 +8,22 @@ import { AuthService } from '@services/auth.service';
78
templateUrl: './header.component.html',
89
styleUrls: ['./header.component.scss']
910
})
10-
export class HeaderComponent {
11+
export class HeaderComponent implements OnInit {
1112
@ViewChild('dropdownUser') dropdownUser: ElementRef;
1213
@ViewChild('inputSearch') inputSearch: ElementRef;
1314
userActive = this.authService.userActive;
15+
currentValueSearch = '';
1416

1517
constructor(
16-
private authService: AuthService
18+
private authService: AuthService,
19+
private router: Router,
20+
private activatedRoute: ActivatedRoute,
1721
) { }
1822

23+
ngOnInit(): void {
24+
this.activatedRoute.queryParams.subscribe(({ q }) => this.currentValueSearch = q || '');
25+
}
26+
1927
changeVisibilitySidebar(): void {
2028
const sidebarElement = document.querySelector('.sidebar') as HTMLElement;
2129
sidebarElement.classList.toggle('closed');
@@ -34,4 +42,9 @@ export class HeaderComponent {
3442
focusInputSearch(): void {
3543
this.inputSearch.nativeElement.classList.toggle('focus');
3644
}
45+
46+
goToSearch(query: string): void {
47+
if (query) this.router.navigate(['/search'], { queryParams: { q: query } });
48+
}
49+
3750
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ export class File {
1515
type: string;
1616
_id?: string;
1717
color?: string;
18+
path?: Folder[];
1819
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ export class Folder {
1717
color: string;
1818
_id?: string;
1919
__v?: number;
20+
path?: Folder[];
2021
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,9 @@ export class FileService {
5858
}));
5959
}
6060

61+
searchFiles(query: string): Observable<IFileResponse> {
62+
const url = `${base_url}/file/search?q=${query}`;
63+
return this.http.get<IFileResponse>(url, this.headers);
64+
}
65+
6166
}

src/app/features/features.module.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { ComponentsModule } from '@components/components.module';
77
import { FeaturesComponent } from './features.component';
88
import { FolderModule } from './folder/folder.module';
99
import { HomeModule } from './home/home.module';
10+
import { SearchModule } from './search/search.module';
1011

1112
@NgModule({
1213
declarations: [
@@ -17,7 +18,8 @@ import { HomeModule } from './home/home.module';
1718
RouterModule,
1819
ComponentsModule,
1920
HomeModule,
20-
FolderModule
21+
FolderModule,
22+
SearchModule
2123
]
2224
})
2325
export class FeaturesModule { }

src/app/features/features.routing.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ const routes: Routes = [
1919
canActivate: [AuthGuard],
2020
loadChildren: () => import('./folder/folder.routing')
2121
.then(m => m.FolderRoutingModule)
22+
},
23+
{
24+
path: 'search',
25+
component: FeaturesComponent,
26+
canActivate: [AuthGuard],
27+
loadChildren: () => import('./search/search.routing')
28+
.then(m => m.SearchRoutingModule)
2229
}
2330
];
2431

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</div>
88
<div class="files" *ngIf="allFiles.length && !isLoading">
99
<section class="group">
10-
<span class="title">Files</span>
10+
<span class="title">Archivos</span>
1111
<div class="items">
1212
<app-table-files *ngFor="let file of allFiles"
1313
[file]="file"

src/app/features/folder/folder.module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { NgModule } from "@angular/core";
44
import { HeadersModule } from "@shared/headers/headers.module";
55
import { LoadersModule } from "@shared/loaders/loaders.module";
66
import { ModalsModule } from "@shared/modals/modals.module";
7+
import { TablesModule } from "@shared/tables/tables.module";
78

8-
import { ComponentsModule } from "./components/components.module";
99
import { FolderComponent } from "./folder.component";
1010

1111
@NgModule({
@@ -16,8 +16,8 @@ import { FolderComponent } from "./folder.component";
1616
CommonModule,
1717
HeadersModule,
1818
ModalsModule,
19-
ComponentsModule,
2019
LoadersModule,
20+
TablesModule,
2121
]
2222
})
2323
export class FolderModule {}

src/app/features/home/home.component.scss

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,3 @@
3131
}
3232
}
3333
}
34-
35-
.loader {
36-
align-self: center;
37-
}

0 commit comments

Comments
 (0)