Skip to content

Commit

Permalink
feat: loading indicator for genre and personalized pages
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Sep 16, 2023
1 parent 5c5dbf6 commit ffe8d9c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 31 deletions.
1 change: 0 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:catcher/catcher.dart';
import 'package:device_preview/device_preview.dart';
import 'package:fl_query/fl_query.dart';
import 'package:fl_query_devtools/fl_query_devtools.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
Expand Down
37 changes: 20 additions & 17 deletions lib/pages/home/genres.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,24 +73,27 @@ class GenrePage extends HookConsumerWidget {
searchController: searchController,
searchFocus: searchFocus,
),
Expanded(
child: ListView.builder(
controller: scrollController,
itemCount: categories.length,
itemBuilder: (context, index) {
return AnimatedCrossFade(
crossFadeState: searchController.text.isEmpty &&
index == categories.length - 1 &&
categoriesQuery.hasNextPage
? CrossFadeState.showFirst
: CrossFadeState.showSecond,
duration: const Duration(milliseconds: 300),
firstChild: const ShimmerCategories(),
secondChild: CategoryCard(categories[index]),
);
},
if (!categoriesQuery.hasPageData)
const ShimmerCategories()
else
Expanded(
child: ListView.builder(
controller: scrollController,
itemCount: categories.length,
itemBuilder: (context, index) {
return AnimatedCrossFade(
crossFadeState: searchController.text.isEmpty &&
index == categories.length - 1 &&
categoriesQuery.hasNextPage
? CrossFadeState.showFirst
: CrossFadeState.showSecond,
duration: const Duration(milliseconds: 300),
firstChild: const ShimmerCategories(),
secondChild: CategoryCard(categories[index]),
);
},
),
),
),
],
),
),
Expand Down
27 changes: 14 additions & 13 deletions lib/pages/home/personalized.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:spotify/spotify.dart';
import 'package:spotube/components/album/album_card.dart';
import 'package:spotube/components/playlist/playlist_card.dart';
import 'package:spotube/components/shared/shimmers/shimmer_categories.dart';
import 'package:spotube/components/shared/shimmers/shimmer_playbutton_card.dart';
import 'package:spotube/components/shared/waypoint.dart';
import 'package:spotube/extensions/context.dart';
Expand Down Expand Up @@ -107,12 +108,9 @@ class PersonalizedPage extends HookConsumerWidget {
final madeForUser = useQueries.views.get(ref, "made-for-x-hub");

final newReleases = useQueries.album.newReleases(ref);
final userArtists = useQueries.artist
.followedByMeAll(ref)
.data
?.map((s) => s.id!)
.toList() ??
const [];
final userArtistsQuery = useQueries.artist.followedByMeAll(ref);
final userArtists =
userArtistsQuery.data?.map((s) => s.id!).toList() ?? const [];

final albums = useMemoized(
() => newReleases.pages
Expand All @@ -128,13 +126,16 @@ class PersonalizedPage extends HookConsumerWidget {

return ListView(
children: [
PersonalizedItemCard(
playlists: playlists,
title: context.l10n.featured,
hasNextPage: featuredPlaylistsQuery.hasNextPage,
onFetchMore: featuredPlaylistsQuery.fetchNext,
),
if (auth != null)
if (!featuredPlaylistsQuery.hasPageData)
const ShimmerCategories()
else
PersonalizedItemCard(
playlists: playlists,
title: context.l10n.featured,
hasNextPage: featuredPlaylistsQuery.hasNextPage,
onFetchMore: featuredPlaylistsQuery.fetchNext,
),
if (auth != null && newReleases.hasPageData && userArtistsQuery.hasData)
PersonalizedItemCard(
albums: albums,
title: context.l10n.new_releases,
Expand Down

0 comments on commit ffe8d9c

Please sign in to comment.