Make unique URLs for graph timespans

This commit is contained in:
softsimon 2021-04-21 22:12:35 +04:00
parent d4508bd876
commit 5cb98b9813
No known key found for this signature in database
GPG Key ID: 488D7DCFB5A430D7
2 changed files with 23 additions and 10 deletions

View File

@ -14,28 +14,28 @@
<form [formGroup]="radioGroupForm" class="mb-3 float-right"> <form [formGroup]="radioGroupForm" class="mb-3 float-right">
<div class="btn-group btn-group-toggle" ngbRadioGroup name="radioBasic" formControlName="interval"> <div class="btn-group btn-group-toggle" ngbRadioGroup name="radioBasic" formControlName="interval">
<label ngbButtonLabel class="btn-primary btn-sm"> <label ngbButtonLabel class="btn-primary btn-sm">
<input ngbButton type="radio" [value]="'half_hour'"> 30M <input ngbButton type="radio" [value]="'half_hour'" (click)="setFragment('half_hour')"> 30M
</label> </label>
<label ngbButtonLabel class="btn-primary btn-sm"> <label ngbButtonLabel class="btn-primary btn-sm">
<input ngbButton type="radio" [value]="'hour'"> 1H <input ngbButton type="radio" [value]="'hour'" (click)="setFragment('hour')"> 1H
</label> </label>
<label ngbButtonLabel class="btn-primary btn-sm"> <label ngbButtonLabel class="btn-primary btn-sm">
<input ngbButton type="radio" [value]="'half_day'"> 12H <input ngbButton type="radio" [value]="'half_day'" (click)="setFragment('half_day')"> 12H
</label> </label>
<label ngbButtonLabel class="btn-primary btn-sm"> <label ngbButtonLabel class="btn-primary btn-sm">
<input ngbButton type="radio" [value]="'day'"> 1D <input ngbButton type="radio" [value]="'day'" (click)="setFragment('day')"> 1D
</label> </label>
<label ngbButtonLabel class="btn-primary btn-sm"> <label ngbButtonLabel class="btn-primary btn-sm">
<input ngbButton type="radio" [value]="'week'"> 1W <input ngbButton type="radio" [value]="'week'" (click)="setFragment('week')"> 1W
</label> </label>
<label ngbButtonLabel class="btn-primary btn-sm"> <label ngbButtonLabel class="btn-primary btn-sm">
<input ngbButton type="radio" [value]="'month'"> 1M <input ngbButton type="radio" [value]="'month'" (click)="setFragment('month')"> 1M
</label> </label>
<label ngbButtonLabel class="btn-primary btn-sm"> <label ngbButtonLabel class="btn-primary btn-sm">
<input ngbButton type="radio" [value]="'year'"> 1Y <input ngbButton type="radio" [value]="'year'" (click)="setFragment('year')"> 1Y
</label> </label>
<label ngbButtonLabel class="btn-primary btn-sm"> <label ngbButtonLabel class="btn-primary btn-sm">
<input ngbButton type="radio" [value]="'auto'" fragment="auto"> Auto <input ngbButton type="radio" [value]="'auto'" (click)="setFragment('auto')"> Auto
</label> </label>
</div> </div>
</form> </form>

View File

@ -1,6 +1,6 @@
import { ChangeDetectionStrategy, Component, OnDestroy, OnInit } from '@angular/core'; import { ChangeDetectionStrategy, Component, OnDestroy, OnInit } from '@angular/core';
import { FormBuilder, FormGroup } from '@angular/forms'; import { FormBuilder, FormGroup } from '@angular/forms';
import { ActivatedRoute } from '@angular/router'; import { ActivatedRoute, Router } from '@angular/router';
import { combineLatest, merge, Observable, of } from 'rxjs'; import { combineLatest, merge, Observable, of } from 'rxjs';
import { map, switchMap } from 'rxjs/operators'; import { map, switchMap } from 'rxjs/operators';
import { SeoService } from 'src/app/services/seo.service'; import { SeoService } from 'src/app/services/seo.service';
@ -29,6 +29,7 @@ export class BisqMarketComponent implements OnInit, OnDestroy {
private bisqApiService: BisqApiService, private bisqApiService: BisqApiService,
private formBuilder: FormBuilder, private formBuilder: FormBuilder,
private seoService: SeoService, private seoService: SeoService,
private router: Router,
) { } ) { }
ngOnInit(): void { ngOnInit(): void {
@ -36,6 +37,10 @@ export class BisqMarketComponent implements OnInit, OnDestroy {
interval: [this.defaultInterval], interval: [this.defaultInterval],
}); });
if (['half_hour', 'hour', 'half_day', 'day', 'week', 'month', 'year', 'auto'].indexOf(this.route.snapshot.fragment) > -1) {
this.radioGroupForm.controls.interval.setValue(this.route.snapshot.fragment, { emitEvent: false });
}
this.currency$ = this.bisqApiService.getMarkets$() this.currency$ = this.bisqApiService.getMarkets$()
.pipe( .pipe(
switchMap((markets) => combineLatest([of(markets), this.route.paramMap])), switchMap((markets) => combineLatest([of(markets), this.route.paramMap])),
@ -66,7 +71,7 @@ export class BisqMarketComponent implements OnInit, OnDestroy {
this.hlocData$ = combineLatest([ this.hlocData$ = combineLatest([
this.route.paramMap, this.route.paramMap,
merge(this.radioGroupForm.get('interval').valueChanges, of(this.defaultInterval)), merge(this.radioGroupForm.get('interval').valueChanges, of(this.radioGroupForm.get('interval').value)),
]) ])
.pipe( .pipe(
switchMap(([routeParams, interval]) => { switchMap(([routeParams, interval]) => {
@ -95,6 +100,14 @@ export class BisqMarketComponent implements OnInit, OnDestroy {
); );
} }
setFragment(fragment: string) {
this.router.navigate([], {
relativeTo: this.route,
queryParamsHandling: 'merge',
fragment: fragment
});
}
ngOnDestroy(): void { ngOnDestroy(): void {
this.websocketService.stopTrackingBisqMarket(); this.websocketService.stopTrackingBisqMarket();
} }