mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-13 16:05: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/material.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';
|
||||||
@ -46,8 +46,8 @@ class AlbumCard extends HookConsumerWidget {
|
|||||||
final playing = useStream(PlaylistQueueNotifier.playing).data ??
|
final playing = useStream(PlaylistQueueNotifier.playing).data ??
|
||||||
PlaylistQueueNotifier.isPlaying;
|
PlaylistQueueNotifier.isPlaying;
|
||||||
final playlistNotifier = ref.watch(PlaylistQueueNotifier.notifier);
|
final playlistNotifier = ref.watch(PlaylistQueueNotifier.notifier);
|
||||||
final queryBowl = QueryClient.of(context);
|
final queryClient = useQueryClient();
|
||||||
final query = queryBowl
|
final query = queryClient
|
||||||
.getQuery<List<TrackSimple>, dynamic>("album-tracks/${album.id}");
|
.getQuery<List<TrackSimple>, dynamic>("album-tracks/${album.id}");
|
||||||
final tracks = useState(query?.data ?? album.tracks ?? <Track>[]);
|
final tracks = useState(query?.data ?? album.tracks ?? <Track>[]);
|
||||||
bool isPlaylistPlaying = playlistNotifier.isPlayingPlaylist(tracks.value);
|
bool isPlaylistPlaying = playlistNotifier.isPlayingPlaylist(tracks.value);
|
||||||
@ -100,7 +100,7 @@ class AlbumCard extends HookConsumerWidget {
|
|||||||
updating.value = true;
|
updating.value = true;
|
||||||
try {
|
try {
|
||||||
final fetchedTracks =
|
final fetchedTracks =
|
||||||
await queryBowl.fetchQuery<List<TrackSimple>, SpotifyApi>(
|
await queryClient.fetchQuery<List<TrackSimple>, SpotifyApi>(
|
||||||
"album-tracks/${album.id}",
|
"album-tracks/${album.id}",
|
||||||
() {
|
() {
|
||||||
return spotify.albums
|
return spotify.albums
|
||||||
|
@ -35,17 +35,21 @@ class UserPlaylists extends HookConsumerWidget {
|
|||||||
|
|
||||||
final playlistsQuery = useQueries.playlist.ofMine(ref);
|
final playlistsQuery = useQueries.playlist.ofMine(ref);
|
||||||
|
|
||||||
Image image = Image();
|
final likedTracksPlaylist = useMemoized(
|
||||||
image.height = 300;
|
() => PlaylistSimple()
|
||||||
image.width = 300;
|
..name = "Liked Tracks"
|
||||||
PlaylistSimple likedTracksPlaylist = PlaylistSimple();
|
..type = "playlist"
|
||||||
likedTracksPlaylist.name = "Liked Tracks";
|
..collaborative = false
|
||||||
likedTracksPlaylist.type = "playlist";
|
..public = false
|
||||||
likedTracksPlaylist.collaborative = false;
|
..id = "user-liked-tracks"
|
||||||
likedTracksPlaylist.public = false;
|
..images = [
|
||||||
likedTracksPlaylist.id = "user-liked-tracks";
|
Image()
|
||||||
image.url = "https://t.scdn.co/images/3099b3803ad9496896c43f22fe9be8c4.png";
|
..height = 300
|
||||||
likedTracksPlaylist.images = [image];
|
..width = 300
|
||||||
|
..url =
|
||||||
|
"https://t.scdn.co/images/3099b3803ad9496896c43f22fe9be8c4.png"
|
||||||
|
],
|
||||||
|
[]);
|
||||||
|
|
||||||
final playlists = useMemoized(
|
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(
|
final isLikedQuery = useQueries.playlist.doesUserFollow(
|
||||||
ref,
|
ref,
|
||||||
playlist.id!,
|
playlist.id!,
|
||||||
me.data!.id!,
|
me.data?.id ?? '',
|
||||||
);
|
);
|
||||||
|
|
||||||
final togglePlaylistLike = useMutations.playlist.toggleFavorite(
|
final togglePlaylistLike = useMutations.playlist.toggleFavorite(
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/gestures.dart';
|
import 'package:flutter/gestures.dart';
|
||||||
import 'package:flutter/material.dart' hide Page;
|
import 'package:flutter/material.dart' hide Page;
|
||||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||||
@ -50,15 +52,13 @@ class SearchPage extends HookConsumerWidget {
|
|||||||
final searchArtist =
|
final searchArtist =
|
||||||
useQueries.search.query(ref, searchTerm, SearchType.artist);
|
useQueries.search.query(ref, searchTerm, SearchType.artist);
|
||||||
|
|
||||||
void onSearch() {
|
Future<void> onSearch() async {
|
||||||
for (final query in [
|
await Future.wait([
|
||||||
searchTrack,
|
searchTrack.refreshAll(),
|
||||||
searchAlbum,
|
searchAlbum.refreshAll(),
|
||||||
searchPlaylist,
|
searchPlaylist.refreshAll(),
|
||||||
searchArtist,
|
searchArtist.refreshAll(),
|
||||||
]) {
|
]);
|
||||||
query.refreshAll();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return SafeArea(
|
return SafeArea(
|
||||||
@ -82,10 +82,14 @@ class SearchPage extends HookConsumerWidget {
|
|||||||
other: null,
|
other: null,
|
||||||
).resolve(platform!),
|
).resolve(platform!),
|
||||||
placeholder: "Search...",
|
placeholder: "Search...",
|
||||||
onSubmitted: (value) {
|
onSubmitted: (value) async {
|
||||||
ref.read(searchTermStateProvider.notifier).state =
|
ref.read(searchTermStateProvider.notifier).state =
|
||||||
value;
|
value;
|
||||||
|
// Fl-Query is too fast, so we need to delay the search
|
||||||
|
// to prevent spamming the API :)
|
||||||
|
Timer(const Duration(milliseconds: 50), () {
|
||||||
onSearch();
|
onSearch();
|
||||||
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -535,7 +535,7 @@ packages:
|
|||||||
description:
|
description:
|
||||||
path: "packages/fl_query"
|
path: "packages/fl_query"
|
||||||
ref: new-architecture
|
ref: new-architecture
|
||||||
resolved-ref: f2a23b085cd657a1612d87749f6592b4d67814c5
|
resolved-ref: cf2550a2909d0cb957324fe114acacb431a5f33a
|
||||||
url: "https://github.com/KRTirtho/fl-query.git"
|
url: "https://github.com/KRTirtho/fl-query.git"
|
||||||
source: git
|
source: git
|
||||||
version: "0.3.1"
|
version: "0.3.1"
|
||||||
@ -544,7 +544,7 @@ packages:
|
|||||||
description:
|
description:
|
||||||
path: "packages/fl_query_hooks"
|
path: "packages/fl_query_hooks"
|
||||||
ref: new-architecture
|
ref: new-architecture
|
||||||
resolved-ref: f2a23b085cd657a1612d87749f6592b4d67814c5
|
resolved-ref: cf2550a2909d0cb957324fe114acacb431a5f33a
|
||||||
url: "https://github.com/KRTirtho/fl-query.git"
|
url: "https://github.com/KRTirtho/fl-query.git"
|
||||||
source: git
|
source: git
|
||||||
version: "0.3.1"
|
version: "0.3.1"
|
||||||
|
Loading…
Reference in New Issue
Block a user