mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-12 23:45:18 +00:00

* feat: add playback history provider * feat: implement recently played section * refactor: use route names * feat: add stats summary and top tracks/artists/albums * feat: add top date based filtering * feat: add stream money calculation * refactor: place search in mobile navbar and settings in home appbar * feat: add individual minutes and streams page * feat(stats): add individual minutes and streams page * chore: default period to 1 month * feat: add text to explain user how hypothetical fees are calculated * chore: ensure usage of route names instead of direct paths * cd: add cache key * cd: remove media_kit_event_loop from git
41 lines
1.3 KiB
Dart
41 lines
1.3 KiB
Dart
import 'package:collection/collection.dart';
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
import 'package:spotube/provider/history/history.dart';
|
|
import 'package:spotube/provider/history/state.dart';
|
|
|
|
final recentlyPlayedItems = Provider((ref) {
|
|
return ref.watch(
|
|
playbackHistoryProvider.select(
|
|
(s) => s.items
|
|
.toSet()
|
|
// unique items
|
|
.whereIndexed(
|
|
(index, item) =>
|
|
index ==
|
|
s.items.lastIndexWhere(
|
|
(e) => switch ((e, item)) {
|
|
(
|
|
PlaybackHistoryPlaylist(:final playlist),
|
|
PlaybackHistoryPlaylist(playlist: final playlist2)
|
|
) =>
|
|
playlist.id == playlist2.id,
|
|
(
|
|
PlaybackHistoryAlbum(:final album),
|
|
PlaybackHistoryAlbum(album: final album2)
|
|
) =>
|
|
album.id == album2.id,
|
|
_ => false,
|
|
},
|
|
),
|
|
)
|
|
.where(
|
|
(s) => s is PlaybackHistoryPlaylist || s is PlaybackHistoryAlbum,
|
|
)
|
|
.take(10)
|
|
.sortedBy((s) => s.date)
|
|
.reversed
|
|
.toList(),
|
|
),
|
|
);
|
|
});
|