modalVisibility.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* eslint no-param-reassign: 0 */
  2. import ws from "@/ws";
  3. const state = {
  4. modals: {
  5. whatIsNew: false,
  6. manageStation: false,
  7. login: false,
  8. register: false,
  9. createCommunityStation: false,
  10. requestSong: false,
  11. editPlaylist: false,
  12. createPlaylist: false,
  13. report: false,
  14. removeAccount: false,
  15. editNews: false,
  16. editUser: false,
  17. editSong: false,
  18. importAlbum: false,
  19. viewReport: false,
  20. viewPunishment: false
  21. },
  22. currentlyActive: []
  23. };
  24. const getters = {};
  25. const actions = {
  26. closeModal: ({ commit }, modal) => {
  27. if (modal === "register")
  28. lofig.get("recaptcha.enabled").then(enabled => {
  29. if (enabled) window.location.reload();
  30. });
  31. commit("closeModal", modal);
  32. },
  33. openModal: ({ commit }, modal) => {
  34. commit("openModal", modal);
  35. },
  36. closeCurrentModal: ({ commit }) => {
  37. commit("closeCurrentModal");
  38. }
  39. };
  40. const mutations = {
  41. closeModal(state, modal) {
  42. state.modals[modal] = false;
  43. if (state.currentlyActive[0] === modal) state.currentlyActive.shift();
  44. },
  45. openModal(state, modal) {
  46. state.modals[modal] = true;
  47. state.currentlyActive.unshift(modal);
  48. },
  49. closeCurrentModal(state) {
  50. // remove any websocket listeners for the modal
  51. ws.destroyModalListeners(state.currentlyActive[0]);
  52. state.modals[state.currentlyActive[0]] = false;
  53. state.currentlyActive.shift();
  54. }
  55. };
  56. export default {
  57. namespaced: true,
  58. state,
  59. getters,
  60. actions,
  61. mutations
  62. };