-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.component.ts
71 lines (57 loc) · 2.66 KB
/
search.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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 {
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[],
error => this.userResults = []
)
}
getPost(name: String) {
this.searchService.getPost(name).subscribe(
Response => this.postResults = Response as Post[],
error => this.postResults = []
)
}
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);
}
}