src/app/todo-list/todo-list.component.ts
| selector | app-todo-list |
| styleUrls | ./todo-list.component.css |
| templateUrl | ./todo-list.component.html |
Properties |
Methods |
constructor(TodosService: TodosService, AuthService: AuthService)
|
|||||||||
|
Defined in src/app/todo-list/todo-list.component.ts:21
|
|||||||||
|
Parameters :
|
| clearAll |
clearAll()
|
|
Defined in src/app/todo-list/todo-list.component.ts:64
|
|
Returns :
void
|
| deleteTodo | ||||||
deleteTodo(id: number)
|
||||||
|
Defined in src/app/todo-list/todo-list.component.ts:50
|
||||||
|
Parameters :
Returns :
void
|
| loveTodo | ||||||
loveTodo(id: number)
|
||||||
|
Defined in src/app/todo-list/todo-list.component.ts:54
|
||||||
|
Parameters :
Returns :
void
|
| ngOnDestroy |
ngOnDestroy()
|
|
Defined in src/app/todo-list/todo-list.component.ts:31
|
|
Returns :
void
|
| ngOnInit |
ngOnInit()
|
|
Defined in src/app/todo-list/todo-list.component.ts:24
|
|
Returns :
void
|
| selectByStatus | ||||||
selectByStatus(status: string)
|
||||||
|
Defined in src/app/todo-list/todo-list.component.ts:46
|
||||||
|
Parameters :
Returns :
void
|
| setValue |
setValue()
|
|
Defined in src/app/todo-list/todo-list.component.ts:36
|
|
Returns :
void
|
| toggleCompleted | ||||||
toggleCompleted(todo: Todo)
|
||||||
|
Defined in src/app/todo-list/todo-list.component.ts:59
|
||||||
|
Parameters :
Returns :
void
|
| name |
Type : string | undefined
|
|
Defined in src/app/todo-list/todo-list.component.ts:16
|
| newTodo |
Type : string
|
Default value : ''
|
|
Defined in src/app/todo-list/todo-list.component.ts:35
|
| quote |
Type : string | undefined
|
|
Defined in src/app/todo-list/todo-list.component.ts:17
|
| statusSelected$ |
Type : Observable<string>
|
Default value : this.TodosService.statusSelected
|
|
Defined in src/app/todo-list/todo-list.component.ts:21
|
| subscription |
Type : Subscription
|
|
Defined in src/app/todo-list/todo-list.component.ts:15
|
| title |
Type : string
|
Default value : 'todo-app'
|
|
Defined in src/app/todo-list/todo-list.component.ts:14
|
| todos$ |
Type : Observable<Todo[]>
|
Default value : this.TodosService.getSelectedTodos$()
|
|
Defined in src/app/todo-list/todo-list.component.ts:19
|
| todosSummary$ |
Type : Observable<TodosSummary>
|
Default value : this.TodosService.getTodosSummary$()
|
|
Defined in src/app/todo-list/todo-list.component.ts:20
|
import { Component } from '@angular/core';
import { Todo } from './Todo';
import { TodosService } from '../todos.service'
import { Observable, Subscription } from 'rxjs';
import { AuthService } from '../auth/auth.service'
import { TodosSummary } from '../todos-summary';
@Component({
selector: 'app-todo-list',
templateUrl: './todo-list.component.html',
styleUrls: ['./todo-list.component.css']
})
export class TodoListComponent {
title: string = 'todo-app';
subscription!: Subscription;
name!:string | undefined;
quote!:string | undefined;
todos$: Observable<Todo[]> = this.TodosService.getSelectedTodos$();
todosSummary$: Observable<TodosSummary> = this.TodosService.getTodosSummary$();
statusSelected$: Observable<string> =this.TodosService.statusSelected;
constructor(private TodosService: TodosService, private AuthService: AuthService) { }
ngOnInit(): void {
this.subscription = this.AuthService.LoggedUser$.subscribe(user => {
this.name = user?.name;
this.quote = user?.quote;
});
}
ngOnDestroy() {
this.subscription.unsubscribe();
}
newTodo: string = '';
setValue() {
this.TodosService.newTodo({
id: 0,
todo: this.newTodo,
completed: false,
userId: 0,
});
this.newTodo = '';
}
selectByStatus(status: string) {
this.TodosService.selectByStatus(status);
}
deleteTodo(id: number):void {
this.TodosService.deleteTodo(id);
}
loveTodo(id: number):void {
console.log(id);
this.TodosService.loveTodo(id);
}
toggleCompleted(todo: Todo):void {
// Call the service method to update the original todos array
this.TodosService.toggleCompleted(todo);
}
clearAll() {
this.TodosService.clearAll();
}
}
<div class="user-details">
<h1>{{name}}</h1>
<h3>{{quote}}</h3>
</div>
<div class="wrapper">
<div class="task-input">
<input [(ngModel)]="newTodo" (keyup.enter)="setValue()" type="text" placeholder="Add a New Task + Enter">
</div>
<div class="controls">
<div class="filters">
<span class="active" id="all" [ngClass]="{'active': (statusSelected$ | async) == 'all'}"
(click)="selectByStatus('all')">All ({{ (todosSummary$ | async)?.total }})</span>
<span id="pending" [ngClass]="{'active': (statusSelected$ | async) == 'pending'}"
(click)="selectByStatus('pending')">Pending ({{ (todosSummary$ | async)?.pending }})</span>
<span id="completed" [ngClass]="{'active': (statusSelected$ | async) == 'completed'}"
(click)="selectByStatus('completed')">
<i class="bi bi-check2-all"></i>Completed ({{ (todosSummary$ | async)?.completed }}/{{ (todosSummary$ |
async)?.total }})</span>
<span id="favorite" [ngClass]="{'active': (statusSelected$ | async) == 'favorite'}"
(click)="selectByStatus('favorite')">
<i class="bi bi-heart"></i>Favorite ({{ (todosSummary$ | async)?.favorite }})</span>
<span id="deleted" [ngClass]="{'active': (statusSelected$ | async) == 'deleted'}"
(click)="selectByStatus('deleted')">
<i class="bi bi-trash"></i>Deleted ({{ (todosSummary$ | async)?.deleted }})</span>
</div>
<button type="button" class="clear-btn" (click)="clearAll()">Clear All</button>
</div>
<ul class="task-box">
<app-todo class="task" *ngFor="let todo of todos$ | async" [id]=todo.id [todo]="todo.todo"
[favorite]="todo.favorite" [completed]="todo.completed" (toggleEvent)="toggleCompleted($event)"
(deleteEvent)="deleteTodo($event)" (loveEvent)="loveTodo($event)"></app-todo>
</ul>
</div>
./todo-list.component.css
@import "~bootstrap-icons/font/bootstrap-icons.css";
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: "Poppins", sans-serif;
}
::selection {
color: #fff;
background: #f12711;
}
.wrapper {
max-width: 50%;
background: #fff;
margin: 20px auto;
border-radius: 7px;
padding: 28px 0 30px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
}
.task-input {
position: relative;
height: 52px;
padding: 0 25px;
}
.task-input ion-icon {
position: absolute;
top: 50%;
color: #999;
font-size: 25px;
transform: translate(17px, -50%);
}
.task-input input {
height: 100%;
width: 100%;
outline: none;
font-size: 18px;
border-radius: 5px;
padding: 0 20px 0 53px;
border: 1px solid #999;
}
.task-input input:focus,
.task-input input.active {
padding-left: 52px;
border: 2px solid #f12711;
}
.task-input input::placeholder {
color: #bfbfbf;
}
.controls,
li {
display: flex;
align-items: center;
justify-content: space-between;
}
.controls {
padding: 18px 25px;
border-bottom: 1px solid #ccc;
}
.filters span {
margin: 0 8px;
font-size: 17px;
color: #444444;
cursor: pointer;
}
.filters span:first-child {
margin-left: 0;
}
.filters span.active {
color: #f12711;
}
.filters span i {
margin-right: 3px;
}
.clear-btn {
border: none;
opacity: 0.6;
outline: none;
color: #fff;
cursor: pointer;
font-size: 13px;
padding: 7px 13px;
border-radius: 4px;
letter-spacing: 0.3px;
transition: transform 0.25s ease;
background: linear-gradient(135deg, #f5af19 0%, #f12711 100%);
}
.clear-btn.active {
opacity: 0.9;
pointer-events: auto;
}
.clear-btn:hover {
opacity: 0.9;
/* transform: scale(0.93); */
}
.task-box {
margin-top: 20px;
margin-right: 5px;
padding: 0 20px 10px 25px;
}
.task-box.overflow {
overflow-y: auto;
max-height: 300px;
}
.task-box::-webkit-scrollbar {
width: 5px;
}
.task-box::-webkit-scrollbar-track {
background: #f12711;
border-radius: 25px;
}
.task-box::-webkit-scrollbar-thumb {
background: #e6e6e6;
border-radius: 25px;
}
.user-details {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 10px;
border-radius: 5px;
border: 1px solid #e6e6e6;
background-color: #eee;
-webkit-box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.2);
-moz-box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.2);
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.2);
width: 50%;
margin: 20px auto;
font-size: 100px;
font-family: Futura;
background-color: #666666;
-webkit-background-clip: text;
-moz-background-clip: text;
background-clip: text;
color: transparent;
text-shadow: rgba(245, 245, 245, 0.5) 3px 5px 1px;
}
@media (max-width: 400px) {
body {
padding: 0 10px;
}
.wrapper {
padding: 20px 0;
}
.filters span {
margin: 0 5px;
}
.task-input {
padding: 0 20px;
}
.controls {
padding: 18px 20px;
}
.task-box {
margin-top: 20px;
margin-right: 5px;
padding: 0 15px 10px 20px;
}
.task label input {
margin-top: 4px;
}
}
@media (max-width: 600px) {
.wrapper {
max-width: 90%;
}
}
@media (max-width: 800px) {
.wrapper {
max-width: 80%;
}
}