comments.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import CommentsService from "@/services/CommentsService";
  2. import AuthorizedUserService from "@/services/AuthorizedUserService";
  3. export const state = () => ({
  4. lastCommentsList: [],
  5. commentsList: []
  6. });
  7. export const mutations = {
  8. SET_LAST_COMMENTS_LIST(state, lastCommentsList) {
  9. state.lastCommentsList = lastCommentsList;
  10. },
  11. SET_COMMENTS_LIST(state, commentsList) {
  12. state.commentsList = commentsList
  13. }
  14. };
  15. export const actions = {
  16. getLastCommentsList({ commit }) {
  17. return CommentsService.getLastCommentsList()
  18. .then((lastCommentsList) => {
  19. commit("SET_LAST_COMMENTS_LIST", lastCommentsList)
  20. return lastCommentsList
  21. })
  22. },
  23. getCommentsList({commit}, pullId, pageNumber) {
  24. return CommentsService.getCommentsList(pullId, pageNumber)
  25. .then((commentsList) => {
  26. commit("SET_COMMENTS_LIST", commentsList)
  27. return commentsList
  28. })
  29. },
  30. createComment({ commit }, comment, token) {
  31. console.log(comment, token)
  32. return AuthorizedUserService.createComment(comment, token)
  33. }
  34. };
  35. export const getters = {
  36. lastCommentsList: state => state.lastCommentsList,
  37. commentsList: state => state.commentsList
  38. };
  39. export default {
  40. namespaced: true,
  41. state,
  42. getters,
  43. actions,
  44. mutations
  45. }