import { queryClient } from 'src/config/react-query';
import {
  newsKeys,
  addArticleNotification,
} from 'src/pages/dashboard/news/queries';
import { newsRoutes } from 'src/pages/dashboard/news/routes';
import { clearNewsNotifications } from 'src/services/news';

export const addArticle = () => {
  if (window.location.pathname !== newsRoutes.news()) {
    addArticleNotification();
  } else {
    clearNewsNotifications();
    queryClient.invalidateQueries(newsKeys.list());
  }
};

export const updateArticle = () => {
  queryClient.invalidateQueries(newsKeys.notifications.module());
  queryClient.invalidateQueries(newsKeys.topics());
  queryClient.invalidateQueries(newsKeys.list());
};
