Skip to content

Commit

Permalink
Update time showed in the published date dropdown (#490)
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillermo Gonzalez committed Mar 21, 2024
1 parent 212d630 commit 59656ff
Showing 1 changed file with 27 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ import {
} from '@dcs-libs/shared';
import { SelectImageModalComponent } from './select-image-modal/select-image-modal.component';
import { UploadFileModalComponent } from '../../components/upload-file.modal';
import { Time } from "@angular/common";

interface TimeType {
title: string;
minutes: number;
}

@Component({
selector: 'app-overview',
Expand All @@ -32,7 +38,7 @@ export class OverviewComponent extends Permissions implements OnInit, OnDestroy
formDataChange = false;
imageChange = false;

timesSelections: any[] = [];
timesSelections: TimeType[] = [];

articleForm = new UntypedFormGroup({
body: new UntypedFormControl(''),
Expand Down Expand Up @@ -60,11 +66,7 @@ export class OverviewComponent extends Permissions implements OnInit, OnDestroy
@Inject(WINDOW) private window: Window
) {
super();
this.timesSelections = [...Array(24).keys()].reduce((p: any[], v) => {
p.push({minutes: v * 60, title: `${v}:00`});
p.push({minutes: v * 60 + 30, title: `${v}:30`});
return p;
}, []);
this.populateAvailableTimes();

this.window.document.addEventListener('keydown', this.shortCutHandlerMethod.bind(this));
}
Expand All @@ -91,8 +93,11 @@ export class OverviewComponent extends Permissions implements OnInit, OnDestroy
this.post.publishedAt = new Date(this.post.publishedAt);
this.articleForm.controls['date'].setValue(this.post.publishedAt);

const time = this.post.publishedAt.getHours() * 60 + this.post.publishedAt.getMinutes();
this.articleForm.controls['time'].setValue(time);
const minutes = this.post.publishedAt.getHours() * 60 + this.post.publishedAt.getMinutes();
const title = `${this.post.publishedAt.getHours()}:${this.post.publishedAt.getMinutes()}`;
this.populateAvailableTimes({title, minutes} as TimeType)

this.articleForm.controls['time'].setValue(minutes);
}
}
});
Expand All @@ -107,6 +112,20 @@ export class OverviewComponent extends Permissions implements OnInit, OnDestroy
this.getTags = this.getTags.bind(this);
}

populateAvailableTimes(extraTime: TimeType | null = null): void {
this.timesSelections = [...Array(24).keys()].reduce((p: TimeType[], v: number) => {
p.push({minutes: v * 60, title: `${v}:00`} as TimeType);
p.push({minutes: v * 60 + 30, title: `${v}:30`} as TimeType);
return p;
}, []);

if (extraTime) {
this.timesSelections.push(extraTime);
}

this.timesSelections = this.timesSelections.sort((a: TimeType, b: TimeType): number => a.minutes - b.minutes);
}

ngOnDestroy(): void {
this._unsubscribe.next(true);
this._stopTimer.next(true);
Expand Down

0 comments on commit 59656ff

Please sign in to comment.