mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-13 07:55:18 +00:00
fix(search): has to submit twice for search results
This commit is contained in:
parent
b78b657377
commit
f5dc76a98f
@ -1,4 +1,4 @@
|
||||
import 'package:fl_query/fl_query.dart';
|
||||
import 'package:fl_query_hooks/fl_query_hooks.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
@ -46,8 +46,8 @@ class AlbumCard extends HookConsumerWidget {
|
||||
final playing = useStream(PlaylistQueueNotifier.playing).data ??
|
||||
PlaylistQueueNotifier.isPlaying;
|
||||
final playlistNotifier = ref.watch(PlaylistQueueNotifier.notifier);
|
||||
final queryBowl = QueryClient.of(context);
|
||||
final query = queryBowl
|
||||
final queryClient = useQueryClient();
|
||||
final query = queryClient
|
||||
.getQuery<List<TrackSimple>, dynamic>("album-tracks/${album.id}");
|
||||
final tracks = useState(query?.data ?? album.tracks ?? <Track>[]);
|
||||
bool isPlaylistPlaying = playlistNotifier.isPlayingPlaylist(tracks.value);
|
||||
@ -100,7 +100,7 @@ class AlbumCard extends HookConsumerWidget {
|
||||
updating.value = true;
|
||||
try {
|
||||
final fetchedTracks =
|
||||
await queryBowl.fetchQuery<List<TrackSimple>, SpotifyApi>(
|
||||
await queryClient.fetchQuery<List<TrackSimple>, SpotifyApi>(
|
||||
"album-tracks/${album.id}",
|
||||
() {
|
||||
return spotify.albums
|
||||
|
@ -35,17 +35,21 @@ class UserPlaylists extends HookConsumerWidget {
|
||||
|
||||
final playlistsQuery = useQueries.playlist.ofMine(ref);
|
||||
|
||||
Image image = Image();
|
||||
image.height = 300;
|
||||
image.width = 300;
|
||||
PlaylistSimple likedTracksPlaylist = PlaylistSimple();
|
||||
likedTracksPlaylist.name = "Liked Tracks";
|
||||
likedTracksPlaylist.type = "playlist";
|
||||
likedTracksPlaylist.collaborative = false;
|
||||
likedTracksPlaylist.public = false;
|
||||
likedTracksPlaylist.id = "user-liked-tracks";
|
||||
image.url = "https://t.scdn.co/images/3099b3803ad9496896c43f22fe9be8c4.png";
|
||||
likedTracksPlaylist.images = [image];
|
||||
final likedTracksPlaylist = useMemoized(
|
||||
() => PlaylistSimple()
|
||||
..name = "Liked Tracks"
|
||||
..type = "playlist"
|
||||
..collaborative = false
|
||||
..public = false
|
||||
..id = "user-liked-tracks"
|
||||
..images = [
|
||||
Image()
|
||||
..height = 300
|
||||
..width = 300
|
||||
..url =
|
||||
"https://t.scdn.co/images/3099b3803ad9496896c43f22fe9be8c4.png"
|
||||
],
|
||||
[]);
|
||||
|
||||
final playlists = useMemoized(
|
||||
() {
|
||||
|
@ -1,73 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:platform_ui/platform_ui.dart';
|
||||
import 'package:spotify/spotify.dart';
|
||||
import 'package:spotube/components/shared/page_window_title_bar.dart';
|
||||
import 'package:spotube/components/playlist/playlist_card.dart';
|
||||
import 'package:spotube/provider/spotify_provider.dart';
|
||||
|
||||
class PlaylistGenreView extends ConsumerWidget {
|
||||
final String genreId;
|
||||
final String genreName;
|
||||
final Iterable<PlaylistSimple>? playlists;
|
||||
const PlaylistGenreView(
|
||||
this.genreId,
|
||||
this.genreName, {
|
||||
this.playlists,
|
||||
Key? key,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, ref) {
|
||||
return Scaffold(
|
||||
appBar: PageWindowTitleBar(
|
||||
leading: const PlatformBackButton(),
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
PlatformText.subheading(
|
||||
genreName,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
Consumer(
|
||||
builder: (context, ref, child) {
|
||||
SpotifyApi spotifyApi = ref.watch(spotifyProvider);
|
||||
return Expanded(
|
||||
child: SingleChildScrollView(
|
||||
child: FutureBuilder<Iterable<PlaylistSimple>>(
|
||||
future: playlists == null
|
||||
? (genreId != "user-featured-playlists"
|
||||
? spotifyApi.playlists
|
||||
.getByCategoryId(genreId)
|
||||
.all()
|
||||
: spotifyApi.playlists.featured.all())
|
||||
: Future.value(playlists),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasError) {
|
||||
return const Center(child: Text("Error occurred"));
|
||||
}
|
||||
if (!snapshot.hasData) {
|
||||
return const PlatformCircularProgressIndicator();
|
||||
}
|
||||
return Center(
|
||||
child: Wrap(
|
||||
children: snapshot.data!
|
||||
.map(
|
||||
(playlist) => Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: PlaylistCard(playlist),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
);
|
||||
}),
|
||||
),
|
||||
);
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -125,7 +125,7 @@ class PlaylistHeartButton extends HookConsumerWidget {
|
||||
final isLikedQuery = useQueries.playlist.doesUserFollow(
|
||||
ref,
|
||||
playlist.id!,
|
||||
me.data!.id!,
|
||||
me.data?.id ?? '',
|
||||
);
|
||||
|
||||
final togglePlaylistLike = useMutations.playlist.toggleFavorite(
|
||||
|
@ -1,3 +1,5 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart' hide Page;
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
@ -50,15 +52,13 @@ class SearchPage extends HookConsumerWidget {
|
||||
final searchArtist =
|
||||
useQueries.search.query(ref, searchTerm, SearchType.artist);
|
||||
|
||||
void onSearch() {
|
||||
for (final query in [
|
||||
searchTrack,
|
||||
searchAlbum,
|
||||
searchPlaylist,
|
||||
searchArtist,
|
||||
]) {
|
||||
query.refreshAll();
|
||||
}
|
||||
Future<void> onSearch() async {
|
||||
await Future.wait([
|
||||
searchTrack.refreshAll(),
|
||||
searchAlbum.refreshAll(),
|
||||
searchPlaylist.refreshAll(),
|
||||
searchArtist.refreshAll(),
|
||||
]);
|
||||
}
|
||||
|
||||
return SafeArea(
|
||||
@ -82,10 +82,14 @@ class SearchPage extends HookConsumerWidget {
|
||||
other: null,
|
||||
).resolve(platform!),
|
||||
placeholder: "Search...",
|
||||
onSubmitted: (value) {
|
||||
onSubmitted: (value) async {
|
||||
ref.read(searchTermStateProvider.notifier).state =
|
||||
value;
|
||||
onSearch();
|
||||
// Fl-Query is too fast, so we need to delay the search
|
||||
// to prevent spamming the API :)
|
||||
Timer(const Duration(milliseconds: 50), () {
|
||||
onSearch();
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
|
@ -535,7 +535,7 @@ packages:
|
||||
description:
|
||||
path: "packages/fl_query"
|
||||
ref: new-architecture
|
||||
resolved-ref: f2a23b085cd657a1612d87749f6592b4d67814c5
|
||||
resolved-ref: cf2550a2909d0cb957324fe114acacb431a5f33a
|
||||
url: "https://github.com/KRTirtho/fl-query.git"
|
||||
source: git
|
||||
version: "0.3.1"
|
||||
@ -544,7 +544,7 @@ packages:
|
||||
description:
|
||||
path: "packages/fl_query_hooks"
|
||||
ref: new-architecture
|
||||
resolved-ref: f2a23b085cd657a1612d87749f6592b4d67814c5
|
||||
resolved-ref: cf2550a2909d0cb957324fe114acacb431a5f33a
|
||||
url: "https://github.com/KRTirtho/fl-query.git"
|
||||
source: git
|
||||
version: "0.3.1"
|
||||
|
Loading…
Reference in New Issue
Block a user