feat(blackList): Issue-523

This commit is contained in:
mso7nueh
2025-06-30 14:27:10 +03:00
parent 693260afb6
commit d4a05f47d1
24 changed files with 313 additions and 6 deletions

View File

@@ -166,6 +166,7 @@ class _BlogPostScreenState extends State<BlogPostScreen> {
path: 'blog_post/${(widget.blogPost.id)}',
id: widget.blogPost.id,
feedBlogPostModel: widget.blogPost,
userSlug: widget.blogPost.author.authorSlug,
),
const SizedBox(width: 16),
],

View File

@@ -194,6 +194,7 @@ class _DietPreviewScreenState extends State<DietPreviewScreen> {
isAuthor: widget.diet.author.authorIsMe,
path: 'diet/${widget.diet.slug}',
complainedContentType: ComplainedContent.diet,
userSlug: widget.diet.author.authorSlug,
),
const SizedBox(width: 16),
],

View File

@@ -322,6 +322,7 @@ class _AboutDietScreenState extends State<AboutDietScreen> {
complainedContentType: ComplainedContent.diet,
id: widget.diet.id,
diet: widget.diet,
userSlug: widget.diet.author.authorSlug,
),
const SizedBox(width: 16),
],
@@ -503,6 +504,7 @@ class _AboutDietScreenState extends State<AboutDietScreen> {
complainedContentType: ComplainedContent.diet,
id: widget.diet.id,
diet: widget.diet,
userSlug: widget.diet.author.authorSlug,
),
const SizedBox(width: 16),
],
@@ -530,6 +532,7 @@ class _AboutDietScreenState extends State<AboutDietScreen> {
complainedContentType: ComplainedContent.diet,
id: widget.diet.id,
diet: widget.diet,
userSlug: widget.diet.author.authorSlug,
),
const SizedBox(width: 16),
],

View File

@@ -130,6 +130,7 @@ class _BlogPostWidgetState extends State<BlogPostWidget> {
path: 'blog_post/${(state.feedBlogPostList[widget.index].id)}',
id: state.feedBlogPostList[widget.index].id,
feedBlogPostModel: state.feedBlogPostList[widget.index],
userSlug: state.feedBlogPostList[widget.index].author.authorSlug,
),
],
),

View File

@@ -94,6 +94,7 @@ class _DietsWidgetState extends State<DietsWidget> {
id: widget.diet.id,
complainedContentType: ComplainedContent.diet,
diet: widget.diet,
userSlug: widget.diet.author.authorSlug,
),
),
),

View File

@@ -100,6 +100,7 @@ class _PlanWidgetState extends State<PlanWidget> {
id: widget.plan.id,
slug: widget.plan.slug,
complainedContentType: ComplainedContent.plan,
userSlug: widget.plan.author.authorSlug,
),
),
),

View File

@@ -128,6 +128,7 @@ class _RecipesWidgetState extends State<RecipesWidget> {
slug: widget.recipe.slug,
complainedContentType: ComplainedContent.recipe,
recipe: widget.recipe,
userSlug: widget.recipe.author.authorSlug,
),
),
),

View File

@@ -0,0 +1,14 @@
import 'package:eatvio_app/features/profile/models/profile_model.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
part 'blocked_users_model.g.dart';
part 'blocked_users_model.freezed.dart';
@freezed
abstract class BlockedUsersModel with _$BlockedUsersModel {
const factory BlockedUsersModel({
@JsonKey(name: 'data') required List<ProfileModel> profilesList,
}) = _BlockedUsersModel;
factory BlockedUsersModel.fromJson(Map<String, Object?> json) => _$BlockedUsersModelFromJson(json);
}

View File

@@ -0,0 +1,29 @@
import 'package:eatvio_app/features/menu/presentation/blocked_user_cubit/blocked_users_state.dart';
import 'package:eatvio_app/features/menu/presentation/repositories/blocked_users_repository.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class BlockedUsersCubit extends Cubit<BlockedUsersState> {
final BlockedUsersRepository blockedUsersRepository;
BlockedUsersCubit({
required this.blockedUsersRepository,
}) : super(const BlockedUsersState());
getBlockedUsers() async {
try {
emit(BlockedUsersState.loaded(profilesList: await blockedUsersRepository.getBlockedUsers()));
} catch (e, st) {
emit(BlockedUsersState.error(errorMessage: '$e $st'));
}
}
blockUser(String slug) async {
await blockedUsersRepository.blockUserBySlug(slug);
await getBlockedUsers();
}
unblockUser(String slug) async {
await blockedUsersRepository.unblockUserBySlug(slug);
await getBlockedUsers();
}
}

View File

@@ -0,0 +1,15 @@
import 'package:eatvio_app/features/profile/models/profile_model.dart';
import 'package:flutter/foundation.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
part 'blocked_users_state.freezed.dart';
@freezed
abstract class BlockedUsersState with _$BlockedUsersState {
const factory BlockedUsersState() = _BlockedUsersState;
const factory BlockedUsersState.loading() = BlockedUsersStateLoading;
const factory BlockedUsersState.loaded({required List<ProfileModel> profilesList}) = BlockedUsersStateLoaded;
const factory BlockedUsersState.error({
required String errorMessage,
}) = BlockedUsersStateError;
}

View File

@@ -0,0 +1,43 @@
import 'package:eatvio_app/core/locator_service.dart';
import 'package:eatvio_app/features/menu/presentation/blocked_user_cubit/blocked_users_cubit.dart';
import 'package:eatvio_app/features/menu/presentation/blocked_user_cubit/blocked_users_state.dart';
import 'package:eatvio_app/features/menu/presentation/widgets/blocked_user_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class BlockedUsersScreen extends StatefulWidget {
const BlockedUsersScreen({super.key});
@override
State<BlockedUsersScreen> createState() => _BlockedUsersScreenState();
}
class _BlockedUsersScreenState extends State<BlockedUsersScreen> {
@override
Widget build(BuildContext context) {
return BlocProvider<BlockedUsersCubit>(
create: (BuildContext context) => sl<BlockedUsersCubit>()..getBlockedUsers(),
child: BlocBuilder<BlockedUsersCubit, BlockedUsersState>(
builder: (BuildContext context, BlockedUsersState state) {
if (state is BlockedUsersStateLoaded) {
return Scaffold(
appBar: AppBar(
title: const Text('Чёрный список'),
),
body: ListView.builder(
itemBuilder: (context, index) => BlockedUserWidget(profile: state.profilesList[index]),
itemCount: state.profilesList.length,
),
);
} else {
return const Scaffold(
body: Center(
child: CircularProgressIndicator(),
),
);
}
},
),
);
}
}

View File

@@ -53,6 +53,8 @@ class MenuScreen extends StatelessWidget {
_tile(leading: ImageConstant.icnGlossary, title: 'Глоссарий', onTap: () => GoRouter.of(context).push('/glossary-screen')),
_divider(context),
_tile(leading: ImageConstant.icnSupport, title: 'Поддержка', onTap: () => GoRouter.of(context).push('/support-screen')),
_divider(context),
_tile(leading: 'assets/icons/blocked_users.svg', title: 'Чёрный список', onTap: () => GoRouter.of(context).pushNamed('blockedUsersScreen')),
// _divider(context),
// _tile(
// leading: ImageConstant.icnDevTools,

View File

@@ -0,0 +1,47 @@
import 'dart:developer';
import 'package:eatvio_app/features/menu/services/blocked_users_service.dart';
import 'package:eatvio_app/features/profile/models/profile_model.dart';
class BlockedUsersRepository {
final BlockedUserService blockedUserService;
BlockedUsersRepository({
required this.blockedUserService,
});
Future<List<ProfileModel>> getBlockedUsers() async {
try {
return (await blockedUserService.getBlockedUsers()).profilesList;
} catch (e, st) {
log(e.toString(), stackTrace: st);
rethrow;
}
}
blockUserBySlug(String slug) async {
try {
return await blockedUserService.blockUser(
data: {
'slug': slug,
},
);
} catch (e, st) {
log(e.toString(), stackTrace: st);
rethrow;
}
}
unblockUserBySlug(String slug) async {
try {
return await blockedUserService.unblockUser(
data: {
'slug': slug,
},
);
} catch (e, st) {
log(e.toString(), stackTrace: st);
rethrow;
}
}
}

View File

@@ -0,0 +1,83 @@
import 'package:eatvio_app/core/const.dart';
import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart';
import 'package:eatvio_app/features/menu/presentation/blocked_user_cubit/blocked_users_cubit.dart';
import 'package:eatvio_app/features/profile/models/profile_model.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
class BlockedUserWidget extends StatefulWidget {
final ProfileModel profile;
const BlockedUserWidget({super.key, required this.profile});
@override
State<BlockedUserWidget> createState() => _BlockedUserWidgetState();
}
class _BlockedUserWidgetState extends State<BlockedUserWidget> {
@override
Widget build(BuildContext context) {
return InkWell(
onTap: () => GoRouter.of(context).pushNamed(
'profileScreen',
extra: Author(
authorSlug: widget.profile.slug,
authorName: widget.profile.name,
authorProfileIcon: widget.profile.profilePhotoUrl,
authorIsMe: false,
isEntitySubscribedByMe: false,
),
),
child: Ink(
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 16),
child: Row(
children: [
CircleAvatar(
foregroundImage: NetworkImage(baseUrl + widget.profile.profilePhotoUrl),
backgroundImage: const AssetImage('assets/images/no_avatar.png'),
radius: 28,
),
const SizedBox(width: 12),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Text(
widget.profile.name,
style: const TextStyle(
color: Color(0xFF323F4B),
fontSize: 16,
fontWeight: FontWeight.w600,
height: 1,
),
),
],
),
const Spacer(),
InkWell(
onTap: () {
context.read<BlockedUsersCubit>().unblockUser(widget.profile.slug);
},
borderRadius: BorderRadius.circular(4),
child: Ink(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
decoration: BoxDecoration(
color: const Color(0xFFF1F2F6),
borderRadius: BorderRadius.circular(4),
),
child: const Text(
'Убрать',
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
color: Color(0xFF6D6F71),
),
),
),
),
],
),
),
);
}
}

View File

@@ -1,4 +1,5 @@
import 'package:dio/dio.dart';
import 'package:eatvio_app/features/menu/models/blocked_users_model.dart';
import 'package:retrofit/retrofit.dart';
part 'blocked_users_service.g.dart';
@@ -8,17 +9,15 @@ abstract class BlockedUserService {
factory BlockedUserService(Dio dio, {String baseUrl}) = _BlockedUserService;
@GET('/api/blocked_users')
Future<void> getBlockedUsers();
Future<BlockedUsersModel> getBlockedUsers();
@POST('/api/blocked_users/block')
Future<void> blockUser({
String? slug,
String? id,
@Body() required Map<String, Object?> data,
});
@POST('/api/blocked_users/unblock')
Future<void> unblockUser({
String? slug,
String? id,
@Body() required Map<String, Object?> data,
});
}

View File

@@ -116,6 +116,7 @@ class _AboutPlanScreenState extends State<AboutPlanScreen> {
path: 'plan/${widget.plan.slug}',
complainedContentType: ComplainedContent.plan,
slug: widget.plan.slug,
userSlug: widget.plan.author.authorSlug,
),
const SizedBox(width: 16),
],
@@ -146,6 +147,7 @@ class _AboutPlanScreenState extends State<AboutPlanScreen> {
path: 'plan/${widget.plan.slug}',
complainedContentType: ComplainedContent.plan,
slug: widget.plan.slug,
userSlug: widget.plan.author.authorSlug,
),
const SizedBox(width: 16),
],
@@ -365,6 +367,7 @@ class _AboutPlanScreenState extends State<AboutPlanScreen> {
path: 'plan/${widget.plan.slug}',
complainedContentType: ComplainedContent.plan,
slug: widget.plan.slug,
userSlug: widget.plan.author.authorSlug,
),
const SizedBox(width: 16),
],

View File

@@ -14,6 +14,7 @@ import 'package:eatvio_app/features/chat/presentation/pages/photo_view_screen.da
import 'package:eatvio_app/features/complaining/presentation/complaining_bottom_sheet.dart';
import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart';
import 'package:eatvio_app/features/feed/presentation/widgets/plan_widget.dart';
import 'package:eatvio_app/features/menu/presentation/blocked_user_cubit/blocked_users_cubit.dart';
import 'package:eatvio_app/features/profile/models/circumference_model.dart';
import 'package:eatvio_app/features/profile/models/weight_model.dart';
import 'package:eatvio_app/features/profile/presentation/bloc/plans_cubit/plans_cubit.dart';
@@ -1175,6 +1176,8 @@ class _ProfileScreenState extends State<ProfileScreen> {
sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size,
),
);
} else if (value == 'block') {
sl<BlockedUsersCubit>().blockUser(state.profile.slug);
} else {
showModalBottomSheet(
context: context,
@@ -1196,6 +1199,11 @@ class _ProfileScreenState extends State<ProfileScreen> {
value: 'complain',
child: Text('Пожаловаться'),
),
if (widget.author != null)
const PopupMenuItem(
value: 'block',
child: Text('Заблокировать'),
),
],
child: const Icon(Icons.more_horiz_rounded),
),

View File

@@ -102,6 +102,7 @@ class _ProfileBlogPostWidgetState extends State<ProfileBlogPostWidget> {
path: 'blog_post/${(state.blogPosts[widget.index].id)}',
id: state.blogPosts[widget.index].id,
feedBlogPostModel: state.blogPosts[widget.index],
userSlug: state.blogPosts[widget.index].author.authorSlug,
),
],
),

View File

@@ -219,6 +219,7 @@ class _AboutRecipeScreenState extends State<AboutRecipeScreen> {
complainedContentType: ComplainedContent.recipe,
slug: widget.recipe.slug,
recipe: widget.recipe,
userSlug: widget.recipe.author.authorSlug,
),
const SizedBox(width: 16),
],
@@ -403,6 +404,7 @@ class _AboutRecipeScreenState extends State<AboutRecipeScreen> {
complainedContentType: ComplainedContent.recipe,
slug: widget.recipe.slug,
recipe: widget.recipe,
userSlug: widget.recipe.author.authorSlug,
),
const SizedBox(width: 16),
],
@@ -428,6 +430,7 @@ class _AboutRecipeScreenState extends State<AboutRecipeScreen> {
complainedContentType: ComplainedContent.recipe,
slug: widget.recipe.slug,
recipe: widget.recipe,
userSlug: widget.recipe.author.authorSlug,
),
const SizedBox(width: 16),
],