Skip to content

Commit 5294eec

Browse files
committed
Display shelter requests on home page
1 parent 2299044 commit 5294eec

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

client/src/app/_services/shelters.service.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ export class SheltersService {
2828
);
2929
}
3030

31+
public getAllSheltersRequests(): Observable<any> {
32+
return this.http.get(
33+
`${this.apiBaseUrl}/users/request/all`
34+
);
35+
}
36+
3137
public joinShelter(shelter): Observable<any> {
3238
return this.http.post(
3339
`${this.apiBaseUrl}/shelters/join`,

client/src/app/home/home.component.ts

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,6 @@ export class HomeComponent implements AfterViewInit {
4040
accessToken: mapboxgl.accessToken
4141
}));
4242

43-
var personMarkerDiv = document.createElement('div');
44-
personMarkerDiv.style.backgroundImage = 'url("../../assets/person.png")';
45-
personMarkerDiv.style.width = '100px';
46-
personMarkerDiv.style.height = '100px';
47-
personMarkerDiv.style.backgroundRepeat = 'no-repeat'
48-
4943
this.sheltersService.getAllShelters()
5044
.subscribe(
5145
(res) => {
@@ -58,7 +52,7 @@ export class HomeComponent implements AfterViewInit {
5852
shelterMarkerDiv.style.backgroundRepeat = 'no-repeat'
5953

6054
const shelter = res[i];
61-
55+
6256
new mapboxgl.Marker(shelterMarkerDiv)
6357
.setLngLat(shelter.lngLat.split(','))
6458
.setPopup(
@@ -69,7 +63,32 @@ export class HomeComponent implements AfterViewInit {
6963
}
7064
},
7165
(err) => this.alertService.error(err)
72-
)
66+
);
67+
68+
this.sheltersService.getAllSheltersRequests()
69+
.subscribe(
70+
(res) => {
71+
var i = 0;
72+
for (i = 0; i < res.length; i++) {
73+
var personMarkerDiv = document.createElement('div');
74+
personMarkerDiv.style.backgroundImage = 'url("../../assets/person.png")';
75+
personMarkerDiv.style.width = '100px';
76+
personMarkerDiv.style.height = '100px';
77+
personMarkerDiv.style.backgroundRepeat = 'no-repeat'
78+
79+
const userShelterRequest = res[i];
80+
81+
if (!userShelterRequest.shelterRequestLngLat) {
82+
continue;
83+
}
84+
85+
new mapboxgl.Marker(personMarkerDiv)
86+
.setLngLat(userShelterRequest.shelterRequestLngLat.split(','))
87+
.addTo(map);
88+
}
89+
},
90+
(err) => this.alertService.error(err)
91+
);
7392
}
7493

7594
}

0 commit comments

Comments
 (0)