diff --git a/src/app/active-list-tasks/active-list-tasks.component.html b/src/app/active-list-tasks/active-list-tasks.component.html new file mode 100644 index 0000000..491d7bc --- /dev/null +++ b/src/app/active-list-tasks/active-list-tasks.component.html @@ -0,0 +1 @@ +
active-list-tasks works!
diff --git a/src/app/active-list-tasks/active-list-tasks.component.scss b/src/app/active-list-tasks/active-list-tasks.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/src/app/active-list-tasks/active-list-tasks.component.ts b/src/app/active-list-tasks/active-list-tasks.component.ts new file mode 100644 index 0000000..ef70d9d --- /dev/null +++ b/src/app/active-list-tasks/active-list-tasks.component.ts @@ -0,0 +1,42 @@ +import { Component, OnDestroy, OnInit } from '@angular/core'; +import { MatSnackBar } from '@angular/material/snack-bar'; +import { Router } from '@angular/router'; +import { Subscription } from 'rxjs'; +import { TaskList } from '../core/entity/task-list'; +import { TaskListService } from '../core/service/task-list.service'; + +@Component({ + selector: 'app-active-list-tasks', + templateUrl: './active-list-tasks.component.html', + styleUrls: ['./active-list-tasks.component.scss'] +}) +export class ActiveListTasksComponent implements OnInit, OnDestroy { + private _activeTaskList?: TaskList; + private _storeSubscription?: Subscription; + + constructor( + private _router: Router, + private _taskListService: TaskListService, + private _snackBar: MatSnackBar + ) {} + + ngOnInit(): void { + this._storeSubscription = this._taskListService.store$.subscribe(store => { + if (store.activeTaskListId) { + this._activeTaskList = store.taskLists.find(taskList => taskList.id === store.activeTaskListId); + if (!this._activeTaskList) { + this._backToTaskListPane(); + } + } + }); + } + + ngOnDestroy(): void { + this._storeSubscription?.unsubscribe(); + } + + private _backToTaskListPane(): void { + this._snackBar.open('La task-list active n\'existe pas dans le store.', 'Fermer', {duration: 5000}); + this._router.navigate(['/']); + } +} diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 93ce6d6..d960794 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -1,9 +1,11 @@ import { NgModule } from '@angular/core'; import { RouterModule, Routes } from '@angular/router'; +import { ActiveListTasksComponent } from './active-list-tasks/active-list-tasks.component'; import { MainPageComponent } from './main-page/main-page.component'; const routes: Routes = [ - { path: '', component: MainPageComponent} + { path: '', component: MainPageComponent}, + { path: 'task-lists/active', component: ActiveListTasksComponent } ]; @NgModule({ diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 1056484..72b416b 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -17,6 +17,7 @@ import {MatButtonModule} from '@angular/material/button'; import {ReactiveFormsModule} from '@angular/forms'; import {MatSnackBarModule} from '@angular/material/snack-bar'; import { HeaderComponent } from './core/components/header/header.component'; +import { ActiveListTasksComponent } from './active-list-tasks/active-list-tasks.component'; @NgModule({ declarations: [ @@ -26,7 +27,8 @@ import { HeaderComponent } from './core/components/header/header.component'; DisplayTaskComponent, TaskListsComponent, AddTaskListComponent, - HeaderComponent + HeaderComponent, + ActiveListTasksComponent ], imports: [ BrowserModule, diff --git a/src/app/core/components/header/header.component.html b/src/app/core/components/header/header.component.html index 158b172..b0bf001 100644 --- a/src/app/core/components/header/header.component.html +++ b/src/app/core/components/header/header.component.html @@ -1,8 +1,17 @@