diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 5ab9b3e..5b554bc 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -6,6 +6,7 @@ import { AppComponent } from './app.component'; import { HomeComponent } from './home/home.component'; import { ListComponent } from './list/list.component'; import { DetailComponent } from './detail/detail.component'; +import {FormsModule} from "@angular/forms"; @NgModule({ declarations: [ @@ -16,7 +17,8 @@ import { DetailComponent } from './detail/detail.component'; ], imports: [ BrowserModule, - AppRoutingModule + AppRoutingModule, + FormsModule ], providers: [], bootstrap: [AppComponent] diff --git a/src/app/home/home.component.css b/src/app/home/home.component.css index d61eef3..caf329e 100644 --- a/src/app/home/home.component.css +++ b/src/app/home/home.component.css @@ -1,20 +1,32 @@ -input{ - width: 500px; +.search { + display: flex; + align-items: center; + justify-content: center; + flex-direction: column; +} + +input { display: flex; justify-content: center; align-items: center; - position: absolute; - top: 30%; - left: 50%; - right: 50%; - bottom: 50%; - transform: translate(-50%, -50%); +} + +.list { + width: 500px; + justify-content: center; + align-items: center; + align-content: center; } .bg-image { - background-image: url('/assets/mountains.png'); + background-image: url('/src/assets/img/mountains.png'); background-size: cover; background-repeat: no-repeat; background-position: center center; height: 100vh; } + +.sun { + width: 10%; + height: auto; +} diff --git a/src/app/home/home.component.html b/src/app/home/home.component.html index 03e0e23..1564364 100644 --- a/src/app/home/home.component.html +++ b/src/app/home/home.component.html @@ -1,4 +1,14 @@ -
- -
+
+
+ +
+
diff --git a/src/app/home/home.component.ts b/src/app/home/home.component.ts index e78472b..3d44e1b 100644 --- a/src/app/home/home.component.ts +++ b/src/app/home/home.component.ts @@ -1,18 +1,99 @@ -import {Component, OnInit} from '@angular/core'; +import {AfterContentInit, AfterViewInit, Component, ElementRef, OnInit, ViewChild} from '@angular/core'; +import {debounceTime, distinctUntilChanged, fromEvent, Subject} from "rxjs"; + +interface Luogo { + nome: string; + latitudine: number; + longitudine: number; +} @Component({ selector: 'app-home', templateUrl: './home.component.html', styleUrls: ['./home.component.css'] }) -export class HomeComponent implements OnInit { +export class HomeComponent implements OnInit, AfterViewInit { + + luoghiPopup: Subject = new Subject() + latitude: number | undefined; longitude: number | undefined; - ngOnInit(): void { - navigator.geolocation.getCurrentPosition(position => { - this.latitude = position.coords.latitude; - this.longitude = position.coords.longitude; + backgroundColor: string | undefined; + + luoghi: Luogo[] = [ + {nome: 'Locarno', latitudine: 46.1704, longitudine: 8.7931}, + {nome: 'Lugano', latitudine: 46.0037, longitudine: 8.9511}, + {nome: 'Luzern', latitudine: 47.0502, longitudine: 8.3093}, + {nome: 'Lauterbrunnen', latitudine: 46.5939, longitudine: 7.9085} + ]; + luoghiFiltrati: Luogo[] = []; + luogoSelezionato: string = ''; + suggerimentoAttivo: boolean = false; + suggerimento: string = ''; + completamento: string = 'ciao'; + + @ViewChild('myInput') myInput?: ElementRef; + + ngAfterViewInit() { + fromEvent(this.myInput?.nativeElement, 'input') + .pipe( + // debounceTime(500), decommentarlo se bisogna fare una chiamata http + distinctUntilChanged() + ).subscribe((val: any) => { + this.luoghiPopup.next(this.luoghi.filter(l => l.nome.toLowerCase().startsWith(val.target.value.toLowerCase()))) }) } + + cercaLuogo(nome: string){ + + + + setTimeout(() => { + + }, 1000); + this.luoghiFiltrati = this.luoghi.filter((l: Luogo) => l.nome.toLowerCase().startsWith(nome.toLowerCase())); + if (this.luoghiFiltrati.length > 0) { + this.suggerimentoAttivo = true; + this.suggerimento = this.luoghiFiltrati[0].nome; + this.completamento = stringDifference(nome, this.suggerimento); + + } else { + this.suggerimentoAttivo = false; + this.suggerimento = ''; + } + } + + consigliaSuggerimento(nome: string) { + if (this.suggerimentoAttivo) { + this.luogoSelezionato = nome + "-"+this.completamento; + this.suggerimento = ''; + } + } + selezionaSuggerimento(event: KeyboardEvent) { + if (event.key === 'Tab' || event.key === 'Enter') { + if (this.suggerimentoAttivo) { + this.luogoSelezionato = this.suggerimento; + this.suggerimentoAttivo = false; + this.suggerimento = ''; + } + } + } + + ngOnInit(): void { + + } + + } + +function stringDifference(str1: string, str2: string): string { + let diff = ''; + for (let i = 0; i < str2.length; i++) { + if (str1[i] !== str2[i]) { + diff += str2[i]; + } + } + return diff; +} + diff --git a/src/assets/data.json b/src/assets/data.json new file mode 100644 index 0000000..233782c --- /dev/null +++ b/src/assets/data.json @@ -0,0 +1,27 @@ +{ + "nome": "Biasca", + "provincia": "TI", + "waypoints": [ + { + "nome": "Punto 1", + "lat": 46.123, + "lon": 8.123, + "descrizione": "Descrizione del punto 1", + "foto": "https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png" + }, + { + "nome": "Punto 2", + "lat": 46.123, + "lon": 8.123, + "descrizione": "Descrizione del punto 2", + "foto": "https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png" + }, + { + "nome": "Punto 3", + "lat": 46.123, + "lon": 8.123, + "descrizione": "Descrizione del punto 3", + "foto": "https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png" + } + ] +} diff --git a/src/assets/mountains.png b/src/assets/img/mountains.png similarity index 100% rename from src/assets/mountains.png rename to src/assets/img/mountains.png