Skip to content

Commit

Permalink
removing logic from leaf component (ThoughtComponent)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernandomn committed Dec 27, 2023
1 parent 681e11c commit f2fdc0c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ export class ListThoughtsComponent implements OnInit, OnDestroy {
}

onFavoriteUpdated(thought: Thought): void {
if (this.isListingFavorites && !thought.favorite) {
this.listThoughts.splice(this.listThoughts.indexOf(thought), 1);
}
this.thoughtService.updateFavoriteThought(thought).subscribe(() => {
if (this.isListingFavorites && !thought.favorite) {
this.listThoughts.splice(this.listThoughts.indexOf(thought), 1);
}
});
}

private resetSearch() {
Expand Down
7 changes: 2 additions & 5 deletions src/app/components/thoughts/thought/thought.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Component, EventEmitter, Input, Output } from '@angular/core';
import { Thought } from 'src/app/interfaces/thoughts';
import { ThoughtsService } from 'src/app/services/thoughts.service';

@Component({
selector: 'app-thought',
Expand All @@ -18,7 +17,7 @@ export class ThoughtComponent {

@Output() favoriteUpdated = new EventEmitter();

constructor(private thoughtService: ThoughtsService) {}
constructor() {}

thoughtLength(): string {
return this.thought.content && this.thought.content.length >= 256
Expand All @@ -31,8 +30,6 @@ export class ThoughtComponent {
}

updateFavorite(): void {
this.thoughtService
.updateFavoriteThought(this.thought)
.subscribe(() => this.favoriteUpdated.emit(this.thought));
this.favoriteUpdated.emit(this.thought);
}
}

0 comments on commit f2fdc0c

Please sign in to comment.