File

src/components/bar-page/bar-page.tsx

Metadata

tag bar-page
styleUrl bar-page.css

Index

Properties
Methods

Methods

componentDidLoad
componentDidLoad()
Returns : void
Async getBars
getBars(position: Position)
Parameters :
Name Type Optional
position Position No
Returns : any
render
render()
Returns : {}
search
search(ev)
Decorators :
@Listen('ionInput')
Parameters :
Name Optional
ev No
Returns : void
Async showErrorToast
showErrorToast()
Returns : any

Properties

bars
bars: Array<Bar>
Type : Array<Bar>
Decorators :
@State()
Private isServer
isServer: boolean
Type : boolean
Decorators :
@Prop({context: 'isServer'})
toastCtrl
toastCtrl: HTMLIonToastControllerElement
Type : HTMLIonToastControllerElement
Decorators :
@Prop({connect: 'ion-toast-controller'})
import { Component, State, Prop, Listen } from '@stencil/core';

import { Bar } from '../../global/interfaces';

@Component({
  tag: 'bar-page',
  styleUrl: 'bar-page.css'
})
export class BarPage {

  @State() bars: Array<Bar>;

  @Prop({ context: 'isServer' }) private isServer: boolean;
  @Prop({ connect: 'ion-toast-controller' }) toastCtrl: HTMLIonToastControllerElement;

  componentDidLoad() {
    if (!this.isServer) {
      navigator.geolocation.getCurrentPosition((position: Position) => {
        try {
          this.getBars(position);
        }
        catch (err) {
          this.showErrorToast();
        }
      });
    }
  }

  async showErrorToast() {
    const toast = await this.toastCtrl.create({ message: 'Error loading data', duration: 1000 });
    toast.present();
  }

  async getBars(position: Position) {
    const response = await fetch('/googlePlaces', {
      method: 'post',
      body: JSON.stringify({ lat: position.coords.latitude, long: position.coords.longitude })
    })
    const data = await response.json();
    console.log(data);

    this.bars = data;
  }

  @Listen('ionInput')
  search(ev) {
    setTimeout(() => {
      const term = ev.detail.target.value;
      console.log(term);
      console.log(this.bars);

      this.bars = this.bars.filter((bar) =>
        bar.name.toLowerCase().indexOf(term.toLowerCase()) > -1
      );
    }, 1000);
  }

  render() {
    return [
      <profile-header>
      </profile-header>,

      <ion-toolbar color='dark'>
        <ion-searchbar></ion-searchbar>
      </ion-toolbar>,

      <ion-content>
        <bar-list bars={this.bars}></bar-list>
      </ion-content>
    ];
  }
}
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""