Files
Showy/frontend/src/app/shared/components/modals/seen-modal/seen-modal.component.ts
T

85 lines
2.1 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';
@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 {
title: string = 'Watch Details';
hideSeenWith: boolean = false;
public watchDate: string = '';
public watchedWith: string = '';
constructor(
public dialogRef: MatDialogRef<SeenModalComponent>,
@Inject(MAT_DIALOG_DATA) public data: any
) {}
ngOnInit(): void {
if (this.data) {
if (this.data.title) {
this.title = this.data.title;
}
if (this.data.watchedWith)
this.watchedWith = this.data.watchedWith.split(', ').join('\n');
if (this.data.hideSeenWith) {
this.hideSeenWith = this.data.hideSeenWith;
}
// ? no initial data was passed: populate date field with current date
if (this.data.watchDate) {
// ? if data is passed, populate fields
this.watchDate = formatDate(
new Date(this.data.watchDate),
'yyyy-MM-dd',
'en-US'
);
}
} else {
this.watchDate = formatDate(new Date(), 'yyyy-MM-dd', 'en-US');
}
}
onConfirm(): void {
this.dialogRef.close({
watchDate: this.watchDate,
watchedWith: this.watchedWith,
});
}
onClose(): void {
this.dialogRef.close();
}
}