-
Notifications
You must be signed in to change notification settings - Fork 305
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
421 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,29 @@ | ||
<!-- This footer should be hidden by default and shown when there are todos --> | ||
<footer class="footer"> | ||
<!-- This should be `0 items left` by default --> | ||
<span class="todo-count"><strong>0</strong> item left</span> | ||
<span class="todo-count"> | ||
<strong>{{totalElementsPending()}}</strong> | ||
<span > | ||
{{pluralItem()}} left | ||
</span> | ||
|
||
|
||
|
||
</span> | ||
<!-- Remove this if you don't implement routing --> | ||
<ul class="filters"> | ||
<li> | ||
<a routerLink="/" class="selected">All</a> | ||
<a routerLink="" routerLinkActive="selected" [routerLinkActiveOptions]="{ exact: true }">All</a> | ||
</li> | ||
<li> | ||
<a routerLink="/pending">Pending</a> | ||
<a routerLink="/pending" routerLinkActive="selected">Pending</a> | ||
</li> | ||
<li> | ||
<a routerLink="/completed">Completed</a> | ||
<a routerLink="/completed" routerLinkActive="selected">Completed</a> | ||
</li> | ||
</ul> | ||
<!-- Hidden if no completed items are left ↓ --> | ||
<button class="clear-completed">Clear completed</button> | ||
@if(numberOftasksCompleted() > 0){ | ||
<button class="clear-completed" (click)="clearAllTasks()">Clear completed</button> | ||
} | ||
|
||
</footer> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,27 @@ | ||
import { Component } from '@angular/core'; | ||
import { Component, Signal, computed, inject, input } from '@angular/core'; | ||
import { CommonModule } from '@angular/common'; | ||
import { TodoService } from 'src/app/services/todo-service'; | ||
import { RouterLink, RouterLinkActive } from '@angular/router'; | ||
|
||
@Component({ | ||
selector: 'app-footer', | ||
standalone: true, | ||
imports: [CommonModule], | ||
imports: [CommonModule, RouterLink, RouterLinkActive], | ||
templateUrl: './footer.component.html', | ||
}) | ||
export class FooterComponent { | ||
private todosSevice = inject(TodoService); | ||
|
||
public numberOftasksCompleted: Signal<number> = computed(() => this.todosSevice.todos().filter((task) => task.completed).length); | ||
|
||
|
||
public totalElementsPending = input.required<number>(); | ||
|
||
public pluralItem = computed(() => | ||
this.totalElementsPending() > 1 ? 'items' : 'item' | ||
); | ||
|
||
public clearAllTasks(): void { | ||
this.todosSevice.clearAllCompleteTasks(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
export interface TaskTodo { | ||
id:string, | ||
title:string, | ||
completed:boolean | ||
completed:boolean, | ||
edit:boolean | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
@for (task of tasks(); track task.id) { | ||
<li [ngClass]="{ completed: task.completed, editing: task.edit }"> | ||
<div class="view"> | ||
<input | ||
class="toggle" | ||
[checked]="task.completed" | ||
(click)="toogleTask(task.id)" | ||
type="checkbox" | ||
/> | ||
<label (dblclick)="openEditMode(task.id)">{{ task.title }}</label> | ||
<button class="destroy" (click)="removeTask(task.id)"></button> | ||
</div> | ||
<input class="edit" | ||
(input)="changeInputValue($event)" | ||
(keydown.enter)="editTask(task.id)" | ||
(keydown.esc)="closeEditMode(task.id)" | ||
[value]="task.title" /> | ||
</li> | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { CommonModule } from '@angular/common'; | ||
import { Component, Signal, computed, inject, signal } from '@angular/core'; | ||
import { TaskTodo } from 'src/app/interfaces/task'; | ||
import { TodoService } from 'src/app/services/todo-service'; | ||
|
||
@Component({ | ||
selector: 'app-all-tasks', | ||
standalone: true, | ||
imports: [CommonModule], | ||
templateUrl: './all-tasks.component.html', | ||
|
||
}) | ||
export class AllTasksComponent { | ||
|
||
private todoService = inject(TodoService); | ||
|
||
public inputEditValue = signal(''); | ||
|
||
public tasks: Signal<TaskTodo[]> = computed(() => this.todoService.todos()); | ||
|
||
public numberOftasksPending: Signal<number> = computed( | ||
() => this.todoService.todos().filter((task) => !task.completed).length | ||
); | ||
|
||
constructor() {} | ||
|
||
ngOnInit(): void {} | ||
|
||
public toogleTask(taskId: string): void { | ||
this.todoService.toogleTask(taskId); | ||
} | ||
|
||
public removeTask(taskId: string): void { | ||
this.todoService.removeTask(taskId); | ||
} | ||
|
||
public openEditMode(taskId: string) { | ||
this.todoService.openEditModeByIdTask(taskId); | ||
} | ||
|
||
public closeEditMode(taskId: string) { | ||
this.todoService.closeEditModeByIdTask(taskId); | ||
} | ||
|
||
public changeInputValue(event:Event){ | ||
const newValue = (event.target as HTMLInputElement).value; | ||
|
||
this.inputEditValue.set(newValue); | ||
} | ||
|
||
public editTask(taskId: string) { | ||
|
||
this.todoService.editTaskTitle(taskId, this.inputEditValue().trim()); | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
src/app/pages/home/complete-tasks/complete-tasks.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
@for (task of todosCompleted(); track task.id) { | ||
<li [ngClass]="{ completed: task.completed, editing: task.edit }"> | ||
<div class="view"> | ||
<input | ||
class="toggle" | ||
[checked]="task.completed" | ||
(click)="toogleTask(task.id)" | ||
type="checkbox" | ||
/> | ||
<label (dblclick)="openEditMode(task.id)">{{ task.title }}</label> | ||
<button class="destroy" (click)="removeTask(task.id)"></button> | ||
</div> | ||
<input class="edit" | ||
(input)="changeInputValue($event)" | ||
(keydown.enter)="editTask(task.id)" | ||
(keydown.esc)="closeEditMode(task.id)" | ||
[value]="task.title" /> | ||
</li> | ||
} |
46 changes: 46 additions & 0 deletions
46
src/app/pages/home/complete-tasks/complete-tasks.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { CommonModule } from '@angular/common'; | ||
import { Component, computed, inject, signal } from '@angular/core'; | ||
import { TodoService } from 'src/app/services/todo-service'; | ||
|
||
@Component({ | ||
selector: 'app-complete-tasks', | ||
standalone: true, | ||
imports: [CommonModule], | ||
templateUrl: './complete-tasks.component.html', | ||
}) | ||
export class CompleteTasksComponent { | ||
|
||
|
||
private todosService = inject(TodoService); | ||
|
||
public inputEditValue = signal(''); | ||
|
||
public todosCompleted = computed(() => this.todosService.todosCompleted()); | ||
|
||
public toogleTask(taskId: string): void { | ||
this.todosService.toogleTask(taskId); | ||
} | ||
|
||
public removeTask(taskId: string): void { | ||
this.todosService.removeTask(taskId); | ||
} | ||
|
||
public openEditMode(taskId: string) { | ||
this.todosService.openEditModeByIdTask(taskId); | ||
} | ||
|
||
public closeEditMode(taskId: string) { | ||
this.todosService.closeEditModeByIdTask(taskId); | ||
} | ||
|
||
public changeInputValue(event: Event) { | ||
const newValue = (event.target as HTMLInputElement).value; | ||
|
||
this.inputEditValue.set(newValue); | ||
} | ||
|
||
public editTask(taskId: string) { | ||
this.todosService.editTaskTitle(taskId, this.inputEditValue().trim()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.