station.ts 3.4 KB

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