mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-12 23:45:18 +00:00
fix: create and delete playlist not working
This commit is contained in:
parent
93d6e0642b
commit
066fe2a326
@ -2,7 +2,7 @@ import 'package:auto_route/auto_route.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:shadcn_flutter/shadcn_flutter.dart' hide Consumer;
|
||||
import 'package:shadcn_flutter/shadcn_flutter.dart';
|
||||
import 'package:shadcn_flutter/shadcn_flutter_extension.dart';
|
||||
import 'package:spotube/collections/routes.gr.dart';
|
||||
|
||||
|
@ -95,7 +95,11 @@ class PlaylistPage extends HookConsumerWidget {
|
||||
if (!confirmed) return null;
|
||||
|
||||
if (isFavoritePlaylist.asData!.value) {
|
||||
if (isUserPlaylist) {
|
||||
await favoritePlaylistsNotifier.delete(playlist.id);
|
||||
} else {
|
||||
await favoritePlaylistsNotifier.removeFavorite(playlist);
|
||||
}
|
||||
} else {
|
||||
await favoritePlaylistsNotifier.addFavorite(playlist);
|
||||
}
|
||||
|
@ -64,15 +64,18 @@ class MetadataPluginSavedPlaylistsNotifier
|
||||
}
|
||||
|
||||
Future<void> delete(String playlistId) async {
|
||||
await update((state) async {
|
||||
(await metadataPlugin).playlist.deletePlaylist(playlistId);
|
||||
return state.copyWith(
|
||||
items: state.items.where((e) => (e).id != playlistId).toList(),
|
||||
);
|
||||
});
|
||||
|
||||
if (state.value == null) return;
|
||||
final oldState = state;
|
||||
try {
|
||||
state = const AsyncLoading();
|
||||
await (await metadataPlugin).playlist.deletePlaylist(playlistId);
|
||||
ref.invalidateSelf();
|
||||
ref.invalidate(metadataPluginIsSavedPlaylistProvider(playlistId));
|
||||
ref.invalidate(metadataPluginPlaylistTracksProvider(playlistId));
|
||||
} catch (e) {
|
||||
state = oldState;
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> addTracks(String playlistId, List<String> trackIds) async {
|
||||
|
@ -40,8 +40,7 @@ class MetadataPluginPlaylistNotifier
|
||||
if (userId == null) {
|
||||
throw Exception('User ID is not available. Please log in first.');
|
||||
}
|
||||
await update(
|
||||
(prev) async {
|
||||
state = const AsyncValue.loading();
|
||||
try {
|
||||
final playlist = await (await metadataPlugin).playlist.create(
|
||||
userId,
|
||||
@ -50,13 +49,14 @@ class MetadataPluginPlaylistNotifier
|
||||
public: public,
|
||||
collaborative: collaborative,
|
||||
);
|
||||
return playlist!;
|
||||
if (playlist != null) {
|
||||
state = AsyncValue.data(playlist);
|
||||
}
|
||||
ref.invalidate(metadataPluginSavedPlaylistsProvider);
|
||||
} catch (e) {
|
||||
onError?.call(e);
|
||||
rethrow;
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> modify({
|
||||
|
@ -127,7 +127,7 @@ class MetadataPluginPlaylistEndpoint {
|
||||
}
|
||||
|
||||
Future<void> deletePlaylist(String playlistId) async {
|
||||
await hetuMetadataPlaylist.invoke(
|
||||
return await hetuMetadataPlaylist.invoke(
|
||||
"deletePlaylist",
|
||||
positionalArgs: [playlistId],
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user