JSFiddle - React, Tailwind, and code Playground
by nomadev
TypeScript
import { WindowRef } from './../../modules/shared/services/window.service';
import { ActivatedRoute, Router } from '@angular/router';
import { SubscriptionsService } from './../../modules/shared/services/subscriptions.service';
import { LocationService } from '../../services/location.service';
import { Component, OnDestroy, OnInit } from '@angular/core';
import { filter, tap, switchMap, map, throttleTime } from 'rxjs/operators';
import { combineLatest } from 'rxjs';
@Component({
selector: 'app-dashboard',
/**
* Il template di dashboard è una composizione di altri componenti. In particolare, le classi sidebar e right-body
* sono il selettore per la content projection all'interno del componente app-left-sidebar
* Il contenuto delle pagine figlie di dashboard sarà proiettato all'interno dell'elemento ng-content (punto di transclusion)
*/
template: `
<app-left-sidebar>
<app-sidebar class="sidebar"></app-sidebar>
<div class="right-body"><ng-content></ng-content></div>
</app-left-sidebar>`,
providers: [SubscriptionsService]
})
export class DashboardComponent implements OnInit, OnDestroy {
constructor(
public locations: LocationService,
private subs: SubscriptionsService,
private route: ActivatedRoute,
private $w: WindowRef,
private router: Router
) {}
private routeHandler() {
return switchMap( res => this.locations.getUserLocations()
.pipe(
filter(locations => locations.length > 0),
tap( locations => {
/**
* selected location is assigned given this priority:
* user selected location, route param, first available
*/
let id;
if (res[0] && res[0].id)
id = res[0].id;
else if (res[1])
id = res[1];
...