station.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. import { defineStore } from "pinia";
  2. import { Playlist } from "@/types/playlist";
  3. import { Song, CurrentSong } from "@/types/song";
  4. import { Station } from "@/types/station";
  5. import { User } from "@/types/user";
  6. import ws from "@/ws";
  7. export const useStationStore = defineStore("station", {
  8. state: () => ({
  9. station: <Station>{},
  10. autoRequest: <Playlist[]>[],
  11. autoRequestLock: false,
  12. editing: {},
  13. userCount: 0,
  14. users: {
  15. loggedIn: <User[]>[],
  16. loggedOut: <User[]>[]
  17. },
  18. currentSong: <CurrentSong | undefined>{},
  19. nextSong: <Song | undefined | null>null,
  20. songsList: <Song[]>[],
  21. stationPaused: true,
  22. localPaused: false,
  23. noSong: true,
  24. autofill: <Playlist[]>[],
  25. blacklist: <Playlist[]>[],
  26. mediaModalPlayingAudio: false,
  27. permissions: {}
  28. }),
  29. actions: {
  30. joinStation(station) {
  31. this.station = { ...station };
  32. },
  33. leaveStation() {
  34. this.station = {};
  35. this.autoRequest = [];
  36. this.autoRequestLock = false;
  37. this.editing = {};
  38. this.userCount = 0;
  39. this.users = {
  40. loggedIn: [],
  41. loggedOut: []
  42. };
  43. this.currentSong = {};
  44. this.nextSong = null;
  45. this.songsList = [];
  46. this.stationPaused = true;
  47. this.localPaused = false;
  48. this.noSong = true;
  49. this.autofill = [];
  50. this.blacklist = [];
  51. this.permissions = {};
  52. },
  53. editStation(station) {
  54. this.editing = { ...station };
  55. },
  56. updateStation(station) {
  57. this.station = { ...this.station, ...station };
  58. },
  59. updateUserCount(userCount) {
  60. this.userCount = userCount;
  61. },
  62. updateUsers(users) {
  63. this.users = users;
  64. },
  65. updateCurrentSong(currentSong) {
  66. this.currentSong = currentSong;
  67. },
  68. updateNextSong(nextSong) {
  69. this.nextSong = nextSong;
  70. },
  71. updateSongsList(songsList) {
  72. this.songsList = songsList;
  73. },
  74. repositionSongInList(song) {
  75. if (
  76. this.songsList[song.newIndex] &&
  77. this.songsList[song.newIndex].youtubeId === song.youtubeId
  78. )
  79. return;
  80. this.songsList.splice(
  81. song.newIndex,
  82. 0,
  83. this.songsList.splice(song.oldIndex, 1)[0]
  84. );
  85. },
  86. updateStationPaused(stationPaused) {
  87. this.stationPaused = stationPaused;
  88. },
  89. updateLocalPaused(localPaused) {
  90. this.localPaused = localPaused;
  91. },
  92. updateNoSong(noSong) {
  93. this.noSong = noSong;
  94. },
  95. updateAutoRequest(playlists) {
  96. this.autoRequest = playlists;
  97. },
  98. updateAutoRequestLock(lock) {
  99. this.autoRequestLock = lock;
  100. },
  101. updateIfStationIsFavorited(isFavorited) {
  102. this.station.isFavorited = isFavorited;
  103. },
  104. setAutofillPlaylists(autofillPlaylists) {
  105. this.autofill = JSON.parse(JSON.stringify(autofillPlaylists));
  106. },
  107. setBlacklist(blacklist) {
  108. this.blacklist = JSON.parse(JSON.stringify(blacklist));
  109. },
  110. updateCurrentSongRatings(songRatings) {
  111. this.currentSong.likes = songRatings.likes;
  112. this.currentSong.dislikes = songRatings.dislikes;
  113. },
  114. updateOwnCurrentSongRatings(ownSongRatings) {
  115. this.currentSong.liked = ownSongRatings.liked;
  116. this.currentSong.disliked = ownSongRatings.disliked;
  117. },
  118. updateCurrentSongSkipVotes({ skipVotes, skipVotesCurrent }) {
  119. this.currentSong.skipVotes = skipVotes;
  120. if (skipVotesCurrent !== null)
  121. this.currentSong.skipVotesCurrent = skipVotesCurrent;
  122. },
  123. addPlaylistToAutoRequest(playlist) {
  124. this.autoRequest.push(playlist);
  125. },
  126. removePlaylistFromAutoRequest(playlistId) {
  127. this.autoRequest.forEach((playlist, index) => {
  128. if (playlist._id === playlistId) {
  129. this.autoRequest.splice(index, 1);
  130. }
  131. });
  132. },
  133. updateMediaModalPlayingAudio(mediaModalPlayingAudio) {
  134. this.mediaModalPlayingAudio = mediaModalPlayingAudio;
  135. },
  136. hasPermission(permission) {
  137. return !!(this.permissions && this.permissions[permission]);
  138. },
  139. updatePermissions() {
  140. return new Promise(resolve => {
  141. ws.socket.dispatch(
  142. "utils.getPermissions",
  143. this.station._id,
  144. res => {
  145. this.permissions = res.data.permissions;
  146. resolve(this.permissions);
  147. }
  148. );
  149. });
  150. },
  151. addDj(user) {
  152. this.station.djs.push(user);
  153. },
  154. removeDj(user) {
  155. this.station.djs.forEach((dj, index) => {
  156. if (dj._id === user._id) {
  157. this.station.djs.splice(index, 1);
  158. }
  159. });
  160. }
  161. }
  162. });