diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 29bbadd..ebbf788 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -23,7 +23,8 @@ import {MatCheckboxModule} from '@angular/material/checkbox'; import { TaskListService } from './core/service/task-list.service'; import { StorePersistenceService } from './core/service/store-persistence.service'; import {MatTooltipModule} from '@angular/material/tooltip'; -import {MatRippleModule} from '@angular/material/core'; +import {MatRippleModule} from '@angular/material/core'; +import { RenameTaskListComponent } from './task-lists/rename-task-list/rename-task-list.component'; @NgModule({ declarations: [ @@ -35,7 +36,8 @@ import {MatRippleModule} from '@angular/material/core'; AddTaskListComponent, HeaderComponent, ActiveListTasksComponent, - TaskDisplayComponent + TaskDisplayComponent, + RenameTaskListComponent ], imports: [ BrowserModule, diff --git a/src/app/core/service/task-list.service.ts b/src/app/core/service/task-list.service.ts index 9f433b5..654a794 100644 --- a/src/app/core/service/task-list.service.ts +++ b/src/app/core/service/task-list.service.ts @@ -29,7 +29,12 @@ export class TaskListService { } private get store(): Store { - return this._storePersistenceService.load(); + let result = this._store.value; + + if (!result) { + result = this._storePersistenceService.load(); + } + return result; } private saveStore(store: Store, silent: boolean = false): void { @@ -112,6 +117,16 @@ export class TaskListService { this.saveStore(store); } + updateTaskListName(taskListToUpdate: TaskList): void { + const store = this.store; + const matchingTaskList = store.taskLists.find(taskList => taskList.id === taskListToUpdate.id); + if (matchingTaskList) { + matchingTaskList.name = taskListToUpdate.name; + this.saveStore(store); + this.disableSelectionMode(); + } + } + getAll(): TaskList[] { return this.store.taskLists ?? []; } @@ -175,4 +190,13 @@ export class TaskListService { store.selectedTaskLists = []; this.saveStore(store); } + + isThereMultipleTaskListsSelected(): boolean { + const store = this.store; + return (store.selectedTaskLists?.length ?? 0) > 1; + } + + get selectedTaskList(): TaskList { + return this._store.value?.selectedTaskLists[0]; + } } diff --git a/src/app/task-lists/rename-task-list/rename-task-list.component.html b/src/app/task-lists/rename-task-list/rename-task-list.component.html new file mode 100644 index 0000000..aee5bd2 --- /dev/null +++ b/src/app/task-lists/rename-task-list/rename-task-list.component.html @@ -0,0 +1,15 @@ +
\ No newline at end of file diff --git a/src/app/task-lists/rename-task-list/rename-task-list.component.scss b/src/app/task-lists/rename-task-list/rename-task-list.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/src/app/task-lists/rename-task-list/rename-task-list.component.ts b/src/app/task-lists/rename-task-list/rename-task-list.component.ts new file mode 100644 index 0000000..06ce6a6 --- /dev/null +++ b/src/app/task-lists/rename-task-list/rename-task-list.component.ts @@ -0,0 +1,59 @@ +import { Component, OnInit } from '@angular/core'; +import { FormBuilder, FormGroup, Validators } from '@angular/forms'; +import { MatDialogRef } from '@angular/material/dialog'; +import { MatSnackBar } from '@angular/material/snack-bar'; +import { TaskList } from 'src/app/core/entity/task-list'; +import { TaskListService } from 'src/app/core/service/task-list.service'; + +@Component({ + selector: 'app-rename-task-list', + templateUrl: './rename-task-list.component.html', + styleUrls: ['./rename-task-list.component.scss'] +}) +export class RenameTaskListComponent implements OnInit { + renameTaskListFormGroup: FormGroup = this._formBuilder.group({ + name: [undefined, Validators.required] + }); + + selectedTaskList?: TaskList; + + constructor( + private _dialogRef: MatDialogRef