Vyachowski/frontend-project-11

View on GitHub
src/app/controller/controllers/viewButtonController.js

Summary

Maintainability
A
0 mins
Test Coverage
const viewButtonController = (e, watchedState) => {
  const dataIdValue = e.target.getAttribute('data-id');

  if (!watchedState.uiState.viewedPosts.includes(dataIdValue)) {
    watchedState.uiState.viewedPosts.unshift(dataIdValue);
  }

  const { title, description, link } = watchedState.posts
    .filter(({ id }) => dataIdValue === id)
    .at(0);

  watchedState.uiState.activePost = { title, description, link };
};

export default viewButtonController;