Skip to content

Commit

Permalink
Merge branch 'main' into fix/felix
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderKugler authored Aug 1, 2024
2 parents d4001a4 + 77759ae commit 989672b
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/app/components/activity-card/activity-card.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class ActivityCardComponent implements OnInit {
this.getBookmarked(this.activity?.osm_id)
}

onBookmark(osm_id: string | null | undefined) {
onBookmark(osm_id: number | null | undefined) {
this.isBookmarked = !this.isBookmarked
const item = localStorage.getItem("savedLocations")
if (item) {
Expand All @@ -38,7 +38,7 @@ export class ActivityCardComponent implements OnInit {

}

getBookmarked(osm_id: string | null | undefined) {
getBookmarked(osm_id: number | null | undefined) {
const item = localStorage.getItem("savedLocations")
if(item) {
const savedLocations = JSON.parse(item)
Expand Down
5 changes: 3 additions & 2 deletions src/app/components/detail/detail.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ export class DetailComponent implements OnInit {

ngOnInit(): void {
this.scrollToTop();
const osmId = this.route.snapshot.paramMap.get('osm_id');
if (osmId) {
const osmIdString = this.route.snapshot.paramMap.get('osm_id');
if (osmIdString) {
const osmId = parseInt(osmIdString, 10);
this.activityService.getActivitiesByOsmId(osmId).subscribe((activities) => {
this.activity = activities[0];
});
Expand Down
46 changes: 38 additions & 8 deletions src/app/components/for-you-page/for-you-page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Activity } from '../../types/activity.interface';
import { AirtableService } from '../../services/airtable.service';
import { ActivityCardComponent } from '../activity-card/activity-card.component';
import { NgIf } from '@angular/common';
import { ActivatedRoute, Router } from '@angular/router';

@Component({
selector: 'app-for-you-page',
Expand All @@ -20,7 +21,11 @@ export class ForYouPageComponent implements OnInit{
isLoading = true;
activities: Activity[] = [];

constructor(private airtable: AirtableService){}
constructor(
private airtable: AirtableService,
private route: ActivatedRoute,
private router: Router
){}

ngOnInit(): void {
this.airtable.getActivityList().subscribe(
Expand All @@ -35,16 +40,41 @@ export class ForYouPageComponent implements OnInit{
}

shuffle(activities: Activity[], count: number): Activity[] {
const shuffledArray = activities.slice();
for (let i = shuffledArray.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[shuffledArray[i], shuffledArray[j]] = [shuffledArray[j], shuffledArray[i]];
}
let result: Activity[];
// Prüfen, ob URL-Parameter vorhanden sind
const osmIds = this.route.snapshot.queryParamMap.get('osm_ids');

return shuffledArray.slice(0, count);
if (osmIds) {
const idsArray: number[] = osmIds.split(',').map((id: string) => parseInt(id, 10));
result = activities.filter((activity: Activity) => idsArray.includes(activity.osm_id));
} else {
const shuffledArray = activities.slice();
for (let i = shuffledArray.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[shuffledArray[i], shuffledArray[j]] = [shuffledArray[j], shuffledArray[i]];
}
result = shuffledArray.slice(0, count);
this.updateUrlWithIds(result);
}
return result
}

doReshuffle(): void {
this.shuffledActivities = this.shuffle(this.allActivities, 3);
this.router.navigate([], {
relativeTo: this.route,
queryParams: { osm_ids: null },
queryParamsHandling: 'merge'
}).then(() => {
this.shuffledActivities = this.shuffle(this.allActivities, 3);
});
}

updateUrlWithIds(randomItems: Activity[]): void {
const osmIds = randomItems.map((activity: Activity) => activity.osm_id).join(',');
this.router.navigate([], {
relativeTo: this.route,
queryParams: { osm_ids: osmIds },
queryParamsHandling: 'merge'
});
}
}
2 changes: 1 addition & 1 deletion src/app/components/map/map.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class MapComponent implements OnInit {

constructor(private router: Router, private airtableService: AirtableService) {}

getBookmarked(osm_id: string | null | undefined) {
getBookmarked(osm_id: number | null | undefined) {
const item = localStorage.getItem("savedLocations")
if(item) {
const savedLocations = JSON.parse(item)
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/navbar/navbar.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
@if (isRootUrl) {
<button routerLink="/map" class="btn hide-on-mobile rounded-full"><i class="bi bi-map"></i></button>
} @else {
<button routerLink="/" class="btn hide-on-mobile rounded-full"><i class="bi bi-map"></i></button>
<button routerLink="/" class="btn hide-on-mobile rounded-full"><i class="bi bi-list-ul"></i></button>
}
<button routerLink="/favorites" class="btn hide-on-mobile rounded-full"><i class="bi bi-bookmark"></i></button>
@if(isHamburgerMenuActive) {
Expand Down
2 changes: 1 addition & 1 deletion src/app/features/favorites/favorites.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class FavoritesComponent {

constructor(private airtable: AirtableService) { }

getActivityByOsm(osm_id: string) {
getActivityByOsm(osm_id: number) {
return this.airtable.getActivitiesByOsmId(osm_id);
}

Expand Down
4 changes: 2 additions & 2 deletions src/app/services/airtable.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class AirtableService {
}
}

getActivitiesByOsmId(osmId: string): Observable<Activity[]> {
getActivitiesByOsmId(osmId: number): Observable<Activity[]> {
return this.getActivityList().pipe(map(activities => {
return Array.from(activities).filter(activity => activity.osm_id == osmId)
}))
Expand Down Expand Up @@ -77,7 +77,7 @@ export class AirtableService {
latitude: record.fields['latitude'] as number,
longitude: record.fields['longitude'] as number,
website: record.fields['website'] as string,
osm_id: record.fields['osm_id'] as string,
osm_id: record.fields['osm_id'] as number,
media: medias.find((media: any) => media.id === (record.fields?.['media']?.[0])) as any,
age_restriction: record.fields['age_restriction'] as number,
barrier_free: record.fields['barrier_free'] as boolean,
Expand Down
2 changes: 1 addition & 1 deletion src/app/types/activity.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export interface Activity {
name: string;
description?: string;
type: TypesInterface;
osm_id: string;
osm_id: number;
street: string;
number?: string;
zip: string;
Expand Down

0 comments on commit 989672b

Please sign in to comment.