mirror of
https://github.com/jwetzell/itsfiveoclockwhere.git
synced 2026-08-22 07:18:59 +00:00
Make list able to just show closest with animation
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import { NgModule } from '@angular/core';
|
import { NgModule } from '@angular/core';
|
||||||
import { BrowserModule } from '@angular/platform-browser';
|
import { BrowserModule } from '@angular/platform-browser';
|
||||||
|
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
||||||
|
|
||||||
import { AppComponent } from './app.component';
|
import { AppComponent } from './app.component';
|
||||||
import { TimezoneService } from './timezone/services/timezone.service';
|
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 { TimezoneListComponent } from './timezone/components/timezone-list/timezone-list.component';
|
||||||
import { FiveoclockComponent } from './fiveoclock/fiveoclock.component';
|
import { FiveoclockComponent } from './fiveoclock/fiveoclock.component';
|
||||||
import { TimezoneSingleComponent } from './timezone/components/timezone-single/timezone-single.component';
|
import { TimezoneSingleComponent } from './timezone/components/timezone-single/timezone-single.component';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
declarations: [
|
declarations: [
|
||||||
AppComponent,
|
AppComponent,
|
||||||
@@ -17,6 +17,7 @@ import { TimezoneSingleComponent } from './timezone/components/timezone-single/t
|
|||||||
],
|
],
|
||||||
imports: [
|
imports: [
|
||||||
BrowserModule,
|
BrowserModule,
|
||||||
|
BrowserAnimationsModule,
|
||||||
AppRoutingModule,
|
AppRoutingModule,
|
||||||
],
|
],
|
||||||
providers: [TimezoneService],
|
providers: [TimezoneService],
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<ng-container *ngIf="justClosest; else listView">
|
<app-timezone-list
|
||||||
<app-timezone-single *ngIf="fiveOclock" [timezone]="fiveOclock" (click)="toggleView()"></app-timezone-single>
|
*ngIf="fiveOclocks"
|
||||||
</ng-container>
|
[timezones]="fiveOclocks"
|
||||||
|
[closest]="fiveOclock"
|
||||||
<ng-template #listView>
|
[showAll]="showAll"
|
||||||
<app-timezone-list *ngIf="fiveOclocks" [timezones]="fiveOclocks" (click)="toggleView()"></app-timezone-list>
|
(click)="toggleView()">
|
||||||
</ng-template>
|
</app-timezone-list>
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ export class FiveoclockComponent implements OnInit {
|
|||||||
fiveOclocks: Timezone[] = [];
|
fiveOclocks: Timezone[] = [];
|
||||||
fiveOclock: Timezone | undefined;
|
fiveOclock: Timezone | undefined;
|
||||||
|
|
||||||
justClosest: boolean = true;
|
showAll: boolean = false;
|
||||||
|
|
||||||
timezones: string[] =[]
|
timezones: string[] =[]
|
||||||
|
|
||||||
@@ -36,7 +36,7 @@ export class FiveoclockComponent implements OnInit {
|
|||||||
ngOnInit(): void { }
|
ngOnInit(): void { }
|
||||||
|
|
||||||
toggleView(){
|
toggleView(){
|
||||||
this.justClosest = !this.justClosest
|
this.showAll = !this.showAll
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,14 @@
|
|||||||
<div class="background">
|
<div class="background" [@displayState]="state" (@displayState.start)="animationEvent($event)" (@displayState.done)="animationEvent($event)">
|
||||||
<ng-container *ngFor="let timezone of timezones">
|
<ng-container *ngIf="showAllItems; else single" >
|
||||||
<div class="container">
|
<div *ngFor="let timezone of timezones" class="container" [ngStyle]="{'height': timezones.length == 1 ? '100%' : 'auto'}">
|
||||||
<h1 class="timezone">{{timezone.name}}</h1>
|
<h1 class="timezone">{{timezone.name}}</h1>
|
||||||
<h2 class="time">{{timezone.time?.toFormat('tt')}}</h2>
|
<h2 class="time">{{timezone.time?.toFormat('tt')}}</h2>
|
||||||
</div>
|
</div>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
<ng-template #single >
|
||||||
|
<div *ngIf="closest" class="single-container">
|
||||||
|
<h1 class="timezone">{{closest.name}}</h1>
|
||||||
|
<h2 class="time">{{closest.time?.toFormat('tt')}}</h2>
|
||||||
|
</div>
|
||||||
|
</ng-template>
|
||||||
</div>
|
</div>
|
||||||
@@ -1,21 +1,58 @@
|
|||||||
import { Component, Input, OnInit } from '@angular/core';
|
import { trigger, state, style, transition, animate, query, stagger } from '@angular/animations';
|
||||||
import { interval, Observable } from 'rxjs';
|
import { Component, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core';
|
||||||
import { Timezone } from '../../models/timezone.model';
|
import { Timezone } from '../../models/timezone.model';
|
||||||
import { TimezoneService } from '../../services/timezone.service';
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-timezone-list',
|
selector: 'app-timezone-list',
|
||||||
templateUrl: './timezone-list.component.html',
|
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() timezones: Timezone[] = [];
|
||||||
|
@Input() closest?: Timezone;
|
||||||
|
@Input() showAll: boolean = true;
|
||||||
|
|
||||||
|
showAllItems = true;
|
||||||
|
|
||||||
|
state: string = 'show'
|
||||||
constructor(){}
|
constructor(){}
|
||||||
|
|
||||||
|
|
||||||
|
ngOnChanges(changes: SimpleChanges): void {
|
||||||
|
if(!!changes['showAll']){
|
||||||
|
if(changes['showAll'].previousValue != changes['showAll'].currentValue){
|
||||||
|
this.state = 'hide'
|
||||||
|
}else{
|
||||||
|
this.state = 'show'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
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'){
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<div class="background">
|
<div class="background" [@displayState]="state">
|
||||||
<ng-container *ngIf="timezone">
|
<ng-container *ngIf="timezone">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<h1 class="timezone">{{timezone.name}}</h1>
|
<h1 class="timezone">{{timezone.name}}</h1>
|
||||||
|
|||||||
@@ -1,16 +1,30 @@
|
|||||||
|
import { animate, state, style, transition, trigger } from '@angular/animations';
|
||||||
import { Component, Input, OnInit } from '@angular/core';
|
import { Component, Input, OnInit } from '@angular/core';
|
||||||
import { Timezone } from '../../models/timezone.model';
|
import { Timezone } from '../../models/timezone.model';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-timezone-single',
|
selector: 'app-timezone-single',
|
||||||
templateUrl: './timezone-single.component.html',
|
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 {
|
export class TimezoneSingleComponent implements OnInit {
|
||||||
|
|
||||||
@Input() timezone: Timezone | undefined;
|
@Input() timezone: Timezone | undefined;
|
||||||
|
@Input() state: string = 'hide';
|
||||||
|
|
||||||
constructor(){ }
|
constructor(){}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ export function TimezoneCompare(a: Timezone, b: Timezone) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// http://www.movable-type.co.uk/scripts/latlong.html
|
// 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 location1 = timezoneMap[timezone]
|
||||||
var closestDist = Number.MAX_SAFE_INTEGER
|
var closestDist = Number.MAX_SAFE_INTEGER
|
||||||
var closestTimezone: Timezone | undefined = undefined
|
var closestTimezone: Timezone | undefined = undefined
|
||||||
|
|||||||
Reference in New Issue
Block a user