Skip to content

Commit

Permalink
Added post update validations
Browse files Browse the repository at this point in the history
  • Loading branch information
kumarpalsinh25 committed Feb 21, 2025
1 parent f246177 commit d8e8c11
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 51 deletions.
114 changes: 63 additions & 51 deletions app/lib/features/news/pages/add_news/add_news_post_to_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import 'package:acter/features/news/model/keys.dart';
import 'package:acter/features/news/providers/news_post_editor_providers.dart';
import 'package:acter/features/space/widgets/space_sections/section_header.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

enum PostType { story, boost }
enum PostTypeSelection { story, boost, none }

class AddNewsPostToPage extends ConsumerStatefulWidget {
final String? initialSelectedSpace;
Expand All @@ -23,23 +24,27 @@ class AddNewsPostToPage extends ConsumerStatefulWidget {
}

class _AddNewsPostToPageState extends ConsumerState<AddNewsPostToPage> {
PostType selectedOption = PostType.story;
ValueNotifier<PostTypeSelection> selectedPostType =
ValueNotifier(PostTypeSelection.none);
ValueNotifier<bool> canPostBoost = ValueNotifier(false);
ValueNotifier<bool> canPostStories = ValueNotifier(false);

@override

Check warning on line 32 in app/lib/features/news/pages/add_news/add_news_post_to_page.dart

View check run for this annotation

Codecov / codecov/patch

app/lib/features/news/pages/add_news/add_news_post_to_page.dart#L32

Added line #L32 was not covered by tests
Widget build(BuildContext context) {
//Initialize variables based on the selected space
final selectedSpaceId = ref.read(newsStateProvider).newsPostSpaceId;

Check warning on line 35 in app/lib/features/news/pages/add_news/add_news_post_to_page.dart

View check run for this annotation

Codecov / codecov/patch

app/lib/features/news/pages/add_news/add_news_post_to_page.dart#L35

Added line #L35 was not covered by tests
if (selectedSpaceId != null) {
final membership =
ref.watch(roomMembershipProvider(selectedSpaceId)).valueOrNull;
canPostBoost.value = membership?.canString('CanPostNews') == true;
if (canPostBoost.value == false) {
selectedOption = PostType.story;
}
canPostStories.value = membership?.canString('CanPostStories') == true;
selectedPostType.value = PostTypeSelection.none;

Check warning on line 41 in app/lib/features/news/pages/add_news/add_news_post_to_page.dart

View check run for this annotation

Codecov / codecov/patch

app/lib/features/news/pages/add_news/add_news_post_to_page.dart#L38-L41

Added lines #L38 - L41 were not covered by tests
}

//Start build UI
return Scaffold(
appBar: appBarUI(),
body: postToBodyUI(),
body: postToBodyUI(selectedSpaceId),

Check warning on line 47 in app/lib/features/news/pages/add_news/add_news_post_to_page.dart

View check run for this annotation

Codecov / codecov/patch

app/lib/features/news/pages/add_news/add_news_post_to_page.dart#L45-L47

Added lines #L45 - L47 were not covered by tests
);
}

Expand All @@ -48,39 +53,55 @@ class _AddNewsPostToPageState extends ConsumerState<AddNewsPostToPage> {
return AppBar(title: Text(lang.postTo));

Check warning on line 53 in app/lib/features/news/pages/add_news/add_news_post_to_page.dart

View check run for this annotation

Codecov / codecov/patch

app/lib/features/news/pages/add_news/add_news_post_to_page.dart#L51-L53

Added lines #L51 - L53 were not covered by tests
}

Widget postToBodyUI() {
Widget postToBodyUI(String? selectedSpaceId) {
final lang = L10n.of(context);
return Column(

Check warning on line 58 in app/lib/features/news/pages/add_news/add_news_post_to_page.dart

View check run for this annotation

Codecov / codecov/patch

app/lib/features/news/pages/add_news/add_news_post_to_page.dart#L56-L58

Added lines #L56 - L58 were not covered by tests
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
spaceSelector(),
SectionHeader(title: lang.select),
postOptionItemUI(
true,
lang.story,
lang.storyInfo,
Icons.amp_stories,
PostType.story,
ValueListenableBuilder<bool>(
valueListenable: canPostStories,
builder: (context, canPostStories, child) {
return postOptionItemUI(

Check warning on line 66 in app/lib/features/news/pages/add_news/add_news_post_to_page.dart

View check run for this annotation

Codecov / codecov/patch

app/lib/features/news/pages/add_news/add_news_post_to_page.dart#L60-L66

Added lines #L60 - L66 were not covered by tests
isEnable: canPostStories,
title: lang.story,
description: lang.storyInfo,

Check warning on line 69 in app/lib/features/news/pages/add_news/add_news_post_to_page.dart

View check run for this annotation

Codecov / codecov/patch

app/lib/features/news/pages/add_news/add_news_post_to_page.dart#L68-L69

Added lines #L68 - L69 were not covered by tests
iconData: Icons.amp_stories,
postTypeSelection: PostTypeSelection.story,
);
},
),
ValueListenableBuilder<bool>(
valueListenable: canPostBoost,
builder: (context, canPostBoost, child) {
return postOptionItemUI(

Check warning on line 78 in app/lib/features/news/pages/add_news/add_news_post_to_page.dart

View check run for this annotation

Codecov / codecov/patch

app/lib/features/news/pages/add_news/add_news_post_to_page.dart#L75-L78

Added lines #L75 - L78 were not covered by tests
canPostBoost,
lang.boost,
lang.boostInfo,
Icons.rocket_launch_sharp,
PostType.boost,
isEnable: canPostBoost,
title: lang.boost,
description: lang.boostInfo,

Check warning on line 81 in app/lib/features/news/pages/add_news/add_news_post_to_page.dart

View check run for this annotation

Codecov / codecov/patch

app/lib/features/news/pages/add_news/add_news_post_to_page.dart#L80-L81

Added lines #L80 - L81 were not covered by tests
iconData: Icons.rocket_launch_sharp,
postTypeSelection: PostTypeSelection.boost,
);
},
),
Spacer(),
Padding(

Check warning on line 88 in app/lib/features/news/pages/add_news/add_news_post_to_page.dart

View check run for this annotation

Codecov / codecov/patch

app/lib/features/news/pages/add_news/add_news_post_to_page.dart#L87-L88

Added lines #L87 - L88 were not covered by tests
padding: const EdgeInsets.all(18),
child: ActerPrimaryActionButton(
onPressed: () => selectedOption == PostType.story
? sendStory(context, ref)
: sendNews(context, ref),
onPressed: () {
if (selectedSpaceId == null || selectedSpaceId.isEmpty) {
EasyLoading.showToast(lang.pleaseSelectSpace);
} else if (canPostBoost.value == false &&
canPostStories.value == false) {
EasyLoading.showToast(lang.notHaveBoostStoryPermission);
} else if (selectedPostType.value == PostTypeSelection.none) {
EasyLoading.showToast(lang.pleaseSelectePostType);
} else if (selectedPostType.value == PostTypeSelection.story) {
sendStory(context, ref);
} else if (selectedPostType.value == PostTypeSelection.boost) {
sendNews(context, ref);

Check warning on line 102 in app/lib/features/news/pages/add_news/add_news_post_to_page.dart

View check run for this annotation

Codecov / codecov/patch

app/lib/features/news/pages/add_news/add_news_post_to_page.dart#L90-L102

Added lines #L90 - L102 were not covered by tests
}
},
child: Text(lang.post.toUpperCase()),

Check warning on line 105 in app/lib/features/news/pages/add_news/add_news_post_to_page.dart

View check run for this annotation

Codecov / codecov/patch

app/lib/features/news/pages/add_news/add_news_post_to_page.dart#L105

Added line #L105 was not covered by tests
),
),
Expand Down Expand Up @@ -125,22 +146,16 @@ class _AddNewsPostToPageState extends ConsumerState<AddNewsPostToPage> {
);
}

Widget postOptionItemUI(
bool isEnable,
String title,
String description,
IconData iconData,
PostType optionValue,
) {
Widget postOptionItemUI({

Check warning on line 149 in app/lib/features/news/pages/add_news/add_news_post_to_page.dart

View check run for this annotation

Codecov / codecov/patch

app/lib/features/news/pages/add_news/add_news_post_to_page.dart#L149

Added line #L149 was not covered by tests
required bool isEnable,
required String title,
required String description,
required IconData iconData,
required PostTypeSelection postTypeSelection,
}) {
final color = !isEnable ? Theme.of(context).disabledColor : null;
return InkWell(
onTap: isEnable
? () {
setState(() {
selectedOption = optionValue;
});
}
: null,
onTap: isEnable ? () => selectedPostType.value = postTypeSelection : null,
child: Padding(

Check warning on line 159 in app/lib/features/news/pages/add_news/add_news_post_to_page.dart

View check run for this annotation

Codecov / codecov/patch

app/lib/features/news/pages/add_news/add_news_post_to_page.dart#L156-L159

Added lines #L156 - L159 were not covered by tests
padding: const EdgeInsets.all(18),
child: Row(

Check warning on line 161 in app/lib/features/news/pages/add_news/add_news_post_to_page.dart

View check run for this annotation

Codecov / codecov/patch

app/lib/features/news/pages/add_news/add_news_post_to_page.dart#L161

Added line #L161 was not covered by tests
Expand All @@ -152,10 +167,7 @@ class _AddNewsPostToPageState extends ConsumerState<AddNewsPostToPage> {
child: Column(

Check warning on line 167 in app/lib/features/news/pages/add_news/add_news_post_to_page.dart

View check run for this annotation

Codecov / codecov/patch

app/lib/features/news/pages/add_news/add_news_post_to_page.dart#L163-L167

Added lines #L163 - L167 were not covered by tests
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
title,
style: TextStyle(color: color),
),
Text(title, style: TextStyle(color: color)),
Text(

Check warning on line 171 in app/lib/features/news/pages/add_news/add_news_post_to_page.dart

View check run for this annotation

Codecov / codecov/patch

app/lib/features/news/pages/add_news/add_news_post_to_page.dart#L169-L171

Added lines #L169 - L171 were not covered by tests
description,
style: Theme.of(context)
Expand All @@ -166,18 +178,18 @@ class _AddNewsPostToPageState extends ConsumerState<AddNewsPostToPage> {
],
),
),
Radio(
value: optionValue,
groupValue: selectedOption,
onChanged: isEnable
? (value) {
setState(() {
selectedOption = value as PostType;
});
}
: null,
focusNode: FocusNode(),
toggleable: isEnable,
ValueListenableBuilder<PostTypeSelection>(
valueListenable: selectedPostType,
builder: (context, postType, child) {
return Radio(

Check warning on line 184 in app/lib/features/news/pages/add_news/add_news_post_to_page.dart

View check run for this annotation

Codecov / codecov/patch

app/lib/features/news/pages/add_news/add_news_post_to_page.dart#L181-L184

Added lines #L181 - L184 were not covered by tests
value: postTypeSelection,
groupValue: postType,
onChanged: isEnable
? (value) => selectedPostType.value = postType

Check warning on line 188 in app/lib/features/news/pages/add_news/add_news_post_to_page.dart

View check run for this annotation

Codecov / codecov/patch

app/lib/features/news/pages/add_news/add_news_post_to_page.dart#L188

Added line #L188 was not covered by tests
: null,
toggleable: isEnable,
);
},
),
],
),
Expand Down
2 changes: 2 additions & 0 deletions app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -2347,6 +2347,8 @@
"story": "Story",
"storyInfo": "Everyone can see, this is from you. It disappears in 14 days",
"boostInfo": "Important News. Sends a push notification to 17 members",
"notHaveBoostStoryPermission": "You do not have permission to post Boost or Story in selected space",
"pleaseSelectePostType": "Please select post type",
"postTo": "Post to",
"post": "Post",
"unableToLoadFile": "Unable to load file",
Expand Down

0 comments on commit d8e8c11

Please sign in to comment.