mirror of
https://github.com/KRTirtho/spotube.git
synced 2026-05-08 16:24:36 +00:00
feat: add all categories providers
This commit is contained in:
parent
78b7759f10
commit
54b32459a8
20
lib/provider/spotify/category/categories.dart
Normal file
20
lib/provider/spotify/category/categories.dart
Normal file
@ -0,0 +1,20 @@
|
||||
part of '../spotify.dart';
|
||||
|
||||
final categoriesProvider = FutureProvider(
|
||||
(ref) async {
|
||||
final spotify = ref.watch(spotifyProvider);
|
||||
final market = ref
|
||||
.watch(userPreferencesProvider.select((s) => s.recommendationMarket));
|
||||
final locale = ref.watch(userPreferencesProvider.select((s) => s.locale));
|
||||
final categories = await spotify.categories
|
||||
.list(
|
||||
country: market,
|
||||
locale: Intl.canonicalizedLocale(
|
||||
locale.toString(),
|
||||
),
|
||||
)
|
||||
.all();
|
||||
|
||||
return categories.toList()..shuffle();
|
||||
},
|
||||
);
|
||||
6
lib/provider/spotify/category/genres.dart
Normal file
6
lib/provider/spotify/category/genres.dart
Normal file
@ -0,0 +1,6 @@
|
||||
part of '../spotify.dart';
|
||||
|
||||
final categoryGenresProvider = FutureProvider<List<String>>((ref) async {
|
||||
final customSpotify = ref.watch(customSpotifyEndpointProvider);
|
||||
return await customSpotify.listGenreSeeds();
|
||||
});
|
||||
65
lib/provider/spotify/category/playlists.dart
Normal file
65
lib/provider/spotify/category/playlists.dart
Normal file
@ -0,0 +1,65 @@
|
||||
part of '../spotify.dart';
|
||||
|
||||
class CategoryPlaylistsState extends PaginatedState<PlaylistSimple> {
|
||||
CategoryPlaylistsState({
|
||||
required super.items,
|
||||
required super.offset,
|
||||
required super.limit,
|
||||
required super.hasMore,
|
||||
});
|
||||
|
||||
@override
|
||||
CategoryPlaylistsState copyWith({
|
||||
List<PlaylistSimple>? items,
|
||||
int? offset,
|
||||
int? limit,
|
||||
bool? hasMore,
|
||||
}) {
|
||||
return CategoryPlaylistsState(
|
||||
items: items ?? this.items,
|
||||
offset: offset ?? this.offset,
|
||||
limit: limit ?? this.limit,
|
||||
hasMore: hasMore ?? this.hasMore,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class CategoryPlaylistsNotifier extends FamilyPaginatedAsyncNotifier<
|
||||
PlaylistSimple, CategoryPlaylistsState, String> {
|
||||
CategoryPlaylistsNotifier() : super();
|
||||
|
||||
@override
|
||||
fetch(arg, offset, limit) async {
|
||||
final preferences = ref.read(userPreferencesProvider);
|
||||
final playlists = await Pages<PlaylistSimple?>(
|
||||
spotify,
|
||||
"v1/browse/categories/$arg/playlists?country=${preferences.recommendationMarket.name}&locale=${preferences.locale}",
|
||||
(json) => json == null ? null : PlaylistSimple.fromJson(json),
|
||||
'playlists',
|
||||
(json) => PlaylistsFeatured.fromJson(json),
|
||||
).getPage(offset, limit);
|
||||
|
||||
return playlists.items?.whereNotNull().toList() ?? [];
|
||||
}
|
||||
|
||||
@override
|
||||
build(arg) async {
|
||||
ref.watch(spotifyProvider);
|
||||
ref.watch(userPreferencesProvider.select((s) => s.locale));
|
||||
ref.watch(userPreferencesProvider.select((s) => s.recommendationMarket));
|
||||
|
||||
final playlists = await fetch(arg, 0, 8);
|
||||
|
||||
return CategoryPlaylistsState(
|
||||
items: playlists,
|
||||
offset: 0,
|
||||
limit: 8,
|
||||
hasMore: playlists.length == 8,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
final categoryPlaylistsProvider = AsyncNotifierProviderFamily<
|
||||
CategoryPlaylistsNotifier, CategoryPlaylistsState, String>(
|
||||
() => CategoryPlaylistsNotifier(),
|
||||
);
|
||||
@ -1,9 +1,12 @@
|
||||
library spotify;
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:spotify/spotify.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
// ignore: depend_on_referenced_packages, implementation_imports
|
||||
import 'package:riverpod/src/async_notifier.dart';
|
||||
import 'package:spotube/provider/custom_spotify_endpoint_provider.dart';
|
||||
import 'package:spotube/provider/spotify_provider.dart';
|
||||
import 'package:spotube/provider/user_preferences/user_preferences_provider.dart';
|
||||
|
||||
@ -18,6 +21,10 @@ part 'artist/following.dart';
|
||||
part 'artist/top_tracks.dart';
|
||||
part 'artist/albums.dart';
|
||||
|
||||
part 'category/genres.dart';
|
||||
part 'category/categories.dart';
|
||||
part 'category/playlists.dart';
|
||||
|
||||
part 'utils/mixin.dart';
|
||||
part 'utils/state.dart';
|
||||
part 'utils/provider.dart';
|
||||
|
||||
Loading…
Reference in New Issue
Block a user