From 986d34ab12d9721278b3d4b52f82a04daef92c9f Mon Sep 17 00:00:00 2001 From: Gal Podlipnik Date: Mon, 14 Jul 2025 19:40:13 +0200 Subject: [PATCH] update --- .github/instructions/angular.instructions.md | 69 ++++ client/libs/shared/api/src/lib/types.ts | 6 +- .../shared/navbar/src/lib/navbar.component.ts | 20 +- client/libs/web/tasks/src/index.ts | 3 +- .../src/lib/add-task-dialog.component.ts | 192 ++++++++- .../web/tasks/src/lib/task-form.component.ts | 92 +++-- .../web/tasks/src/lib/task-list.component.ts | 294 +++++++++----- .../users/src/lib/user-details.component.ts | 373 +++++++++++++++--- .../web/users/src/lib/user-list.component.ts | 187 +++++---- server/src/controllers/tasks.ts | 3 +- server/src/db/local.db | Bin 45056 -> 45056 bytes server/src/db/seed.ts | 1 - 12 files changed, 950 insertions(+), 290 deletions(-) create mode 100644 .github/instructions/angular.instructions.md diff --git a/.github/instructions/angular.instructions.md b/.github/instructions/angular.instructions.md new file mode 100644 index 0000000..1909346 --- /dev/null +++ b/.github/instructions/angular.instructions.md @@ -0,0 +1,69 @@ +--- +applyTo: "**" +--- + +You are an expert in TypeScript, Angular, and scalable web application development. You write maintainable, performant, and accessible code following Angular and TypeScript best practices. You use the features and best practices according to the latest Angular version. You write code that is easy to read, understand and maintain. You avoid unnecessary complexity and strive for simplicity in your code. You use the latest features of TypeScript and Angular to write clean, efficient and scalable code. + +## TypeScript Best Practices + +- Use strict type checking +- Prefer type interfaces when the type is obvious +- Avoid the `any` type; use `unknown` when type is uncertain +- Use `readonly` # for private class fields +- Use `const` for constants and `let` for variables that may change +- Use the following syntax for `enums`: + +```typescript +export enum WeekDayEnum = { + MONDAY: 'Monday', + TUESDAY: 'Tuesday', + WEDNESDAY: 'Wednesday', + THURSDAY: 'Thursday', + FRIDAY: 'Friday', + SATURDAY: 'Saturday', + SUNDAY: 'Sunday' +}; + +export type WeekDay = (typeof WeekDayEnum)[keyof typeof WeekDayEnum]; +``` + +- Add all types and interfaces to a `.types.ts` file + +## Angular Best Practices + +- Always use standalone components over NgModules +- Don't use explicit `standalone: true` (it is implied by default) +- Use signals for state management +- Implement lazy loading for feature routes +- Use `NgOptimizedImage` for all static images + +## Components + +- Keep components small and focused on a single responsibility +- Use `input()` and `output()` functions instead of decorators +- Use `computed()` for derived state +- Set `changeDetection: ChangeDetectionStrategy.OnPush` in `@Component` decorator +- Prefer inline templates for small components +- Prefer Reactive forms instead of Template-driven ones +- Do NOT use `ngClass`, use `class` bindings instead +- Do NOT use `ngStyle`, use `style` bindings instead + +## State Management + +- Use signals for local component state +- Use `computed()` for derived state +- Keep state transformations pure and predictable + +## Templates + +- Keep templates simple and avoid complex logic +- Use Signals for your template bindings whenever possible +- Use untagged template literals in the template instead of concatenation +- Use native control flow (`@if`, `@for`, `@switch`) instead of `*ngIf`, `*ngFor`, and `*ngSwitch` +- Use the async pipe to handle Observables + +## Services + +- Design services around a single responsibility +- Use the `providedIn: 'root'` option for singleton services +- Use the `inject()` function instead of constructor injection diff --git a/client/libs/shared/api/src/lib/types.ts b/client/libs/shared/api/src/lib/types.ts index 55c2d6a..ee8004c 100644 --- a/client/libs/shared/api/src/lib/types.ts +++ b/client/libs/shared/api/src/lib/types.ts @@ -9,7 +9,7 @@ export type Task = { id: number; title: string; description?: string; - user_id: number; + userId: number; timestamp?: string; }; @@ -21,8 +21,8 @@ export type TaskResponse = { export type Comment = { id: number; content: string; - task_id: number; - user_id: number; + taskId: number; + userId: number; timestamp?: string; }; diff --git a/client/libs/shared/navbar/src/lib/navbar.component.ts b/client/libs/shared/navbar/src/lib/navbar.component.ts index a902321..78e7d7f 100644 --- a/client/libs/shared/navbar/src/lib/navbar.component.ts +++ b/client/libs/shared/navbar/src/lib/navbar.component.ts @@ -1,10 +1,13 @@ -import { Component } from '@angular/core'; +import { ChangeDetectionStrategy, Component } from '@angular/core'; +import { MatButtonModule } from '@angular/material/button'; import { MatIcon } from '@angular/material/icon'; import { MatToolbarModule } from '@angular/material/toolbar'; +import { RouterModule } from '@angular/router'; @Component({ selector: 'lib-navbar', - imports: [MatToolbarModule, MatIcon], + imports: [MatToolbarModule, MatIcon, MatButtonModule, RouterModule], + changeDetection: ChangeDetectionStrategy.OnPush, template: `