1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- using Microsoft.AspNetCore.Components;
- namespace FNZCM.BlazorWasm.Helpers
- {
- public class PlaylistHelper
- {
- public event Action Changed ;
- private readonly LocalStorageHelper localStorage;
- public PlaylistHelper(LocalStorageHelper localStorage) => this.localStorage = localStorage;
- public Dictionary<Guid, string> PlayListLoadSave { get => localStorage.Get<Dictionary<Guid, string>>() ?? new Dictionary<Guid, string>(); set => localStorage.Set(value); }
- public List<string> this[Guid playlistId]
- {
- get => localStorage.Get<List<string>>($"playlist-{playlistId}") ?? new List<string>();
- set => localStorage.Set(value, $"playlist-{playlistId}");
- }
- public void CreateNewPlaylist(string name)
- {
- var pls = PlayListLoadSave;
- pls[Guid.NewGuid()] = name;
- PlayListLoadSave = pls;
- Changed?.Invoke();
- }
- public void AddTrackToPlaylist(string trackPath, Guid playlistId)
- {
- var p = this[playlistId];
- p.Add(trackPath);
- this[playlistId] = p;
- Changed?.Invoke();
- }
- public void DeleteTrackInPlaylist(Guid playlistId, int index, string trackPathForConfirm)
- {
- var p = this[playlistId];
- if (index < p.Count && p[index] == trackPathForConfirm) p.RemoveAt(index);
- this[playlistId] = p;
- Changed?.Invoke();
- }
- public void Deleteplaylist(Guid playlistId)
- {
- localStorage.Remove($"playlist-{playlistId}");
- var pls = PlayListLoadSave;
- pls.Remove(playlistId);
- PlayListLoadSave = pls;
- Changed?.Invoke();
- }
- public void UpdatePlaylistName(Guid playlistId,string name)
- {
- var pls = PlayListLoadSave;
- pls[playlistId] = name;
- PlayListLoadSave = pls;
- Changed?.Invoke();
- }
- //TODO: Move order track in playlist
- }
- }
|