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/foundation.dart';
|
||||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||||
import 'package:hooks_riverpod/hooks_riverpod.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:shadcn_flutter/shadcn_flutter_extension.dart';
|
||||||
import 'package:spotube/collections/routes.gr.dart';
|
import 'package:spotube/collections/routes.gr.dart';
|
||||||
|
|
||||||
|
@ -95,7 +95,11 @@ class PlaylistPage extends HookConsumerWidget {
|
|||||||
if (!confirmed) return null;
|
if (!confirmed) return null;
|
||||||
|
|
||||||
if (isFavoritePlaylist.asData!.value) {
|
if (isFavoritePlaylist.asData!.value) {
|
||||||
await favoritePlaylistsNotifier.removeFavorite(playlist);
|
if (isUserPlaylist) {
|
||||||
|
await favoritePlaylistsNotifier.delete(playlist.id);
|
||||||
|
} else {
|
||||||
|
await favoritePlaylistsNotifier.removeFavorite(playlist);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
await favoritePlaylistsNotifier.addFavorite(playlist);
|
await favoritePlaylistsNotifier.addFavorite(playlist);
|
||||||
}
|
}
|
||||||
|
@ -64,15 +64,18 @@ class MetadataPluginSavedPlaylistsNotifier
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> delete(String playlistId) async {
|
Future<void> delete(String playlistId) async {
|
||||||
await update((state) async {
|
if (state.value == null) return;
|
||||||
(await metadataPlugin).playlist.deletePlaylist(playlistId);
|
final oldState = state;
|
||||||
return state.copyWith(
|
try {
|
||||||
items: state.items.where((e) => (e).id != playlistId).toList(),
|
state = const AsyncLoading();
|
||||||
);
|
await (await metadataPlugin).playlist.deletePlaylist(playlistId);
|
||||||
});
|
ref.invalidateSelf();
|
||||||
|
ref.invalidate(metadataPluginIsSavedPlaylistProvider(playlistId));
|
||||||
ref.invalidate(metadataPluginIsSavedPlaylistProvider(playlistId));
|
ref.invalidate(metadataPluginPlaylistTracksProvider(playlistId));
|
||||||
ref.invalidate(metadataPluginPlaylistTracksProvider(playlistId));
|
} catch (e) {
|
||||||
|
state = oldState;
|
||||||
|
rethrow;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> addTracks(String playlistId, List<String> trackIds) async {
|
Future<void> addTracks(String playlistId, List<String> trackIds) async {
|
||||||
|
@ -40,23 +40,23 @@ class MetadataPluginPlaylistNotifier
|
|||||||
if (userId == null) {
|
if (userId == null) {
|
||||||
throw Exception('User ID is not available. Please log in first.');
|
throw Exception('User ID is not available. Please log in first.');
|
||||||
}
|
}
|
||||||
await update(
|
state = const AsyncValue.loading();
|
||||||
(prev) async {
|
try {
|
||||||
try {
|
final playlist = await (await metadataPlugin).playlist.create(
|
||||||
final playlist = await (await metadataPlugin).playlist.create(
|
userId,
|
||||||
userId,
|
name: name,
|
||||||
name: name,
|
description: description,
|
||||||
description: description,
|
public: public,
|
||||||
public: public,
|
collaborative: collaborative,
|
||||||
collaborative: collaborative,
|
);
|
||||||
);
|
if (playlist != null) {
|
||||||
return playlist!;
|
state = AsyncValue.data(playlist);
|
||||||
} catch (e) {
|
}
|
||||||
onError?.call(e);
|
ref.invalidate(metadataPluginSavedPlaylistsProvider);
|
||||||
rethrow;
|
} catch (e) {
|
||||||
}
|
onError?.call(e);
|
||||||
},
|
rethrow;
|
||||||
);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> modify({
|
Future<void> modify({
|
||||||
|
@ -127,7 +127,7 @@ class MetadataPluginPlaylistEndpoint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> deletePlaylist(String playlistId) async {
|
Future<void> deletePlaylist(String playlistId) async {
|
||||||
await hetuMetadataPlaylist.invoke(
|
return await hetuMetadataPlaylist.invoke(
|
||||||
"deletePlaylist",
|
"deletePlaylist",
|
||||||
positionalArgs: [playlistId],
|
positionalArgs: [playlistId],
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user