userPlaylists.ts 643 B

123456789101112131415161718192021222324252627
  1. import { defineStore } from "pinia";
  2. import { Playlist } from "@/types/playlist";
  3. export const useUserPlaylistsStore = defineStore("userPlaylists", {
  4. state: (): {
  5. playlists: Playlist[];
  6. } => ({
  7. playlists: []
  8. }),
  9. actions: {
  10. setPlaylists(playlists: Playlist[]) {
  11. this.playlists = playlists;
  12. },
  13. updatePlaylists(playlists: Playlist[]) {
  14. this.playlists = playlists;
  15. },
  16. addPlaylist(playlist: Playlist) {
  17. this.playlists.push(playlist);
  18. },
  19. removePlaylist(playlistId: string) {
  20. this.playlists.forEach((playlist, index) => {
  21. if (playlist._id === playlistId)
  22. this.playlists.splice(index, 1);
  23. });
  24. }
  25. }
  26. });