Added nav-bar to show home link and user status
This commit is contained in:
5
bookie/src/app/nav-bar/nav-bar.component.css
Normal file
5
bookie/src/app/nav-bar/nav-bar.component.css
Normal file
@ -0,0 +1,5 @@
|
||||
.fill-remaining-space {
|
||||
/* This fills the remaining space, by using flexbox.
|
||||
Every toolbar row uses a flexbox row layout. */
|
||||
flex: 1 1 auto;
|
||||
}
|
||||
15
bookie/src/app/nav-bar/nav-bar.component.html
Normal file
15
bookie/src/app/nav-bar/nav-bar.component.html
Normal file
@ -0,0 +1,15 @@
|
||||
<mat-toolbar>
|
||||
<a mat-button [routerLink]="['/']">
|
||||
<mat-icon>home</mat-icon>
|
||||
Point of Sale
|
||||
</a>
|
||||
<span class="fill-remaining-space"></span>
|
||||
<button mat-button [routerLink]="['/', 'login']" *ngIf="!(user | async)">
|
||||
<mat-icon>account_box</mat-icon>
|
||||
Login
|
||||
</button>
|
||||
<button mat-button [routerLink]="['/', 'logout']" *ngIf="user | async as name">
|
||||
<mat-icon>account_box</mat-icon>
|
||||
Logout {{name}}
|
||||
</button>
|
||||
</mat-toolbar>
|
||||
25
bookie/src/app/nav-bar/nav-bar.component.spec.ts
Normal file
25
bookie/src/app/nav-bar/nav-bar.component.spec.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { NavBarComponent } from './nav-bar.component';
|
||||
|
||||
describe('NavBarComponent', () => {
|
||||
let component: NavBarComponent;
|
||||
let fixture: ComponentFixture<NavBarComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ NavBarComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(NavBarComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
24
bookie/src/app/nav-bar/nav-bar.component.ts
Normal file
24
bookie/src/app/nav-bar/nav-bar.component.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { Observable } from "rxjs";
|
||||
import { map, share } from "rxjs/operators";
|
||||
import { AuthService } from "../auth/auth.service";
|
||||
|
||||
@Component({
|
||||
selector: 'app-nav-bar',
|
||||
templateUrl: './nav-bar.component.html',
|
||||
styleUrls: ['./nav-bar.component.css']
|
||||
})
|
||||
export class NavBarComponent implements OnInit {
|
||||
public user: Observable<string>;
|
||||
|
||||
constructor(public auth: AuthService) {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.user = this.auth.userObservable.pipe(
|
||||
map (x => x.isAuthenticated ? x.name : null),
|
||||
share()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user