Skip to content

Commit

Permalink
fix(appointment-ui): wrong dates in header
Browse files Browse the repository at this point in the history
  • Loading branch information
draylegend committed Sep 27, 2022
1 parent e7cbb82 commit 759941b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 12 deletions.
11 changes: 9 additions & 2 deletions libs/appointment/domain/src/lib/appointment.selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,16 @@ export const selectFeature = createFeatureSelector<State>(APPOINTMENT_KEY);

export const selectWorkingDays = createSelector(selectFeature, s => {
const d = getWeekSpan(s.selectedWeek, s.selectedYear).start;
const firstDay = d.getDate() - d.getDay();

return s.workingDays.map(day => ({ day, date: firstDay + day }));
return s.workingDays.map(day => {
const date = new Date();

date.setFullYear(s.selectedYear);
date.setMonth(d.getMonth());
date.setDate(d.getDate() + day);

return date;
});
});

export const selectWorkingHours = createSelector(
Expand Down
8 changes: 4 additions & 4 deletions libs/appointment/ui/src/lib/days/days.component.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<div
*ngFor="let day of workingDays"
*ngFor="let date of workingDays"
[ngClass]="{
active: day.date === now,
'past-day': day.date < now
active: date | today,
'past-day': date.getTime() < time
}"
>
{{ day.date }} {{ dayNames[day.day] }}
{{ date.getDate() }} {{ dayNames[date.getDay()] }}
</div>
26 changes: 21 additions & 5 deletions libs/appointment/ui/src/lib/days/days.component.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,35 @@
import { JsonPipe, NgClass, NgForOf } from '@angular/common';
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
import {
ChangeDetectionStrategy,
Component,
Input,
Pipe,
PipeTransform,
} from '@angular/core';

const now = () => new Date().getDate();
@Pipe({
name: 'today',
standalone: true,
})
export class TodayPipe implements PipeTransform {
transform(date: Date): boolean {
const d = new Date();

return date.getDate() === d.getDate();
}
}

@Component({
changeDetection: ChangeDetectionStrategy.OnPush,
selector: 'im-days[workingDays]',
standalone: true,
styleUrls: ['./days.component.scss'],
templateUrl: './days.component.html',
imports: [NgForOf, JsonPipe, NgClass],
imports: [NgForOf, JsonPipe, NgClass, TodayPipe],
})
export class DaysComponent {
dayNames = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
now = now();
time = new Date().getTime();

@Input() workingDays?: { day: number; date: number }[];
@Input() workingDays?: Date[];
}
2 changes: 1 addition & 1 deletion libs/appointment/ui/src/lib/week/week.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { WeekContentComponent } from '../week-content/week-content.component';
],
})
export class WeekComponent {
@Input() workingDays?: { day: number; date: number }[];
@Input() workingDays?: Date[];

@Input() viewings?: Viewings;

Expand Down

0 comments on commit 759941b

Please sign in to comment.