From 587b979ff212b9beadcc5cc75677fc3208809908 Mon Sep 17 00:00:00 2001 From: ExostFlash Date: Wed, 26 Nov 2025 15:33:26 +0100 Subject: [PATCH] Loazing --- src/app/app.routes.ts | 12 +++- .../component/header/header.component.html | 1 + src/app/component/home/home.component.html | 20 +------ src/app/component/home/home.component.ts | 42 ++------------ .../tasks-page/tasks-page.component.css | 18 ++++++ .../tasks-page/tasks-page.component.html | 25 ++++++++ .../tasks-page/tasks-page.component.spec.ts | 23 ++++++++ .../tasks-page/tasks-page.component.ts | 58 +++++++++++++++++++ src/app/module/about/about.component.css | 0 src/app/module/about/about.component.html | 1 + src/app/module/about/about.component.spec.ts | 23 ++++++++ src/app/module/about/about.component.ts | 7 +++ src/app/module/task/task.component.css | 0 src/app/module/task/task.component.html | 1 + src/app/module/task/task.component.spec.ts | 23 ++++++++ src/app/module/task/task.component.ts | 7 +++ src/app/service/task.service.ts | 5 ++ 17 files changed, 208 insertions(+), 58 deletions(-) create mode 100644 src/app/component/tasks-page/tasks-page.component.css create mode 100644 src/app/component/tasks-page/tasks-page.component.html create mode 100644 src/app/component/tasks-page/tasks-page.component.spec.ts create mode 100644 src/app/component/tasks-page/tasks-page.component.ts create mode 100644 src/app/module/about/about.component.css create mode 100644 src/app/module/about/about.component.html create mode 100644 src/app/module/about/about.component.spec.ts create mode 100644 src/app/module/about/about.component.ts create mode 100644 src/app/module/task/task.component.css create mode 100644 src/app/module/task/task.component.html create mode 100644 src/app/module/task/task.component.spec.ts create mode 100644 src/app/module/task/task.component.ts diff --git a/src/app/app.routes.ts b/src/app/app.routes.ts index cdc1771..428c0e4 100644 --- a/src/app/app.routes.ts +++ b/src/app/app.routes.ts @@ -1,9 +1,17 @@ import { Routes } from '@angular/router'; import { HomeComponent } from './component/home/home.component'; -import { AboutComponent } from './component/about/about.component'; export const routes: Routes = [ { path: '', component: HomeComponent }, { path: 'home', component: HomeComponent }, - { path: 'about', component: AboutComponent } + + { + path: 'tasks', + loadChildren: () => import('./module/task/task.component').then(m => m.TASKS_ROUTES) + }, + + { + path: 'about', + loadChildren: () => import('./module/about/about.component').then(m => m.ABOUT_ROUTES) + } ]; diff --git a/src/app/component/header/header.component.html b/src/app/component/header/header.component.html index 13a359d..6e6e073 100644 --- a/src/app/component/header/header.component.html +++ b/src/app/component/header/header.component.html @@ -2,6 +2,7 @@ diff --git a/src/app/component/home/home.component.html b/src/app/component/home/home.component.html index f5ae9c5..07d2b70 100644 --- a/src/app/component/home/home.component.html +++ b/src/app/component/home/home.component.html @@ -1,19 +1 @@ -

Home works!

- -

Task List

-@if (tasks$ | async; as tasks) { - -} @else { -

Loading tasks...

-} - -

Elapsed time: {{ elapsedClock }}

- - - \ No newline at end of file +

Home works!

diff --git a/src/app/component/home/home.component.ts b/src/app/component/home/home.component.ts index 84c2a96..891e67d 100644 --- a/src/app/component/home/home.component.ts +++ b/src/app/component/home/home.component.ts @@ -1,45 +1,13 @@ - -import { Component, inject } from '@angular/core'; -import { CommonModule, AsyncPipe } from '@angular/common'; -import { TaskService } from '../../service/task.service'; +import { Component } from '@angular/core'; +import { CommonModule } from '@angular/common'; @Component({ selector: 'app-home', - imports: [CommonModule, AsyncPipe], + standalone: true, + imports: [CommonModule], templateUrl: './home.component.html', styleUrl: './home.component.css' }) export class HomeComponent { - protected count = 0; - private intervalId: any; - public elapsedClock: string = ''; - - private taskService = inject(TaskService); - tasks$ = this.taskService.tasks$; - - ngOnInit() { - this.updateElapsedClock(); - this.intervalId = setInterval(() => { - this.count++; - this.updateElapsedClock(); - }, 500); - } - - ngOnDestroy() { - if (this.intervalId) { - clearInterval(this.intervalId); - } - } - - private updateElapsedClock() { - const totalSeconds = Math.floor(this.count / 2); - const h = String(Math.floor(totalSeconds / 3600)).padStart(2, '0'); - const m = String(Math.floor((totalSeconds % 3600) / 60)).padStart(2, '0'); - const s = String(totalSeconds % 60).padStart(2, '0'); - this.elapsedClock = `${h}:${m}:${s}`; - } - - addTask(title: string) { - this.taskService.addTask(title); - } + } \ No newline at end of file diff --git a/src/app/component/tasks-page/tasks-page.component.css b/src/app/component/tasks-page/tasks-page.component.css new file mode 100644 index 0000000..ee8b85f --- /dev/null +++ b/src/app/component/tasks-page/tasks-page.component.css @@ -0,0 +1,18 @@ +.trash-btn { + background: none; + border: none; + cursor: pointer; + color: #c00; + font-size: 1.1em; + padding: 0.1em 0.3em; + border-radius: 4px; + transition: background 0.2s, color 0.2s; +} +.trash-btn:hover { + background: #ffeaea; + color: #fff; +} +.trash-btn:hover svg { + color: #fff; + fill: #fff; +} diff --git a/src/app/component/tasks-page/tasks-page.component.html b/src/app/component/tasks-page/tasks-page.component.html new file mode 100644 index 0000000..d9690c3 --- /dev/null +++ b/src/app/component/tasks-page/tasks-page.component.html @@ -0,0 +1,25 @@ +

tasks-page works!

+ +

Task List

+@if (tasks$ | async; as tasks) { + +} @else { +

Loading tasks...

+} + +

Elapsed time: {{ elapsedClock }}

+ + +
+ + +
\ No newline at end of file diff --git a/src/app/component/tasks-page/tasks-page.component.spec.ts b/src/app/component/tasks-page/tasks-page.component.spec.ts new file mode 100644 index 0000000..13b4888 --- /dev/null +++ b/src/app/component/tasks-page/tasks-page.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { TasksPageComponent } from './tasks-page.component'; + +describe('TasksPageComponent', () => { + let component: TasksPageComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [TasksPageComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(TasksPageComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/component/tasks-page/tasks-page.component.ts b/src/app/component/tasks-page/tasks-page.component.ts new file mode 100644 index 0000000..839672e --- /dev/null +++ b/src/app/component/tasks-page/tasks-page.component.ts @@ -0,0 +1,58 @@ +import { Component, inject } from '@angular/core'; +import { CommonModule, AsyncPipe } from '@angular/common'; +import { TaskService } from '../../service/task.service'; + +@Component({ + selector: 'app-tasks-page', + imports: [CommonModule, AsyncPipe], + templateUrl: './tasks-page.component.html', + styleUrl: './tasks-page.component.css', +}) +export class TasksPageComponent { + protected count = 0; + private intervalId: any; + public elapsedClock: string = ''; + + private taskService = inject(TaskService); + tasks$ = this.taskService.tasks$; + + ngOnInit() { + this.updateElapsedClock(); + this.intervalId = setInterval(() => { + this.count++; + this.updateElapsedClock(); + }, 500); + } + + ngOnDestroy() { + if (this.intervalId) { + clearInterval(this.intervalId); + } + } + + private updateElapsedClock() { + const totalSeconds = Math.floor(this.count / 2); + const h = String(Math.floor(totalSeconds / 3600)).padStart(2, '0'); + const m = String(Math.floor((totalSeconds % 3600) / 60)).padStart(2, '0'); + const s = String(totalSeconds % 60).padStart(2, '0'); + this.elapsedClock = `${h}:${m}:${s}`; + } + + removeTask(id: number) { + this.taskService.removeTask(id); + } + + onAddTaskSubmit(event: SubmitEvent) { + event.preventDefault(); + const form = event.target as HTMLFormElement; + const input = form.elements.namedItem('taskTitle') as HTMLInputElement | null; + if (input && input.value.trim()) { + this.addTask(input.value.trim()); + form.reset(); + } + } + + addTask(title: string) { + this.taskService.addTask(title); + } +} diff --git a/src/app/module/about/about.component.css b/src/app/module/about/about.component.css new file mode 100644 index 0000000..e69de29 diff --git a/src/app/module/about/about.component.html b/src/app/module/about/about.component.html new file mode 100644 index 0000000..6094aa9 --- /dev/null +++ b/src/app/module/about/about.component.html @@ -0,0 +1 @@ +

about works!

diff --git a/src/app/module/about/about.component.spec.ts b/src/app/module/about/about.component.spec.ts new file mode 100644 index 0000000..74d6d9e --- /dev/null +++ b/src/app/module/about/about.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { AboutComponent } from './about.component'; + +describe('AboutComponent', () => { + let component: AboutComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [AboutComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(AboutComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/module/about/about.component.ts b/src/app/module/about/about.component.ts new file mode 100644 index 0000000..e8ccf9e --- /dev/null +++ b/src/app/module/about/about.component.ts @@ -0,0 +1,7 @@ +import { Routes } from '@angular/router'; + +import { AboutComponent } from '../../component/about/about.component'; + +export const ABOUT_ROUTES: Routes = [ + { path: '', component: AboutComponent }, +]; \ No newline at end of file diff --git a/src/app/module/task/task.component.css b/src/app/module/task/task.component.css new file mode 100644 index 0000000..e69de29 diff --git a/src/app/module/task/task.component.html b/src/app/module/task/task.component.html new file mode 100644 index 0000000..0c8a790 --- /dev/null +++ b/src/app/module/task/task.component.html @@ -0,0 +1 @@ +

task works!

diff --git a/src/app/module/task/task.component.spec.ts b/src/app/module/task/task.component.spec.ts new file mode 100644 index 0000000..13dacb1 --- /dev/null +++ b/src/app/module/task/task.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { TaskComponent } from './task.component'; + +describe('TaskComponent', () => { + let component: TaskComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [TaskComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(TaskComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/module/task/task.component.ts b/src/app/module/task/task.component.ts new file mode 100644 index 0000000..2f966db --- /dev/null +++ b/src/app/module/task/task.component.ts @@ -0,0 +1,7 @@ +import { Routes } from '@angular/router'; + +import { TasksPageComponent } from '../../component/tasks-page/tasks-page.component'; + +export const TASKS_ROUTES: Routes = [ + { path: '', component: TasksPageComponent }, +]; \ No newline at end of file diff --git a/src/app/service/task.service.ts b/src/app/service/task.service.ts index f92ff99..9dd166e 100644 --- a/src/app/service/task.service.ts +++ b/src/app/service/task.service.ts @@ -25,4 +25,9 @@ export class TaskService { this.tasks.push(newTask); this.tasksSubject.next([...this.tasks]); } + + removeTask(id: number) { + this.tasks = this.tasks.filter(task => task.id !== id); + this.tasksSubject.next([...this.tasks]); + } }