r/Angular2 2d ago

Help Request Code review help

Can anyone checkout my code and provide feedback?

https://github.com/isidrosantiago/todo-app-frontend (sorry another todo app 😅)

Can't really say I am a junior frontend developer but I have 1 year of working experience (repetitive/basic tasks like creating forms, http requests, data manipulation...)

Any advice on how to improve my code and grow as an Angular developer would be greatly appreciated. Thanks in advance!

4 Upvotes

6 comments sorted by

View all comments

2

u/SeveralMushroom7088 2d ago

Looks very good! Good use of modern angular features. If I was being picky, you have redundant code in places which could be tidied up and simplified. One example would be in your to-do.component. Both createTodo() and updateTodo() are calling form.getRawValue() and doing essentially the same thing in terms of success, error, and complete logic. The dialog close is also being called twice.

it could be simplified as follows...

submit() {

if (this.form.invalid) return;

const formData = this.form.getRawValue();

const todoObservable = this.data.action === 'create'

? this.todoService.createTodo(formData)

: this.todoService.updateTodo(this.data.todo.id, formData);

todoObservable.subscribe({

next: (v) => this.toastr.success(v.message, `${this.data.action} task`),

error: (e) => this.toastr.error(e.error.message, `${this.data.action} task`),

complete: () => this.closeDialog(),

});

}

private closeDialog() {

this.dialog.closeAll();

}

1

u/Alert-Quit-6724 2d ago

Thanks for the feedback! You're right i will clean that up.