Skip to content

Commit 060ef6c

Browse files
authored
Merge pull request #3156 from acterglobal/anisha/improve-editing-screen
Make HTML Description dialog editable and improve UI styling of title and description dialog.
2 parents 349a1d7 + a1495be commit 060ef6c

File tree

9 files changed

+304
-46
lines changed

9 files changed

+304
-46
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- [Fix] : Fixed description editing, enhanced dialog UI, and require users to press Save or Cancel (dialog no longer draggable).

app/lib/common/themes/components/button_theme.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ import 'package:flutter/material.dart';
66

77
ElevatedButtonThemeData elevatedButtonTheme() => ElevatedButtonThemeData(
88
style: ElevatedButton.styleFrom(
9-
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
9+
padding: EdgeInsets.symmetric(
10+
horizontal: 16,
11+
vertical: Platform.isAndroid || Platform.isIOS ? 12 : 16,
12+
),
1013
elevation: 0,
1114
textStyle: textTheme.titleMedium?.copyWith(
1215
color: colorScheme.primary,
@@ -48,7 +51,7 @@ OutlinedButtonThemeData outlinedButtonTheme() => OutlinedButtonThemeData(
4851
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
4952
padding: EdgeInsets.symmetric(
5053
horizontal: 12,
51-
vertical: Platform.isAndroid || Platform.isIOS ? 6 : 12,
54+
vertical: Platform.isAndroid || Platform.isIOS ? 6 : 16,
5255
),
5356
textStyle: textTheme.titleMedium?.copyWith(fontSize: 15),
5457
minimumSize: Size.zero,

app/lib/common/utils/utils.dart

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -230,20 +230,31 @@ extension ColorUtils on Color {
230230
}
231231
}
232232

233+
/// Comprehensive regex for detecting empty HTML tags and structures
234+
final RegExp emptyHtmlTagsRegex = RegExp(
235+
r'<br\s*/?>\s*|<p\s*>(\s|&nbsp;|&#160;|<br\s*/?>)*</p>\s*|<div\s*>(\s|&nbsp;|&#160;)*</div>\s*|<span\s*>(\s|&nbsp;|&#160;)*</span>\s*|<h[1-6]\s*>(\s|&nbsp;|&#160;)*</h[1-6]>\s*|<(strong|b|em|i)\s*>(\s|&nbsp;|&#160;)*</(strong|b|em|i)>\s*|<(ul|ol|li)\s*>(\s|&nbsp;|&#160;)*</(ul|ol|li)>\s*',
236+
multiLine: true,
237+
caseSensitive: false,
238+
);
239+
240+
/// Check if HTML content contains only empty tags or whitespace
241+
bool isEmptyHtmlContent(String html) {
242+
if (html.trim().isEmpty) return true;
243+
244+
// Remove all empty tags and structures
245+
String cleanedHtml = html
246+
.replaceAll(emptyHtmlTagsRegex, '')
247+
.replaceAll(RegExp(r'\s+'), ' ') // Normalize whitespace
248+
.trim();
249+
250+
return cleanedHtml.isEmpty;
251+
}
252+
233253
/// html requires to have some kind of structure even when document is empty, so check for that
234254
bool hasValidEditorContent({required String plainText, required String html}) {
235-
if (plainText.trim().isEmpty) return false;
236-
if (html.isEmpty) return false;
237-
238-
final hasOnlyStructure =
239-
html
240-
.replaceAll(RegExp(r'<br\s*/?>|<p\s*></p>|<p\s*>\s*</p>'), '')
241-
.replaceAll(RegExp(r'<[^>]*>'), '')
242-
.replaceAll('&nbsp;', ' ')
243-
.trim()
244-
.isEmpty;
245-
246-
return !hasOnlyStructure;
255+
final hasPlainTextContent = plainText.trim().isNotEmpty;
256+
final hasHtmlTextContent = !isEmptyHtmlContent(html);
257+
return hasPlainTextContent || hasHtmlTextContent;
247258
}
248259

249260
String formatChatDayDividerDateString(BuildContext context, String dateString) {

app/lib/common/widgets/edit_html_description_sheet.dart

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:acter/common/themes/colors/color_scheme.dart';
22
import 'package:acter/common/toolkit/buttons/primary_action_button.dart';
33
import 'package:acter/common/toolkit/html_editor/html_editor.dart';
4+
import 'package:acter/common/utils/utils.dart';
45
import 'package:appflowy_editor/appflowy_editor.dart';
56
import 'package:flutter/material.dart';
67
import 'package:acter/l10n/generated/l10n.dart';
@@ -14,11 +15,20 @@ void showEditHtmlDescriptionBottomSheet({
1415
required Function(WidgetRef, String, String) onSave,
1516
}) {
1617
showModalBottomSheet(
17-
showDragHandle: true,
18+
showDragHandle: false,
19+
isDismissible: false,
20+
enableDrag: false,
1821
useSafeArea: true,
1922
context: context,
20-
isDismissible: true,
2123
isScrollControlled: true,
24+
shape: const RoundedRectangleBorder(
25+
borderRadius: BorderRadius.only(
26+
topLeft: Radius.circular(16),
27+
topRight: Radius.circular(16),
28+
bottomLeft: Radius.circular(0),
29+
bottomRight: Radius.circular(0),
30+
),
31+
),
2232
builder: (context) {
2333
return EditHtmlDescriptionSheet(
2434
bottomSheetTitle: bottomSheetTitle,
@@ -56,29 +66,48 @@ class _EditHtmlDescriptionSheetState
5666
@override
5767
void initState() {
5868
super.initState();
59-
textEditorState = ActerEditorStateHelpers.fromContent(
60-
widget.descriptionMarkdownValue ?? '',
61-
widget.descriptionHtmlValue,
62-
);
69+
70+
final hasValidContent = hasValidEditorContent(
71+
plainText: widget.descriptionMarkdownValue ?? '',
72+
html: widget.descriptionHtmlValue ?? '');
73+
74+
if (hasValidContent) {
75+
// Use existing content
76+
textEditorState = ActerEditorStateHelpers.fromContent(
77+
widget.descriptionMarkdownValue ?? '',
78+
widget.descriptionHtmlValue,
79+
);
80+
} else {
81+
// Use blank editor with initial text for empty state
82+
textEditorState = EditorState.blank(withInitialText: true);
83+
}
6384
}
6485

6586
@override
6687
Widget build(BuildContext context) {
6788
final lang = L10n.of(context);
6889
return Padding(
69-
padding: MediaQuery.of(context).viewInsets,
90+
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 20),
7091
child: Column(
7192
mainAxisSize: MainAxisSize.min,
7293
children: [
73-
Text(widget.bottomSheetTitle ?? lang.editDescription),
74-
const SizedBox(height: 20),
94+
Text(
95+
widget.bottomSheetTitle ?? lang.editDescription,
96+
style: Theme.of(context).textTheme.titleMedium,
97+
),
98+
const SizedBox(height: 10),
7599
Container(
100+
padding: const EdgeInsets.all(20),
76101
height: 200,
77102
decoration: BoxDecoration(
78103
border: Border.all(color: brandColor),
79104
borderRadius: BorderRadius.circular(10.0),
80105
),
81-
child: HtmlEditor(editorState: textEditorState, editable: true),
106+
child: HtmlEditor(
107+
editorState: textEditorState,
108+
editable: true,
109+
hintText: lang.addDescription,
110+
),
82111
),
83112
const SizedBox(height: 20),
84113
Row(
@@ -106,7 +135,7 @@ class _EditHtmlDescriptionSheetState
106135
),
107136
],
108137
),
109-
const SizedBox(height: 100),
138+
const SizedBox(height: 20),
110139
],
111140
),
112141
);

app/lib/common/widgets/edit_plain_description_sheet.dart

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,20 @@ void showEditPlainDescriptionBottomSheet({
88
required Function(String) onSave,
99
}) {
1010
showModalBottomSheet(
11-
showDragHandle: true,
11+
showDragHandle: false,
12+
isDismissible: false,
13+
enableDrag: false,
1214
useSafeArea: true,
1315
context: context,
14-
isDismissible: true,
16+
isScrollControlled: true,
17+
shape: const RoundedRectangleBorder(
18+
borderRadius: BorderRadius.only(
19+
topLeft: Radius.circular(16),
20+
topRight: Radius.circular(16),
21+
bottomLeft: Radius.circular(0),
22+
bottomRight: Radius.circular(0),
23+
),
24+
),
1525
builder: (context) {
1626
return EditPlainDescriptionSheet(
1727
descriptionValue: descriptionValue,
@@ -50,10 +60,10 @@ class _EditPlainDescriptionSheetState extends State<EditPlainDescriptionSheet> {
5060
final lang = L10n.of(context);
5161
return SingleChildScrollView(
5262
child: Padding(
53-
padding: const EdgeInsets.symmetric(horizontal: 20.0),
63+
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 20),
5464
child: Column(
5565
children: [
56-
Text(lang.editDescription),
66+
Text(lang.editDescription,style: Theme.of(context).textTheme.titleMedium,),
5767
const SizedBox(height: 20),
5868
TextFormField(
5969
keyboardType: TextInputType.multiline,
@@ -62,7 +72,7 @@ class _EditPlainDescriptionSheetState extends State<EditPlainDescriptionSheet> {
6272
minLines: 4,
6373
autofocus: true,
6474
maxLines: 4,
65-
decoration: InputDecoration(hintText: lang.description),
75+
decoration: InputDecoration(hintText: lang.addDescription),
6676
),
6777
const SizedBox(height: 20),
6878
Row(

app/lib/common/widgets/edit_title_sheet.dart

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,20 @@ void showEditTitleBottomSheet({
1010
required Function(WidgetRef, String) onSave,
1111
}) {
1212
showModalBottomSheet(
13-
showDragHandle: true,
13+
showDragHandle: false,
14+
isDismissible: false,
15+
enableDrag: false,
1416
useSafeArea: true,
1517
context: context,
1618
isScrollControlled: true,
19+
shape: const RoundedRectangleBorder(
20+
borderRadius: BorderRadius.only(
21+
topLeft: Radius.circular(16),
22+
topRight: Radius.circular(16),
23+
bottomLeft: Radius.circular(0),
24+
bottomRight: Radius.circular(0),
25+
),
26+
),
1727
builder: (context) {
1828
return EditTitleSheet(
1929
bottomSheetTitle: bottomSheetTitle,
@@ -53,7 +63,7 @@ class _EditTitleSheetState extends ConsumerState<EditTitleSheet> {
5363
Widget build(BuildContext context) {
5464
final lang = L10n.of(context);
5565
return Container(
56-
padding: MediaQuery.of(context).viewInsets,
66+
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 20),
5767
child: Column(
5868
mainAxisSize: MainAxisSize.min,
5969
children: [
@@ -62,7 +72,7 @@ class _EditTitleSheetState extends ConsumerState<EditTitleSheet> {
6272
textAlign: TextAlign.center,
6373
style: Theme.of(context).textTheme.titleMedium,
6474
),
65-
const SizedBox(height: 40),
75+
const SizedBox(height: 20),
6676
TextFormField(
6777
keyboardType: TextInputType.text,
6878
textInputAction: TextInputAction.done,
@@ -97,6 +107,7 @@ class _EditTitleSheetState extends ConsumerState<EditTitleSheet> {
97107
),
98108
],
99109
),
110+
const SizedBox(height: 20),
100111
],
101112
),
102113
);

app/lib/l10n/app_en.arb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2420,6 +2420,8 @@
24202420
"@editName": {},
24212421
"editDescription": "Edit Description",
24222422
"@editDescription": {},
2423+
"addDescription": "Add description here",
2424+
"@addDescription": {},
24232425
"updateNameFailed": "Updating name failed: {error}",
24242426
"@updateNameFailed": {},
24252427
"updateDescriptionFailed": "Updating description failed: {error}",

0 commit comments

Comments
 (0)