station.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. import { defineStore } from "pinia";
  2. export const useStationStore = defineStore("station", {
  3. state: () => ({
  4. station: {},
  5. autoRequest: [],
  6. autoRequestLock: false,
  7. editing: {},
  8. userCount: 0,
  9. users: {
  10. loggedIn: [],
  11. loggedOut: []
  12. },
  13. currentSong: {},
  14. nextSong: null,
  15. songsList: [],
  16. stationPaused: true,
  17. localPaused: false,
  18. noSong: true,
  19. autofill: [],
  20. blacklist: []
  21. }),
  22. actions: {
  23. joinStation(station) {
  24. this.station = { ...station };
  25. },
  26. leaveStation() {
  27. this.station = {};
  28. this.autoRequest = [];
  29. this.autoRequestLock = false;
  30. this.editing = {};
  31. this.userCount = 0;
  32. this.users = {
  33. loggedIn: [],
  34. loggedOut: []
  35. };
  36. this.currentSong = {};
  37. this.nextSong = null;
  38. this.songsList = [];
  39. this.stationPaused = true;
  40. this.localPaused = false;
  41. this.noSong = true;
  42. this.autofill = [];
  43. this.blacklist = [];
  44. },
  45. editStation(station) {
  46. this.editing = { ...station };
  47. },
  48. updateStation(station) {
  49. this.station = { ...this.station, ...station };
  50. },
  51. updateUserCount(userCount) {
  52. this.userCount = userCount;
  53. },
  54. updateUsers(users) {
  55. this.users = users;
  56. },
  57. updateCurrentSong(currentSong) {
  58. this.currentSong = currentSong;
  59. },
  60. updateNextSong(nextSong) {
  61. this.nextSong = nextSong;
  62. },
  63. updateSongsList(songsList) {
  64. this.songsList = songsList;
  65. },
  66. repositionSongInList(song) {
  67. if (
  68. this.songsList[song.newIndex] &&
  69. this.songsList[song.newIndex].youtubeId === song.youtubeId
  70. )
  71. return;
  72. this.songsList.splice(
  73. song.newIndex,
  74. 0,
  75. this.songsList.splice(song.oldIndex, 1)[0]
  76. );
  77. },
  78. updateStationPaused(stationPaused) {
  79. this.stationPaused = stationPaused;
  80. },
  81. updateLocalPaused(localPaused) {
  82. this.localPaused = localPaused;
  83. },
  84. updateNoSong(noSong) {
  85. this.noSong = noSong;
  86. },
  87. updateAutoRequest(playlists) {
  88. this.autoRequest = playlists;
  89. },
  90. updateAutoRequestLock(lock) {
  91. this.autoRequestLock = lock;
  92. },
  93. updateIfStationIsFavorited(isFavorited) {
  94. this.station.isFavorited = isFavorited;
  95. },
  96. setAutofillPlaylists(autofillPlaylists) {
  97. this.autofill = JSON.parse(JSON.stringify(autofillPlaylists));
  98. },
  99. setBlacklist(blacklist) {
  100. this.blacklist = JSON.parse(JSON.stringify(blacklist));
  101. },
  102. updateCurrentSongRatings(songRatings) {
  103. this.currentSong.likes = songRatings.likes;
  104. this.currentSong.dislikes = songRatings.dislikes;
  105. },
  106. updateOwnCurrentSongRatings(ownSongRatings) {
  107. this.currentSong.liked = ownSongRatings.liked;
  108. this.currentSong.disliked = ownSongRatings.disliked;
  109. },
  110. updateCurrentSongSkipVotes({ skipVotes, skipVotesCurrent }) {
  111. this.currentSong.skipVotes = skipVotes;
  112. if (skipVotesCurrent !== null)
  113. this.currentSong.skipVotesCurrent = skipVotesCurrent;
  114. },
  115. addPlaylistToAutoRequest(playlist) {
  116. this.autoRequest.push(playlist);
  117. },
  118. removePlaylistFromAutoRequest(playlistId) {
  119. this.autoRequest.forEach((playlist, index) => {
  120. if (playlist._id === playlistId) {
  121. this.autoRequest.splice(index, 1);
  122. }
  123. });
  124. }
  125. }
  126. });