Skip to content

Commit

Permalink
fix(search): grey screen, only tracks update on new search string, pl…
Browse files Browse the repository at this point in the history
…aylists,albums,artists show up before hitting return/submit
  • Loading branch information
KRTirtho committed Feb 3, 2023
1 parent 1bb38c3 commit a774817
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 23 deletions.
8 changes: 5 additions & 3 deletions lib/components/player/player_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,11 @@ class PlayerControls extends HookConsumerWidget {
// there's an edge case for value being bigger
// than total duration. Keeping it resolved
value: progress.value.toDouble(),
onChanged: (v) {
progress.value = v;
},
onChanged: playlist?.isLoading == true
? null
: (v) {
progress.value = v;
},
onChangeEnd: (value) async {
await playlistNotifier.seek(
Duration(
Expand Down
57 changes: 38 additions & 19 deletions lib/pages/search/search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class SearchPage extends HookConsumerWidget {

@override
Widget build(BuildContext context, ref) {
final Auth auth = ref.watch(authProvider);
final auth = ref.watch(authProvider);
final spotify = ref.watch(spotifyProvider);
final albumController = useScrollController();
final playlistController = useScrollController();
final artistController = useScrollController();
Expand All @@ -42,23 +43,27 @@ class SearchPage extends HookConsumerWidget {
final getVariables = useCallback(
() => Tuple2(
ref.read(searchTermStateProvider),
ref.read(spotifyProvider),
spotify,
),
[],
);

final searchTrack = useInfiniteQuery(
job: Queries.search.get(SearchType.track.key),
externalData: getVariables());
job: Queries.search.get(SearchType.track.key),
externalData: Tuple2("", spotify),
);
final searchAlbum = useInfiniteQuery(
job: Queries.search.get(SearchType.album.key),
externalData: getVariables());
job: Queries.search.get(SearchType.album.key),
externalData: Tuple2("", spotify),
);
final searchPlaylist = useInfiniteQuery(
job: Queries.search.get(SearchType.playlist.key),
externalData: getVariables());
job: Queries.search.get(SearchType.playlist.key),
externalData: Tuple2("", spotify),
);
final searchArtist = useInfiniteQuery(
job: Queries.search.get(SearchType.artist.key),
externalData: getVariables());
job: Queries.search.get(SearchType.artist.key),
externalData: Tuple2("", spotify),
);

void onSearch() {
for (final query in [
Expand All @@ -68,9 +73,9 @@ class SearchPage extends HookConsumerWidget {
searchArtist,
]) {
query.enabled = false;
query.fetched = true;
query.fetched = false;
query.setExternalData(getVariables());
query.refetch();
query.refetchPages();
}
}

Expand Down Expand Up @@ -150,7 +155,9 @@ class SearchPage extends HookConsumerWidget {
const PlatformCircularProgressIndicator()
else if (searchTrack.hasError)
PlatformText(searchTrack
.error?[searchTrack.pageParams.last])
.error?[searchTrack.pageParams.last]
?.toString() ??
"")
else
...tracks.asMap().entries.map((track) {
String duration =
Expand Down Expand Up @@ -233,8 +240,12 @@ class SearchPage extends HookConsumerWidget {
!searchPlaylist.isFetchingNextPage)
const PlatformCircularProgressIndicator(),
if (searchPlaylist.hasError)
PlatformText(searchPlaylist
.error?[searchPlaylist.pageParams.last]),
PlatformText(
searchPlaylist.error?[
searchPlaylist.pageParams.last]
?.toString() ??
"",
),
const SizedBox(height: 20),
if (artists.isNotEmpty)
PlatformText.headline("Artists"),
Expand Down Expand Up @@ -284,8 +295,12 @@ class SearchPage extends HookConsumerWidget {
!searchArtist.isFetchingNextPage)
const PlatformCircularProgressIndicator(),
if (searchArtist.hasError)
PlatformText(searchArtist
.error?[searchArtist.pageParams.last]),
PlatformText(
searchArtist.error?[
searchArtist.pageParams.last]
?.toString() ??
"",
),
const SizedBox(height: 20),
if (albums.isNotEmpty)
PlatformText.subheading("Albums"),
Expand Down Expand Up @@ -333,8 +348,12 @@ class SearchPage extends HookConsumerWidget {
!searchAlbum.isFetchingNextPage)
const PlatformCircularProgressIndicator(),
if (searchAlbum.hasError)
PlatformText(searchAlbum
.error?[searchAlbum.pageParams.last]),
PlatformText(
searchAlbum
.error?[searchAlbum.pageParams.last]
?.toString() ??
"",
),
],
),
),
Expand Down
2 changes: 1 addition & 1 deletion lib/services/queries/search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ class SearchQueries {
: lastParam + 10,
getPreviousPageParam: (lastPage, lastParam) => lastParam - 10,
task: (queryKey, pageParam, variables) {
if (variables.item1.trim().isEmpty) return [];
final queryString = variables.item1;
final spotify = variables.item2;
if (queryString.isEmpty) return [];
final searchType = getVariable(queryKey);
return spotify.search.get(
queryString,
Expand Down

0 comments on commit a774817

Please sign in to comment.