forked from eatvio/eatvio_app
feat(profile): add search in subs
This commit is contained in:
@@ -9,19 +9,19 @@ class SubCubit extends Cubit<SubState> {
|
||||
required this.profileRepository,
|
||||
}) : super(const SubState());
|
||||
|
||||
getSubscriptions(String slug) async {
|
||||
getSubscriptions(String slug, [String? query]) async {
|
||||
emit(const SubState.loading());
|
||||
try {
|
||||
emit(SubState.loaded(subList: await profileRepository.getSubscriptionsBySlug(slug)));
|
||||
emit(SubState.loaded(subList: await profileRepository.getSubscriptionsBySlug(slug, query)));
|
||||
} catch (e) {
|
||||
emit(SubState.error(errorMessage: e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
getSubscribers(String slug) async {
|
||||
getSubscribers(String slug, [String? query]) async {
|
||||
emit(const SubState.loading());
|
||||
try {
|
||||
emit(SubState.loaded(subList: await profileRepository.getSubscribersBySlug(slug)));
|
||||
emit(SubState.loaded(subList: await profileRepository.getSubscribersBySlug(slug, query)));
|
||||
} catch (e) {
|
||||
emit(SubState.error(errorMessage: e.toString()));
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import 'package:easy_debounce/easy_debounce.dart';
|
||||
import 'package:eatvio_app/core/locator_service.dart';
|
||||
import 'package:eatvio_app/core/widgets/loader.dart';
|
||||
import 'package:eatvio_app/features/profile/presentation/bloc/sub_cubit/sub_cubit.dart';
|
||||
import 'package:eatvio_app/features/profile/presentation/bloc/sub_cubit/sub_state.dart';
|
||||
import 'package:eatvio_app/features/profile/presentation/widgets/sub_widget.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
@@ -39,6 +41,33 @@ class _SubsScreenState extends State<SubsScreen> {
|
||||
builder: (BuildContext context, SubState state) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
bottom: PreferredSize(
|
||||
preferredSize: Size(MediaQuery.of(context).size.width, 40),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
child: CupertinoSearchTextField(
|
||||
prefixIcon: Icon(Icons.search),
|
||||
placeholder: 'Поиск',
|
||||
onChanged: (query) {
|
||||
if (query.length > 2) {
|
||||
EasyDebounce.debounce(
|
||||
'searchSubs',
|
||||
Duration(milliseconds: 300),
|
||||
() {
|
||||
widget.subType == SubType.Subscriptions
|
||||
? (context.read<SubCubit>().getSubscriptions(widget.slug, query))
|
||||
: (context.read<SubCubit>().getSubscribers(widget.slug, query));
|
||||
},
|
||||
);
|
||||
} else {
|
||||
widget.subType == SubType.Subscriptions
|
||||
? (context.read<SubCubit>().getSubscriptions(widget.slug))
|
||||
: (context.read<SubCubit>().getSubscribers(widget.slug));
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
title: Text(
|
||||
widget.subType == SubType.Subscriptions ? 'Подписки' : 'Подписчики',
|
||||
),
|
||||
|
||||
@@ -114,17 +114,17 @@ class ProfileRepository {
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<SubModel>> getSubscribersBySlug(String slug) async {
|
||||
Future<List<SubModel>> getSubscribersBySlug(String slug, [String? query]) async {
|
||||
try {
|
||||
return (await profileService.getSubscribers(slug: slug)).data;
|
||||
return (await profileService.getSubscribers(slug: slug, query: query)).data;
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<SubModel>> getSubscriptionsBySlug(String slug) async {
|
||||
Future<List<SubModel>> getSubscriptionsBySlug(String slug, [String? query]) async {
|
||||
try {
|
||||
return (await profileService.getSubscriptions(slug: slug)).data;
|
||||
return (await profileService.getSubscriptions(slug: slug, query: query)).data;
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
|
||||
@@ -64,11 +64,13 @@ abstract class ProfileService {
|
||||
@GET('/api/profile/{slug}/subscribers')
|
||||
Future<SubPaginationModel> getSubscribers({
|
||||
@Path() required String slug,
|
||||
@Query('filters[name][\$startsWith]') String? query,
|
||||
});
|
||||
|
||||
@GET('/api/profile/{slug}/subscriptions')
|
||||
Future<SubPaginationModel> getSubscriptions({
|
||||
@Path() required String slug,
|
||||
@Query('filters[name][\$startsWith]') String? query,
|
||||
});
|
||||
|
||||
@POST('/api/profile/subscribe/{slug}')
|
||||
|
||||
@@ -377,9 +377,15 @@ class _ProfileService implements ProfileService {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<SubPaginationModel> getSubscribers({required String slug}) async {
|
||||
Future<SubPaginationModel> getSubscribers({
|
||||
required String slug,
|
||||
String? query,
|
||||
}) async {
|
||||
final _extra = <String, dynamic>{};
|
||||
final queryParameters = <String, dynamic>{};
|
||||
final queryParameters = <String, dynamic>{
|
||||
r'filters[name][$startsWith]': query
|
||||
};
|
||||
queryParameters.removeWhere((k, v) => v == null);
|
||||
final _headers = <String, dynamic>{};
|
||||
const Map<String, dynamic>? _data = null;
|
||||
final _options = _setStreamType<SubPaginationModel>(Options(
|
||||
@@ -410,9 +416,15 @@ class _ProfileService implements ProfileService {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<SubPaginationModel> getSubscriptions({required String slug}) async {
|
||||
Future<SubPaginationModel> getSubscriptions({
|
||||
required String slug,
|
||||
String? query,
|
||||
}) async {
|
||||
final _extra = <String, dynamic>{};
|
||||
final queryParameters = <String, dynamic>{};
|
||||
final queryParameters = <String, dynamic>{
|
||||
r'filters[name][$startsWith]': query
|
||||
};
|
||||
queryParameters.removeWhere((k, v) => v == null);
|
||||
final _headers = <String, dynamic>{};
|
||||
const Map<String, dynamic>? _data = null;
|
||||
final _options = _setStreamType<SubPaginationModel>(Options(
|
||||
|
||||
Reference in New Issue
Block a user