Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/app/core/models/user.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ export class User {
public subscriptions?: string[],
public readFeeds?: string[],
public savedFeeds?: string[],
public likedFeeds?: string[],
) {}
}
17 changes: 9 additions & 8 deletions src/app/core/services/feed.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,16 @@ export class FeedService {

public mapInUserResource(feeds: Feed[] | Feed): Feed[] | Feed {
const userActive = this.authService.getUserActive();
if(userActive) {
const { savedFeeds } = userActive;
if(Array.isArray(feeds)) {
feeds.map(feed => feed.inUser = savedFeeds?.includes(feed._id));
} else {
feeds.inUser = savedFeeds?.includes(feeds._id);
}
if (userActive) {
const { savedFeeds, likedFeeds } = userActive;
const mapFeed = (feed: Feed): Feed => {
feed.inUser = savedFeeds?.includes(feed._id) || false;
feed.liked = likedFeeds?.includes(feed._id) || false;
feed.likes = feed.likes ?? 0;
return feed;
};
Array.isArray(feeds) ? feeds.forEach(mapFeed) : feeds = mapFeed(feeds);
}
return feeds;
}

}
3 changes: 2 additions & 1 deletion src/app/shared/news-container/news-container.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ export class NewsContainerComponent implements OnInit {
}
if(option === 'liked' && feed._id === idFeed) {
feed.liked = !feed.liked;
feed.liked ? feed.likes++ : feed.likes--;
feed.likes += feed.liked ? 1 : -1;
}
return feed;
});
});
}
Expand Down
Loading