modalVisibility.js 1.3 KB

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