-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Search bar full functional merged with the main
- Loading branch information
Showing
7 changed files
with
157 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,69 @@ | ||
import { Post } from 'src/app/models/post.model'; | ||
import { SearchService } from './search.service'; | ||
import { Component } from '@angular/core'; | ||
import { PostItem } from 'src/app/models/postItem.model'; | ||
import { User } from 'src/app/models/user.model'; | ||
import { PostsService } from 'src/app/post/services/posts.service'; | ||
|
||
|
||
@Component({ | ||
selector: 'app-search', | ||
templateUrl: './search.component.html', | ||
styleUrls: ['./search.component.css'], | ||
}) | ||
export class SearchComponent {} | ||
export class SearchComponent { | ||
userResults: User[] = [] | ||
postResults: Post[] = [] | ||
|
||
constructor(private searchService: SearchService, private postsService: PostsService) { } | ||
|
||
getUser(username: String) { | ||
this.searchService.getUser(username).subscribe( | ||
Response => this.userResults = Response as User[] | ||
) | ||
} | ||
|
||
getPost(name: String) { | ||
this.searchService.getPost(name).subscribe( | ||
Response => this.postResults = Response as Post[] | ||
) | ||
} | ||
|
||
searcher(name: String) { | ||
this.getUser(name) | ||
this.getPost(name) | ||
|
||
} | ||
|
||
|
||
|
||
|
||
hideContainer() { | ||
//[0]: desktop div [1]: mobile div | ||
//hide suggestion box | ||
(document.getElementsByClassName("autoCompleteBox")[0] as HTMLElement).style.visibility = "hidden"; | ||
(document.getElementsByClassName("autoCompleteBox")[1] as HTMLElement).style.visibility = "hidden"; | ||
//add border bottom radius | ||
(document.getElementsByClassName("searchBar")[0] as HTMLElement).style.borderBottomLeftRadius = "10px"; | ||
(document.getElementsByClassName("searchBar")[1] as HTMLElement).style.borderBottomLeftRadius = "10px"; | ||
(document.getElementsByClassName("searchWrapper")[0] as HTMLElement).style.borderBottomRightRadius = "10px"; | ||
(document.getElementsByClassName("searchWrapper")[1] as HTMLElement).style.borderBottomRightRadius = "10px"; | ||
} | ||
|
||
showContainer() { | ||
//[0]: desktop div [1]: mobile div | ||
//reveal suggestion box | ||
(document.getElementsByClassName("autoCompleteBox")[0] as HTMLElement).style.visibility = "visible"; | ||
(document.getElementsByClassName("autoCompleteBox")[1] as HTMLElement).style.visibility = "visible"; | ||
|
||
//remove border bottom radius | ||
(document.getElementsByClassName("searchBar")[0] as HTMLElement).style.borderBottomLeftRadius = "0px"; | ||
(document.getElementsByClassName("searchBar")[1] as HTMLElement).style.borderBottomLeftRadius = "0px"; | ||
(document.getElementsByClassName("searchWrapper")[0] as HTMLElement).style.borderBottomRightRadius = "0px"; | ||
(document.getElementsByClassName("searchWrapper")[1] as HTMLElement).style.borderBottomRightRadius = "0px"; | ||
} | ||
|
||
fetchImage(src: number | undefined) { | ||
return this.postsService.downloadImage(src as number); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
front/src/app/shared/components/search/search.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* tslint:disable:no-unused-variable */ | ||
|
||
import { TestBed, async, inject } from '@angular/core/testing'; | ||
import { SearchService } from './search.service'; | ||
|
||
describe('Service: Search', () => { | ||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
providers: [SearchService] | ||
}); | ||
}); | ||
|
||
it('should ...', inject([SearchService], (service: SearchService) => { | ||
expect(service).toBeTruthy(); | ||
})); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { Observable } from 'rxjs'; | ||
import { User } from 'src/app/models/user.model'; | ||
import { HttpClient } from '@angular/common/http'; | ||
import { Post } from 'src/app/models/post.model'; | ||
|
||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class SearchService { | ||
|
||
|
||
constructor(private httpClient: HttpClient) { } | ||
|
||
getUser(username: String): Observable<User[]> { | ||
return this.httpClient.get<User[]>("api/users/names/" + username); | ||
} | ||
|
||
getPost(username: String): Observable<Post[]> { | ||
return this.httpClient.get<Post[]>("api/posts/names/" + username); | ||
} | ||
|
||
|
||
|
||
} |