mirror of
https://github.com/Dispatcharr/Dispatcharr.git
synced 2026-07-18 00:55:50 +00:00
Merge pull request #1284 from nemesbak:fix/delete-last-playlist-error
fix(frontend): clean up profiles state when playlists are deleted
This commit is contained in:
commit
2156ea6283
2 changed files with 30 additions and 13 deletions
|
|
@ -194,15 +194,25 @@ describe('usePlaylistsStore', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('should remove playlists', () => {
|
||||
it('should remove playlists and their profiles', () => {
|
||||
const { result } = renderHook(() => usePlaylistsStore());
|
||||
|
||||
act(() => {
|
||||
result.current.playlists = [
|
||||
{ id: 'playlist1', name: 'Playlist 1' },
|
||||
{ id: 'playlist2', name: 'Playlist 2' },
|
||||
{ id: 'playlist3', name: 'Playlist 3' },
|
||||
];
|
||||
result.current.addPlaylist({
|
||||
id: 'playlist1',
|
||||
name: 'Playlist 1',
|
||||
profiles: ['profile1'],
|
||||
});
|
||||
result.current.addPlaylist({
|
||||
id: 'playlist2',
|
||||
name: 'Playlist 2',
|
||||
profiles: ['profile2'],
|
||||
});
|
||||
result.current.addPlaylist({
|
||||
id: 'playlist3',
|
||||
name: 'Playlist 3',
|
||||
profiles: ['profile3'],
|
||||
});
|
||||
});
|
||||
|
||||
act(() => {
|
||||
|
|
@ -210,8 +220,11 @@ describe('usePlaylistsStore', () => {
|
|||
});
|
||||
|
||||
expect(result.current.playlists).toEqual([
|
||||
{ id: 'playlist2', name: 'Playlist 2' },
|
||||
{ id: 'playlist2', name: 'Playlist 2', profiles: ['profile2'] },
|
||||
]);
|
||||
expect(result.current.profiles).toEqual({ playlist2: ['profile2'] });
|
||||
expect(result.current.profiles.playlist1).toBeUndefined();
|
||||
expect(result.current.profiles.playlist3).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should set refresh progress with two parameters', () => {
|
||||
|
|
|
|||
|
|
@ -86,12 +86,16 @@ const usePlaylistsStore = create((set) => ({
|
|||
})),
|
||||
|
||||
removePlaylists: (playlistIds) =>
|
||||
set((state) => ({
|
||||
playlists: state.playlists.filter(
|
||||
(playlist) => !playlistIds.includes(playlist.id)
|
||||
),
|
||||
// @TODO: remove playlist profiles here
|
||||
})),
|
||||
set((state) => {
|
||||
const updatedProfiles = { ...state.profiles };
|
||||
playlistIds.forEach((id) => delete updatedProfiles[id]);
|
||||
return {
|
||||
playlists: state.playlists.filter(
|
||||
(playlist) => !playlistIds.includes(playlist.id)
|
||||
),
|
||||
profiles: updatedProfiles,
|
||||
};
|
||||
}),
|
||||
|
||||
setRefreshProgress: (accountIdOrData, data) =>
|
||||
set((state) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue