bookmarks search now works
This commit is contained in:
parent
d0a4c6ea0a
commit
aba3d69dab
|
|
@ -9,20 +9,27 @@ class BookmarksState extends CoreProvier {
|
|||
final List<OverviewData> bookmarks = [];
|
||||
String search = '';
|
||||
String lastSearch = '';
|
||||
int page = 1;
|
||||
int lastPage = 1;
|
||||
|
||||
bool get searching => search != '';
|
||||
|
||||
Future<void> getBookmarks() async {
|
||||
Future<void> getBookmarks({required int page}) async {
|
||||
if (search != '') {
|
||||
lastSearch = search;
|
||||
}
|
||||
if (page == 1) {
|
||||
bookmarks.clear();
|
||||
}
|
||||
this.page = page;
|
||||
appState = AppState.busy;
|
||||
final service = RequestService(RequestHelper.bookmarks());
|
||||
final service =
|
||||
RequestService(RequestHelper.bookmarks(page: page, search: search));
|
||||
await service.httpGet();
|
||||
|
||||
if (service.isSuccess) {
|
||||
lastPage = service.result['lastPage'];
|
||||
final marks = service.result['contents'];
|
||||
bookmarks.clear();
|
||||
for (var i = 0; i < marks.length; i++) {
|
||||
bookmarks.add(OverviewData.fromJson(marks[i]));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ class _BookmarksState extends State<Bookmarks> {
|
|||
@override
|
||||
void initState() {
|
||||
Future.delayed(Duration.zero, () {
|
||||
context.read<BookmarksState>().getBookmarks();
|
||||
context.read<BookmarksState>().getBookmarks(page: 1);
|
||||
});
|
||||
super.initState();
|
||||
}
|
||||
|
|
@ -74,14 +74,14 @@ class _BookmarksState extends State<Bookmarks> {
|
|||
),
|
||||
const DidvanDivider(),
|
||||
MenuItem(
|
||||
onTap: () => _onCategorySelected('videos'),
|
||||
onTap: () => _onCategorySelected('video'),
|
||||
title: 'ویدئوها',
|
||||
icon: DidvanIcons.video_regular,
|
||||
iconSize: 24,
|
||||
),
|
||||
const DidvanDivider(),
|
||||
MenuItem(
|
||||
onTap: () => _onCategorySelected('podcasts'),
|
||||
onTap: () => _onCategorySelected('podcast'),
|
||||
title: 'پادکستها',
|
||||
icon: DidvanIcons.podcast_regular,
|
||||
iconSize: 24,
|
||||
|
|
@ -103,26 +103,33 @@ class _BookmarksState extends State<Bookmarks> {
|
|||
SliverStateHandler<BookmarksState>(
|
||||
state: state,
|
||||
centerEmptyState: state.searching,
|
||||
builder: (context, state, index) => MultitypeOverview(
|
||||
builder: (context, state, index) {
|
||||
index++;
|
||||
if (index % 15 == 0 && state.lastPage != state.page) {
|
||||
state.getBookmarks(page: state.page + 1);
|
||||
}
|
||||
index--;
|
||||
return MultitypeOverview(
|
||||
item: state.bookmarks[index],
|
||||
onMarkChanged: state.onMarkChanged,
|
||||
hasUnmarkConfirmation: true,
|
||||
),
|
||||
);
|
||||
},
|
||||
placeholder: MultitypeOverview.placeholder,
|
||||
itemPadding: const EdgeInsets.only(bottom: 8),
|
||||
emptyState: state.searching
|
||||
? EmptyResult(onNewSearch: _focuseNode.requestFocus)
|
||||
: const EmptyList(),
|
||||
enableEmptyState: state.bookmarks.isEmpty,
|
||||
childCount: state.bookmarks.length,
|
||||
onRetry: state.getBookmarks,
|
||||
childCount:
|
||||
state.bookmarks.length + (state.page != state.lastPage ? 1 : 0),
|
||||
onRetry: () => state.getBookmarks(page: state.page),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
void _onCategorySelected(String type) {
|
||||
if (type != 'radar' && type != 'news') return;
|
||||
FocusScope.of(context).unfocus();
|
||||
Navigator.of(context).pushNamed(Routes.filteredBookmarks, arguments: type);
|
||||
}
|
||||
|
|
@ -135,7 +142,7 @@ class _BookmarksState extends State<Bookmarks> {
|
|||
_timer?.cancel();
|
||||
_timer = Timer(const Duration(seconds: 1), () {
|
||||
state.search = value;
|
||||
state.getBookmarks();
|
||||
state.getBookmarks(page: 1);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ class _FilteredBookmarksState extends State<FilteredBookmarks> {
|
|||
void initState() {
|
||||
Future.delayed(
|
||||
Duration.zero,
|
||||
context.read<FilteredBookmarksState>().getBookmarks,
|
||||
() => context.read<FilteredBookmarksState>().getBookmarks(page: 1),
|
||||
);
|
||||
super.initState();
|
||||
}
|
||||
|
|
@ -54,6 +54,11 @@ class _FilteredBookmarksState extends State<FilteredBookmarks> {
|
|||
placeholder: RadarOverview.placeholder,
|
||||
emptyState: const EmptyList(),
|
||||
builder: (context, state, index) {
|
||||
index++;
|
||||
if (index % 15 == 0 && state.lastPage != state.page) {
|
||||
state.getBookmarks(page: state.page + 1);
|
||||
}
|
||||
index--;
|
||||
if (state.type == 'radar') {
|
||||
return RadarOverview(
|
||||
radar: state.bookmarks[index],
|
||||
|
|
@ -69,7 +74,7 @@ class _FilteredBookmarksState extends State<FilteredBookmarks> {
|
|||
);
|
||||
},
|
||||
childCount: state.bookmarks.length,
|
||||
onRetry: () => state.getBookmarks(),
|
||||
onRetry: () => state.getBookmarks(page: state.page),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
|
|
|||
|
|
@ -10,24 +10,42 @@ class FilteredBookmarksState extends CoreProvier {
|
|||
String lastSearch = '';
|
||||
final List<OverviewData> bookmarks = [];
|
||||
final String type;
|
||||
int page = 1;
|
||||
int lastPage = 1;
|
||||
|
||||
FilteredBookmarksState(this.type);
|
||||
|
||||
bool get searching => search != '';
|
||||
|
||||
Future<void> getBookmarks() async {
|
||||
Future<void> getBookmarks({required int page}) async {
|
||||
if (search != '') {
|
||||
lastSearch = search;
|
||||
}
|
||||
if (page == 1) {
|
||||
bookmarks.clear();
|
||||
}
|
||||
this.page = page;
|
||||
appState = AppState.busy;
|
||||
String typeString = '';
|
||||
if (type == 'video' || type == 'podcast') {
|
||||
typeString = 'studios';
|
||||
} else if (type == 'news') {
|
||||
typeString = type;
|
||||
} else {
|
||||
typeString = type + 's';
|
||||
}
|
||||
final service = RequestService(
|
||||
RequestHelper.bookmarks(type: type == 'news' ? type : type + 's'),
|
||||
RequestHelper.bookmarks(
|
||||
type: typeString,
|
||||
page: page,
|
||||
studioType: type == 'podcast' || type == 'video' ? type : null,
|
||||
),
|
||||
);
|
||||
await service.httpGet();
|
||||
|
||||
if (service.isSuccess) {
|
||||
final marks = service.result[type != 'news' ? type + 's' : type];
|
||||
bookmarks.clear();
|
||||
lastPage = service.result['lastPage'];
|
||||
final marks = service.result[typeString];
|
||||
for (var i = 0; i < marks.length; i++) {
|
||||
bookmarks.add(OverviewData.fromJson(marks[i]));
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue