76 lines
2.0 KiB
TypeScript
76 lines
2.0 KiB
TypeScript
import { Component, Inject, OnInit } from '@angular/core';
|
|
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
|
|
|
|
import {
|
|
trigger,
|
|
state,
|
|
style,
|
|
transition,
|
|
animate,
|
|
} from '@angular/animations';
|
|
import { formatDate } from '@angular/common';
|
|
import flatpickr from 'flatpickr';
|
|
|
|
@Component({
|
|
selector: 'app-seen-modal',
|
|
templateUrl: './seen-modal.component.html',
|
|
styleUrl: './seen-modal.component.css',
|
|
animations: [
|
|
trigger('fadeInOut', [
|
|
state('in', style({ opacity: 1 })),
|
|
transition(':enter', [style({ opacity: 0 }), animate(600)]),
|
|
transition(':leave', [animate(600, style({ opacity: 0 }))]),
|
|
]),
|
|
trigger('scaleInOut', [
|
|
transition(':enter', [
|
|
state('in', style({ opacity: 1 })),
|
|
style({ transform: 'scale(0)' }),
|
|
animate('200ms ease-in-out', style({ transform: 'scale(1)' })),
|
|
]),
|
|
transition(':leave', [
|
|
animate('200ms ease-in-out', style({ transform: 'scale(0)' })),
|
|
]),
|
|
]),
|
|
],
|
|
})
|
|
export class SeenModalComponent implements OnInit {
|
|
public watchDate: string = '';
|
|
public watchedWith: string = '';
|
|
|
|
constructor(
|
|
public dialogRef: MatDialogRef<SeenModalComponent>,
|
|
@Inject(MAT_DIALOG_DATA) public data: any
|
|
) {}
|
|
|
|
ngOnInit(): void {
|
|
if (this.data == null) {
|
|
// ? no initial data was passed: populate date field with current date
|
|
this.watchDate = formatDate(new Date(), 'yyyy-MM-dd', 'en-US');
|
|
} else {
|
|
// ? if data is passed, populate fields
|
|
this.watchDate = formatDate(new Date(this.data.watchDate), 'yyyy-MM-dd', 'en-US');
|
|
this.watchedWith = this.data.watchedWith.split(', ').join('\n');
|
|
}
|
|
|
|
flatpickr('#myDatepicker', {
|
|
inline: true,
|
|
defaultDate: this.watchDate,
|
|
altInput: true,
|
|
allowInput: false,
|
|
altFormat: 'F j, Y',
|
|
dateFormat: 'Y-m-d',
|
|
});
|
|
}
|
|
|
|
onConfirm(): void {
|
|
this.dialogRef.close({
|
|
watchDate: this.watchDate,
|
|
watchedWith: this.watchedWith,
|
|
});
|
|
}
|
|
|
|
onClose(): void {
|
|
this.dialogRef.close();
|
|
}
|
|
}
|