Implement bikesService
parent
892e5dc224
commit
f363afdb55
@ -1,33 +1,19 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
import { DeepExtractTypeSkipArrays } from 'ts-deep-extract-types';
|
import { BikesService, CargoBikeResult } from 'src/app/services/bikes.service';
|
||||||
import { GetCargoBikesGQL, GetCargoBikesQuery } from '../../../../generated/graphql';
|
|
||||||
|
|
||||||
type CargoBikeResult = DeepExtractTypeSkipArrays<GetCargoBikesQuery, ["cargoBikes"]>;
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-bikes',
|
selector: 'app-bikes',
|
||||||
templateUrl: './bikes.component.html',
|
templateUrl: './bikes.component.html',
|
||||||
styleUrls: ['./bikes.component.scss'],
|
styleUrls: ['./bikes.component.scss'],
|
||||||
})
|
})
|
||||||
export class BikesComponent implements OnInit {
|
export class BikesComponent {
|
||||||
displayedColumns: string[] = ['id', 'name', 'weight', 'symbol'];
|
displayedColumns: string[] = ['id', 'name', 'weight', 'symbol'];
|
||||||
|
|
||||||
bikes: CargoBikeResult[];
|
bikes: CargoBikeResult[];
|
||||||
|
|
||||||
constructor(private bikesGQL: GetCargoBikesGQL) {
|
constructor(private bikesService: BikesService) {
|
||||||
this.bikesGQL.watch().valueChanges.subscribe((result) => {
|
bikesService.bikes.subscribe(bikes => this.bikes = bikes);
|
||||||
this.bikes = result.data.cargoBikes;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
onTableInput(element) {
|
bikesService.loadBikes();
|
||||||
//element.weight += 1;
|
|
||||||
console.log(element);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onFocus(event) {
|
|
||||||
console.log(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
ngOnInit(): void {}
|
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,21 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
import { BehaviorSubject } from 'rxjs';
|
||||||
|
import { GetCargoBikesGQL, GetCargoBikesQuery } from 'src/generated/graphql';
|
||||||
|
import { DeepExtractTypeSkipArrays } from 'ts-deep-extract-types';
|
||||||
|
|
||||||
|
export type CargoBikeResult = DeepExtractTypeSkipArrays<GetCargoBikesQuery, ["cargoBikes"]>;
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class BikesService {
|
export class BikesService {
|
||||||
|
bikes: BehaviorSubject<CargoBikeResult[]> = new BehaviorSubject([]);
|
||||||
|
|
||||||
|
constructor(private bikesGQL: GetCargoBikesGQL) { }
|
||||||
|
|
||||||
constructor() { }
|
loadBikes() {
|
||||||
|
this.bikesGQL.watch().valueChanges.subscribe((result) => {
|
||||||
|
this.bikes.next(result.data.cargoBikes);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue