-
Notifications
You must be signed in to change notification settings - Fork 2
/
inner-page.component.ts
81 lines (69 loc) · 2.2 KB
/
inner-page.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
72
73
74
75
76
77
78
79
80
81
import { Component, OnInit } from '@angular/core';
import { ProjectService } from '../services/project.service';
import { AuthService } from '../services/auth.service';
import { HttpClient } from '@angular/common/http';
@Component({
selector: 'app-inner-page',
templateUrl: './inner-page.component.html',
styleUrls: ['./inner-page.component.css']
})
export class InnerPageComponent implements OnInit {
projects: any[] = [];
isLoggedIn;
page = 1;
Recpage = 1;
isLoading = true;
constructor(private authService: AuthService, private projectService: ProjectService, private http: HttpClient) {
this.isLoggedIn = this.authService.getIsLoggedIn();
}
ngOnInit() {
this.loadProjects();
}
loadProjects() {
this.projectService.getProjects(0).subscribe({
next: (projects) => {
this.projects = this.projects.concat(projects);
this.projects.forEach(project => {
this.loadProjectFirstImage(project);
});
this.isLoading = false
},
error: (error) => {
console.error('Error loading the projects:', error);
}
});
}
loadProjectFirstImage(project: any) {
this.projectService.getProjectFirstImage(project.id).subscribe(
imageUrl => {
project.imageUrl = imageUrl;
},
error => {
console.error('Error fetching the first image of the project:', error);
project.imageUrl = null;
}
);
}
loadMoreProjects() {
console.log("Load more");
this.projectService.getProjects(this.page).subscribe(projects => {
this.projects = this.projects.concat(projects);
projects.forEach(project => this.loadProjectFirstImage(project));
console.log(projects);
this.page++;
}, error => {
console.error('Error loading more projects:', error);
});
}
loadMoreRecProjects() {
console.log("Load more rec");
this.projectService.getProjects(this.Recpage).subscribe(projects => {
this.projects = this.projects.concat(projects);
projects.forEach(project => this.loadProjectFirstImage(project));
console.log(this.projects);
this.Recpage++;
}, error => {
console.error('Error loading more projects:', error);
});
}
}