sidebars.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* eslint no-param-reassign: 0 */
  2. const state = {
  3. sidebars: {
  4. station: {
  5. songslist: false,
  6. users: false,
  7. playlist: false
  8. }
  9. },
  10. currentlyActive: {}
  11. };
  12. const getters = {};
  13. const actions = {
  14. toggleSidebar: ({ commit }, data) => {
  15. commit("toggleSidebar", data);
  16. },
  17. openSidebar: ({ commit }, data) => {
  18. commit("openSidebar", data);
  19. },
  20. closeCurrentSidebar: ({ commit }) => {
  21. commit("closeCurrentSidebar");
  22. }
  23. };
  24. const mutations = {
  25. toggleSidebar(state, data) {
  26. const { sector, sidebar } = data;
  27. if (
  28. state.currentlyActive.sidebar &&
  29. state.currentlyActive.sidebar !== sidebar
  30. ) {
  31. state.sidebars[state.currentlyActive.sector][
  32. state.currentlyActive.sidebar
  33. ] = false;
  34. state.currentlyActive = {};
  35. }
  36. state.sidebars[sector][sidebar] = !state.sidebars[sector][sidebar];
  37. if (state.sidebars[sector][sidebar])
  38. state.currentlyActive = { sector, sidebar };
  39. },
  40. openSidebar(state, data) {
  41. const { sector, sidebar } = data;
  42. state.sidebars[sector][sidebar] = true;
  43. state.currentlyActive = { sector, sidebar };
  44. },
  45. closeCurrentSidebar(state) {
  46. const { sector, sidebar } = state.currentlyActive;
  47. state.sidebars[sector][sidebar] = false;
  48. state.currentlyActive = {};
  49. }
  50. };
  51. export default {
  52. namespaced: true,
  53. state,
  54. getters,
  55. actions,
  56. mutations
  57. };