diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 0776627..791f938 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -1,5 +1,6 @@ import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; +import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { AppComponent } from './app.component'; import { TimezoneService } from './timezone/services/timezone.service'; @@ -7,7 +8,6 @@ import { AppRoutingModule } from './app-routing.module'; import { TimezoneListComponent } from './timezone/components/timezone-list/timezone-list.component'; import { FiveoclockComponent } from './fiveoclock/fiveoclock.component'; import { TimezoneSingleComponent } from './timezone/components/timezone-single/timezone-single.component'; - @NgModule({ declarations: [ AppComponent, @@ -17,6 +17,7 @@ import { TimezoneSingleComponent } from './timezone/components/timezone-single/t ], imports: [ BrowserModule, + BrowserAnimationsModule, AppRoutingModule, ], providers: [TimezoneService], diff --git a/src/app/fiveoclock/fiveoclock.component.html b/src/app/fiveoclock/fiveoclock.component.html index a0a21e7..f85f4a0 100644 --- a/src/app/fiveoclock/fiveoclock.component.html +++ b/src/app/fiveoclock/fiveoclock.component.html @@ -1,7 +1,7 @@ - - - - - - - + + diff --git a/src/app/fiveoclock/fiveoclock.component.ts b/src/app/fiveoclock/fiveoclock.component.ts index 75a8866..54c9ea0 100644 --- a/src/app/fiveoclock/fiveoclock.component.ts +++ b/src/app/fiveoclock/fiveoclock.component.ts @@ -13,7 +13,7 @@ export class FiveoclockComponent implements OnInit { fiveOclocks: Timezone[] = []; fiveOclock: Timezone | undefined; - justClosest: boolean = true; + showAll: boolean = false; timezones: string[] =[] @@ -36,7 +36,7 @@ export class FiveoclockComponent implements OnInit { ngOnInit(): void { } toggleView(){ - this.justClosest = !this.justClosest + this.showAll = !this.showAll } } diff --git a/src/app/timezone/components/timezone-list/timezone-list.component.html b/src/app/timezone/components/timezone-list/timezone-list.component.html index 0dce130..c7d10a9 100644 --- a/src/app/timezone/components/timezone-list/timezone-list.component.html +++ b/src/app/timezone/components/timezone-list/timezone-list.component.html @@ -1,8 +1,14 @@ -
- -
+
+ +

{{timezone.name}}

{{timezone.time?.toFormat('tt')}}

+ +
+

{{closest.name}}

+

{{closest.time?.toFormat('tt')}}

+
+
\ No newline at end of file diff --git a/src/app/timezone/components/timezone-list/timezone-list.component.ts b/src/app/timezone/components/timezone-list/timezone-list.component.ts index 1904e4d..6fbc841 100644 --- a/src/app/timezone/components/timezone-list/timezone-list.component.ts +++ b/src/app/timezone/components/timezone-list/timezone-list.component.ts @@ -1,21 +1,58 @@ -import { Component, Input, OnInit } from '@angular/core'; -import { interval, Observable } from 'rxjs'; +import { trigger, state, style, transition, animate, query, stagger } from '@angular/animations'; +import { Component, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core'; import { Timezone } from '../../models/timezone.model'; -import { TimezoneService } from '../../services/timezone.service'; @Component({ selector: 'app-timezone-list', templateUrl: './timezone-list.component.html', - styleUrls: ['./timezone-list.component.scss'] + styleUrls: ['./timezone-list.component.scss'], + animations:[ + trigger('displayState',[ + state('show', style({ + opacity : 1 + })), + state('hide', style({ + opacity : 0 + })), + transition('show=>hide', animate('450ms ease-out')), + transition('hide=>show', animate('450ms ease-in')) + ]) + ] }) -export class TimezoneListComponent implements OnInit { +export class TimezoneListComponent implements OnInit, OnChanges { @Input() timezones: Timezone[] = []; + @Input() closest?: Timezone; + @Input() showAll: boolean = true; + showAllItems = true; + + state: string = 'show' constructor(){} + + ngOnChanges(changes: SimpleChanges): void { + if(!!changes['showAll']){ + if(changes['showAll'].previousValue != changes['showAll'].currentValue){ + this.state = 'hide' + }else{ + this.state = 'show' + } + } + } + ngOnInit(): void { } + animationEvent($event: any){ + // console.log(`${this.state} has entered ${$event.phaseName}`); + if(this.state == 'hide' && $event.phaseName == 'done'){ + this.showAllItems = this.showAll; + this.state = 'show' + }else if(this.state == 'show' && $event.phaseName == 'done'){ + + } + } + } diff --git a/src/app/timezone/components/timezone-single/timezone-single.component.html b/src/app/timezone/components/timezone-single/timezone-single.component.html index 970f561..3ad7258 100644 --- a/src/app/timezone/components/timezone-single/timezone-single.component.html +++ b/src/app/timezone/components/timezone-single/timezone-single.component.html @@ -1,4 +1,4 @@ -
+

{{timezone.name}}

diff --git a/src/app/timezone/components/timezone-single/timezone-single.component.ts b/src/app/timezone/components/timezone-single/timezone-single.component.ts index 2fde846..1a3d3f9 100644 --- a/src/app/timezone/components/timezone-single/timezone-single.component.ts +++ b/src/app/timezone/components/timezone-single/timezone-single.component.ts @@ -1,16 +1,30 @@ +import { animate, state, style, transition, trigger } from '@angular/animations'; import { Component, Input, OnInit } from '@angular/core'; import { Timezone } from '../../models/timezone.model'; @Component({ selector: 'app-timezone-single', templateUrl: './timezone-single.component.html', - styleUrls: ['./timezone-single.component.scss'] + styleUrls: ['./timezone-single.component.scss'], + animations:[ + trigger('displayState',[ + state('show', style({ + opacity : 1 + })), + state('hide', style({ + opacity : 0 + })), + transition('show=>hide', animate('500ms ease-out')), + transition('hide=>show', animate('500ms ease-in')) + ]) + ] }) export class TimezoneSingleComponent implements OnInit { @Input() timezone: Timezone | undefined; + @Input() state: string = 'hide'; - constructor(){ } + constructor(){} ngOnInit(): void { } diff --git a/src/app/timezone/models/timezone.model.ts b/src/app/timezone/models/timezone.model.ts index 19849d3..f3e2923 100644 --- a/src/app/timezone/models/timezone.model.ts +++ b/src/app/timezone/models/timezone.model.ts @@ -26,7 +26,7 @@ export function TimezoneCompare(a: Timezone, b: Timezone) { } // http://www.movable-type.co.uk/scripts/latlong.html -export function GetClosestTimezoneFrom(timezone: string, timezones: Timezone[]) { +export function GetClosestTimezoneFrom(timezone: string, timezones: Timezone[]): Timezone | undefined{ var location1 = timezoneMap[timezone] var closestDist = Number.MAX_SAFE_INTEGER var closestTimezone: Timezone | undefined = undefined