mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-13 16:05:18 +00:00
chore: enable search again
This commit is contained in:
parent
7617439915
commit
b78b657377
@ -3,6 +3,7 @@ import 'package:flutter/widgets.dart';
|
|||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:spotify/spotify.dart' hide Search;
|
import 'package:spotify/spotify.dart' hide Search;
|
||||||
import 'package:spotube/pages/home/home.dart';
|
import 'package:spotube/pages/home/home.dart';
|
||||||
|
import 'package:spotube/pages/search/search.dart';
|
||||||
import 'package:spotube/pages/settings/blacklist.dart';
|
import 'package:spotube/pages/settings/blacklist.dart';
|
||||||
import 'package:spotube/pages/settings/about.dart';
|
import 'package:spotube/pages/settings/about.dart';
|
||||||
import 'package:spotube/utils/platform.dart';
|
import 'package:spotube/utils/platform.dart';
|
||||||
@ -33,12 +34,12 @@ final router = GoRouter(
|
|||||||
path: "/",
|
path: "/",
|
||||||
pageBuilder: (context, state) => SpotubePage(child: const HomePage()),
|
pageBuilder: (context, state) => SpotubePage(child: const HomePage()),
|
||||||
),
|
),
|
||||||
// GoRoute(
|
GoRoute(
|
||||||
// path: "/search",
|
path: "/search",
|
||||||
// name: "Search",
|
name: "Search",
|
||||||
// pageBuilder: (context, state) =>
|
pageBuilder: (context, state) =>
|
||||||
// SpotubePage(child: const SearchPage()),
|
SpotubePage(child: const SearchPage()),
|
||||||
// ),
|
),
|
||||||
GoRoute(
|
GoRoute(
|
||||||
path: "/library",
|
path: "/library",
|
||||||
name: "Library",
|
name: "Library",
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import 'package:fl_query_hooks/fl_query_hooks.dart';
|
|
||||||
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';
|
||||||
@ -17,14 +16,12 @@ import 'package:spotube/components/artist/artist_card.dart';
|
|||||||
import 'package:spotube/components/playlist/playlist_card.dart';
|
import 'package:spotube/components/playlist/playlist_card.dart';
|
||||||
import 'package:spotube/hooks/use_breakpoints.dart';
|
import 'package:spotube/hooks/use_breakpoints.dart';
|
||||||
import 'package:spotube/provider/authentication_provider.dart';
|
import 'package:spotube/provider/authentication_provider.dart';
|
||||||
import 'package:spotube/provider/spotify_provider.dart';
|
|
||||||
import 'package:spotube/provider/playlist_queue_provider.dart';
|
import 'package:spotube/provider/playlist_queue_provider.dart';
|
||||||
import 'package:spotube/services/queries/queries.dart';
|
import 'package:spotube/services/queries/queries.dart';
|
||||||
|
|
||||||
import 'package:spotube/utils/platform.dart';
|
import 'package:spotube/utils/platform.dart';
|
||||||
import 'package:spotube/utils/primitive_utils.dart';
|
import 'package:spotube/utils/primitive_utils.dart';
|
||||||
import 'package:spotube/utils/type_conversion_utils.dart';
|
import 'package:spotube/utils/type_conversion_utils.dart';
|
||||||
import 'package:tuple/tuple.dart';
|
|
||||||
import 'package:collection/collection.dart';
|
import 'package:collection/collection.dart';
|
||||||
|
|
||||||
final searchTermStateProvider = StateProvider<String>((ref) => "");
|
final searchTermStateProvider = StateProvider<String>((ref) => "");
|
||||||
@ -37,36 +34,21 @@ class SearchPage extends HookConsumerWidget {
|
|||||||
ref.watch(AuthenticationNotifier.provider);
|
ref.watch(AuthenticationNotifier.provider);
|
||||||
final authenticationNotifier =
|
final authenticationNotifier =
|
||||||
ref.watch(AuthenticationNotifier.provider.notifier);
|
ref.watch(AuthenticationNotifier.provider.notifier);
|
||||||
final spotify = ref.watch(spotifyProvider);
|
|
||||||
final albumController = useScrollController();
|
final albumController = useScrollController();
|
||||||
final playlistController = useScrollController();
|
final playlistController = useScrollController();
|
||||||
final artistController = useScrollController();
|
final artistController = useScrollController();
|
||||||
final breakpoint = useBreakpoints();
|
final breakpoint = useBreakpoints();
|
||||||
|
|
||||||
final getVariables = useCallback(
|
final searchTerm = ref.watch(searchTermStateProvider);
|
||||||
() => Tuple2(
|
|
||||||
ref.read(searchTermStateProvider),
|
|
||||||
spotify,
|
|
||||||
),
|
|
||||||
[],
|
|
||||||
);
|
|
||||||
|
|
||||||
final searchTrack = useInfiniteQuery(
|
final searchTrack =
|
||||||
job: useQueries.search.get(SearchType.track.key),
|
useQueries.search.query(ref, searchTerm, SearchType.track);
|
||||||
externalData: Tuple2("", spotify),
|
final searchAlbum =
|
||||||
);
|
useQueries.search.query(ref, searchTerm, SearchType.album);
|
||||||
final searchAlbum = useInfiniteQuery(
|
final searchPlaylist =
|
||||||
job: useQueries.search.get(SearchType.album.key),
|
useQueries.search.query(ref, searchTerm, SearchType.playlist);
|
||||||
externalData: Tuple2("", spotify),
|
final searchArtist =
|
||||||
);
|
useQueries.search.query(ref, searchTerm, SearchType.artist);
|
||||||
final searchPlaylist = useInfiniteQuery(
|
|
||||||
job: useQueries.search.get(SearchType.playlist.key),
|
|
||||||
externalData: Tuple2("", spotify),
|
|
||||||
);
|
|
||||||
final searchArtist = useInfiniteQuery(
|
|
||||||
job: useQueries.search.get(SearchType.artist.key),
|
|
||||||
externalData: Tuple2("", spotify),
|
|
||||||
);
|
|
||||||
|
|
||||||
void onSearch() {
|
void onSearch() {
|
||||||
for (final query in [
|
for (final query in [
|
||||||
@ -75,10 +57,7 @@ class SearchPage extends HookConsumerWidget {
|
|||||||
searchPlaylist,
|
searchPlaylist,
|
||||||
searchArtist,
|
searchArtist,
|
||||||
]) {
|
]) {
|
||||||
query.enabled = false;
|
query.refreshAll();
|
||||||
query.fetched = false;
|
|
||||||
query.setExternalData(getVariables());
|
|
||||||
query.refetchPages();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,10 +75,6 @@ class SearchPage extends HookConsumerWidget {
|
|||||||
),
|
),
|
||||||
color: PlatformTheme.of(context).scaffoldBackgroundColor,
|
color: PlatformTheme.of(context).scaffoldBackgroundColor,
|
||||||
child: PlatformTextField(
|
child: PlatformTextField(
|
||||||
onChanged: (value) {
|
|
||||||
ref.read(searchTermStateProvider.notifier).state =
|
|
||||||
value;
|
|
||||||
},
|
|
||||||
prefixIcon: SpotubeIcons.search,
|
prefixIcon: SpotubeIcons.search,
|
||||||
prefixIconColor: PlatformProperty.only(
|
prefixIconColor: PlatformProperty.only(
|
||||||
ios:
|
ios:
|
||||||
@ -108,6 +83,8 @@ class SearchPage extends HookConsumerWidget {
|
|||||||
).resolve(platform!),
|
).resolve(platform!),
|
||||||
placeholder: "Search...",
|
placeholder: "Search...",
|
||||||
onSubmitted: (value) {
|
onSubmitted: (value) {
|
||||||
|
ref.read(searchTermStateProvider.notifier).state =
|
||||||
|
value;
|
||||||
onSearch();
|
onSearch();
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@ -127,7 +104,7 @@ class SearchPage extends HookConsumerWidget {
|
|||||||
...searchAlbum.pages,
|
...searchAlbum.pages,
|
||||||
...searchPlaylist.pages,
|
...searchPlaylist.pages,
|
||||||
...searchArtist.pages,
|
...searchArtist.pages,
|
||||||
].expand<Page>((page) => page ?? []).toList();
|
].expand<Page>((page) => page).toList();
|
||||||
for (MapEntry<int, Page> page in pages.asMap().entries) {
|
for (MapEntry<int, Page> page in pages.asMap().entries) {
|
||||||
for (var item in page.value.items ?? []) {
|
for (var item in page.value.items ?? []) {
|
||||||
if (item is AlbumSimple) {
|
if (item is AlbumSimple) {
|
||||||
@ -153,12 +130,10 @@ class SearchPage extends HookConsumerWidget {
|
|||||||
children: [
|
children: [
|
||||||
if (tracks.isNotEmpty)
|
if (tracks.isNotEmpty)
|
||||||
PlatformText.headline("Songs"),
|
PlatformText.headline("Songs"),
|
||||||
if (searchTrack.isLoading &&
|
if (searchTrack.isLoadingPage)
|
||||||
!searchTrack.isFetchingNextPage)
|
|
||||||
const PlatformCircularProgressIndicator()
|
const PlatformCircularProgressIndicator()
|
||||||
else if (searchTrack.hasError)
|
else if (searchTrack.hasPageError)
|
||||||
PlatformText(searchTrack
|
PlatformText(searchTrack.errors.lastOrNull
|
||||||
.error?[searchTrack.pageParams.last]
|
|
||||||
?.toString() ??
|
?.toString() ??
|
||||||
"")
|
"")
|
||||||
else
|
else
|
||||||
@ -204,10 +179,10 @@ class SearchPage extends HookConsumerWidget {
|
|||||||
tracks.isNotEmpty)
|
tracks.isNotEmpty)
|
||||||
Center(
|
Center(
|
||||||
child: PlatformTextButton(
|
child: PlatformTextButton(
|
||||||
onPressed: searchTrack.isFetchingNextPage
|
onPressed: searchTrack.isRefreshingPage
|
||||||
? null
|
? null
|
||||||
: () => searchTrack.fetchNextPage(),
|
: () => searchTrack.fetchNext(),
|
||||||
child: searchTrack.isFetchingNextPage
|
child: searchTrack.isRefreshingPage
|
||||||
? const PlatformCircularProgressIndicator()
|
? const PlatformCircularProgressIndicator()
|
||||||
: const PlatformText("Load more"),
|
: const PlatformText("Load more"),
|
||||||
),
|
),
|
||||||
@ -231,7 +206,7 @@ class SearchPage extends HookConsumerWidget {
|
|||||||
controller: playlistController,
|
controller: playlistController,
|
||||||
child: Waypoint(
|
child: Waypoint(
|
||||||
onTouchEdge: () {
|
onTouchEdge: () {
|
||||||
searchPlaylist.fetchNextPage();
|
searchPlaylist.fetchNext();
|
||||||
},
|
},
|
||||||
controller: playlistController,
|
controller: playlistController,
|
||||||
child: SingleChildScrollView(
|
child: SingleChildScrollView(
|
||||||
@ -256,13 +231,11 @@ class SearchPage extends HookConsumerWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (searchPlaylist.isLoading &&
|
if (searchPlaylist.isLoadingPage)
|
||||||
!searchPlaylist.isFetchingNextPage)
|
|
||||||
const PlatformCircularProgressIndicator(),
|
const PlatformCircularProgressIndicator(),
|
||||||
if (searchPlaylist.hasError)
|
if (searchPlaylist.hasPageError)
|
||||||
PlatformText(
|
PlatformText(
|
||||||
searchPlaylist.error?[
|
searchPlaylist.errors.lastOrNull
|
||||||
searchPlaylist.pageParams.last]
|
|
||||||
?.toString() ??
|
?.toString() ??
|
||||||
"",
|
"",
|
||||||
),
|
),
|
||||||
@ -283,7 +256,7 @@ class SearchPage extends HookConsumerWidget {
|
|||||||
child: Waypoint(
|
child: Waypoint(
|
||||||
controller: artistController,
|
controller: artistController,
|
||||||
onTouchEdge: () {
|
onTouchEdge: () {
|
||||||
searchArtist.fetchNextPage();
|
searchArtist.fetchNext();
|
||||||
},
|
},
|
||||||
child: SingleChildScrollView(
|
child: SingleChildScrollView(
|
||||||
scrollDirection: Axis.horizontal,
|
scrollDirection: Axis.horizontal,
|
||||||
@ -311,13 +284,11 @@ class SearchPage extends HookConsumerWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (searchArtist.isLoading &&
|
if (searchArtist.isLoadingPage)
|
||||||
!searchArtist.isFetchingNextPage)
|
|
||||||
const PlatformCircularProgressIndicator(),
|
const PlatformCircularProgressIndicator(),
|
||||||
if (searchArtist.hasError)
|
if (searchArtist.hasPageError)
|
||||||
PlatformText(
|
PlatformText(
|
||||||
searchArtist.error?[
|
searchArtist.errors.lastOrNull
|
||||||
searchArtist.pageParams.last]
|
|
||||||
?.toString() ??
|
?.toString() ??
|
||||||
"",
|
"",
|
||||||
),
|
),
|
||||||
@ -338,7 +309,7 @@ class SearchPage extends HookConsumerWidget {
|
|||||||
child: Waypoint(
|
child: Waypoint(
|
||||||
controller: albumController,
|
controller: albumController,
|
||||||
onTouchEdge: () {
|
onTouchEdge: () {
|
||||||
searchAlbum.fetchNextPage();
|
searchAlbum.fetchNext();
|
||||||
},
|
},
|
||||||
child: SingleChildScrollView(
|
child: SingleChildScrollView(
|
||||||
scrollDirection: Axis.horizontal,
|
scrollDirection: Axis.horizontal,
|
||||||
@ -364,14 +335,11 @@ class SearchPage extends HookConsumerWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (searchAlbum.isLoading &&
|
if (searchAlbum.isLoadingPage)
|
||||||
!searchAlbum.isFetchingNextPage)
|
|
||||||
const PlatformCircularProgressIndicator(),
|
const PlatformCircularProgressIndicator(),
|
||||||
if (searchAlbum.hasError)
|
if (searchAlbum.hasPageError)
|
||||||
PlatformText(
|
PlatformText(
|
||||||
searchAlbum
|
searchAlbum.errors.lastOrNull?.toString() ??
|
||||||
.error?[searchAlbum.pageParams.last]
|
|
||||||
?.toString() ??
|
|
||||||
"",
|
"",
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
@ -11,7 +11,7 @@ class SearchQueries {
|
|||||||
SearchType searchType,
|
SearchType searchType,
|
||||||
) {
|
) {
|
||||||
return useSpotifyInfiniteQuery<List<Page>, dynamic, int>(
|
return useSpotifyInfiniteQuery<List<Page>, dynamic, int>(
|
||||||
"search-query/$query",
|
"search-query/${searchType.key}",
|
||||||
(page, spotify) {
|
(page, spotify) {
|
||||||
if (query.trim().isEmpty) return [];
|
if (query.trim().isEmpty) return [];
|
||||||
final queryString = query;
|
final queryString = query;
|
||||||
@ -20,6 +20,7 @@ class SearchQueries {
|
|||||||
types: [searchType],
|
types: [searchType],
|
||||||
).getPage(10, page);
|
).getPage(10, page);
|
||||||
},
|
},
|
||||||
|
enabled: false,
|
||||||
ref: ref,
|
ref: ref,
|
||||||
initialPage: 0,
|
initialPage: 0,
|
||||||
nextPage: (lastPage, lastPageData) {
|
nextPage: (lastPage, lastPageData) {
|
||||||
|
Loading…
Reference in New Issue
Block a user