Skip to content

Commit

Permalink
fix: canteen days when previous day is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
smrtrfszm committed Aug 30, 2022
1 parent ad2479e commit 47c1075
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<h2>Menza étlap</h2>
<ng-container *ngFor="let week of [0, 1]">
<span class="menu-header">{{ week_prefixes[week] }}</span>
<div class="day" *ngFor="let day of [0,1,2,3,4]">
<span class="day-name">{{ weekdays[day] }}</span>
<ng-container *ngIf="(canteen | async)?.[week][day] as thisDay">
<span class="food" *ngFor="let meal of thisDay.menus">{{ meal.menu }}</span>
</ng-container>
</div>
<span class="menu-header">{{ week_prefixes[week] }}</span>
<div class="day" *ngFor="let day of [0, 1, 2, 3, 4]">
<span class="day-name">{{ weekdays[day] }}</span>
<ng-container *ngIf="days[day + week * 5] | async as thisDayMenu">
<span class="food" *ngFor="let meal of thisDayMenu">{{ meal.menu }}</span>
</ng-container>
</div>
</ng-container>
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { ChangeDetectionStrategy, Component, OnDestroy, OnInit } from '@angular/core'
import { Observable } from 'rxjs'
import { map } from 'rxjs/operators'
import { StructuredDataService } from '../../../../services/structured-data.service'
import { TitleService } from '../../../../services/title.service'
import {CanteenDay} from "../../models/cateen";
import {CanteenService} from "../../services/canteen.service";
import { CanteenDay, Menu } from '../../models/cateen'
import { CanteenService } from '../../services/canteen.service'
import { getDay } from 'date-fns'

@Component({
selector: 'verseghy-canteen',
Expand All @@ -22,15 +24,32 @@ export class CanteenComponent implements OnInit, OnDestroy {
{ item: 'https://verseghy-gimnazium.net/canteen', position: 1, name: 'Menza' },
])

days: Observable<[Menu, Menu, Menu?] | null>[] = []

constructor(
private structuredDataService: StructuredDataService,
private titleService: TitleService,
private canteenService: CanteenService,
private canteenService: CanteenService
) {}

ngOnInit() {
this.titleService.setTitle('Menza')
this.canteen = this.canteenService.getCanteen()

for (let week = 0; week < 2; week++) {
for (let day = 0; day < 5; day++) {
this.days[day + week * 5] = this.canteen.pipe(
map((weeks) => {
for (const weekDay of weeks[week]) {
if (getDay(weekDay.date) - 1 === day) {
return weekDay.menus
}
}
return null
})
)
}
}
}

ngOnDestroy() {
Expand Down

0 comments on commit 47c1075

Please sign in to comment.