[frontend] Add dashboard routing and bare component logic

This commit is contained in:
Cathy Hu 2020-08-18 23:48:24 +02:00
parent 165263e559
commit 3e7bb6878f
7 changed files with 46 additions and 11 deletions

View file

@ -3,15 +3,17 @@ import { Routes, RouterModule } from '@angular/router';
import { DashboardComponent } from './dashboard.component'; import { DashboardComponent } from './dashboard.component';
import { HoodsComponent } from './hoods/hoods.component'; import { HoodsComponent } from './hoods/hoods.component';
import { SettingspageComponent } from './settingspage/settingspage.component'; import { SettingspageComponent } from './settingspage/settingspage.component';
import { AuthGuard } from '../core/auth/auth.guard';
const routes: Routes = [ const routes: Routes = [
{ {
path: '', path: '',
component: DashboardComponent, component: DashboardComponent,
children: [ children: [
{ path: 'list', component: HoodsComponent }, { path: '', component: HoodsComponent },
{ path: 'settings', component: SettingspageComponent }, { path: 'settings', component: SettingspageComponent },
], ],
canActivate: [AuthGuard],
}, },
]; ];

View file

@ -1 +1 @@
<p>dashboard works!</p> <router-outlet></router-outlet>

View file

@ -3,9 +3,10 @@ import { CommonModule } from '@angular/common';
import { HoodsComponent } from './hoods/hoods.component'; import { HoodsComponent } from './hoods/hoods.component';
import { SettingspageComponent } from './settingspage/settingspage.component'; import { SettingspageComponent } from './settingspage/settingspage.component';
import { DashboardComponent } from './dashboard.component'; import { DashboardComponent } from './dashboard.component';
import { DashboardRoutingModule } from './dashboard-routing.module';
@NgModule({ @NgModule({
declarations: [HoodsComponent, SettingspageComponent, DashboardComponent], declarations: [HoodsComponent, SettingspageComponent, DashboardComponent],
imports: [CommonModule], imports: [CommonModule, DashboardRoutingModule],
}) })
export class DashboardModule {} export class DashboardModule {}

View file

@ -1 +1,2 @@
<p>hoods works!</p> <p>hoods works!</p>
<div *ngFor="let item of hoods$ | async">{{ item.name }}</div>

View file

@ -1,15 +1,23 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { AdminService } from 'src/app/core/api';
import { map } from 'rxjs/operators';
@Component({ @Component({
selector: 'app-hoods', selector: 'app-hoods',
templateUrl: './hoods.component.html', templateUrl: './hoods.component.html',
styleUrls: ['./hoods.component.scss'] styleUrls: ['./hoods.component.scss'],
}) })
export class HoodsComponent implements OnInit { export class HoodsComponent implements OnInit {
hoods$ = this.adminService.getHoodsAdmin().pipe(
map((hoods) => {
const result = hoods.map((hood) => {
return hood.hood;
});
return result;
})
);
constructor() { } constructor(private readonly adminService: AdminService) {}
ngOnInit(): void {
}
ngOnInit(): void {}
} }

View file

@ -1 +1,3 @@
<p>hoodpage works!</p> <p>hoodpage works!</p>
{{ hood.landingpage }}

View file

@ -1,15 +1,36 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { HoodsService, BodyHood } from '../core/api';
import { first } from 'rxjs/operators';
@Component({ @Component({
selector: 'app-hoodpage', selector: 'app-hoodpage',
templateUrl: './hoodpage.component.html', templateUrl: './hoodpage.component.html',
styleUrls: ['./hoodpage.component.scss'] styleUrls: ['./hoodpage.component.scss'],
}) })
export class HoodpageComponent implements OnInit { export class HoodpageComponent implements OnInit {
hood: BodyHood;
constructor() { } constructor(
private route: ActivatedRoute,
private router: Router,
private readonly hoodService: HoodsService
) {}
ngOnInit(): void { ngOnInit(): void {
const hoodId = this.route.snapshot.params['id'];
if (hoodId) {
this.hoodService
.getHood(hoodId)
.pipe(first())
.subscribe(
(data) => {
this.hood = data;
},
(error) => {
this.router.navigate(['/404']);
}
);
}
} }
} }