manageStation.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import { defineStore } from "pinia";
  2. export const useManageStationStore = props => {
  3. const { modalUuid } = props;
  4. return defineStore(`manageStation-${modalUuid}`, {
  5. state: () => ({
  6. stationId: null,
  7. sector: "admin",
  8. tab: "settings",
  9. station: {},
  10. stationPlaylist: { songs: [] },
  11. autofill: [],
  12. blacklist: [],
  13. songsList: [],
  14. stationPaused: true,
  15. currentSong: {}
  16. }),
  17. actions: {
  18. init({ stationId, sector }) {
  19. this.stationId = stationId;
  20. if (sector) this.sector = sector;
  21. },
  22. showTab(tab) {
  23. this.tab = tab;
  24. },
  25. editStation(station) {
  26. this.station = JSON.parse(JSON.stringify(station));
  27. },
  28. setAutofillPlaylists(autofillPlaylists) {
  29. this.autofill = JSON.parse(JSON.stringify(autofillPlaylists));
  30. },
  31. setBlacklist(blacklist) {
  32. this.blacklist = JSON.parse(JSON.stringify(blacklist));
  33. },
  34. clearStation() {
  35. this.station = {};
  36. this.stationPlaylist = { songs: [] };
  37. this.autofill = [];
  38. this.blacklist = [];
  39. this.songsList = [];
  40. this.stationPaused = true;
  41. this.currentSong = {};
  42. },
  43. updateSongsList(songsList) {
  44. this.songsList = songsList;
  45. },
  46. updateStationPlaylist(stationPlaylist) {
  47. this.stationPlaylist = stationPlaylist;
  48. },
  49. repositionSongInList(song) {
  50. if (
  51. this.songsList[song.newIndex] &&
  52. this.songsList[song.newIndex].youtubeId === song.youtubeId
  53. )
  54. return;
  55. this.songsList.splice(
  56. song.newIndex,
  57. 0,
  58. this.songsList.splice(song.oldIndex, 1)[0]
  59. );
  60. },
  61. updateStationPaused(stationPaused) {
  62. this.stationPaused = stationPaused;
  63. },
  64. updateCurrentSong(currentSong) {
  65. this.currentSong = currentSong;
  66. },
  67. updateStation(station) {
  68. this.station = { ...this.station, ...station };
  69. },
  70. updateIsFavorited(isFavorited) {
  71. this.station.isFavorited = isFavorited;
  72. },
  73. hasPermission(permission) {
  74. return !!(
  75. this.station.permissions &&
  76. this.station.permissions[permission]
  77. );
  78. }
  79. }
  80. })();
  81. };