diff --git a/lib/controller/directory/add_comment_controller.dart b/lib/controller/directory/add_comment_controller.dart index bc77c50..beebff5 100644 --- a/lib/controller/directory/add_comment_controller.dart +++ b/lib/controller/directory/add_comment_controller.dart @@ -15,14 +15,15 @@ class AddCommentController extends GetxController { Future submitComment() async { if (note.value.trim().isEmpty) { showAppSnackbar( - title: "Validation", - message: "Comment cannot be empty.", + title: "Missing Comment", + message: "Please enter a comment before submitting.", type: SnackbarType.warning, ); return; } isSubmitting.value = true; + try { logSafe("Submitting comment for contactId: $contactId"); @@ -34,32 +35,30 @@ class AddCommentController extends GetxController { if (success) { logSafe("Comment added successfully."); - // Get the directory controller + // Refresh UI final directoryController = Get.find(); - - // Fetch latest comments for the contact to refresh UI await directoryController.fetchCommentsForContact(contactId); Get.back(result: true); showAppSnackbar( - title: "Success", - message: "Comment added successfully.", + title: "Comment Added", + message: "Your comment has been successfully added.", type: SnackbarType.success, ); } else { logSafe("Comment submission failed", level: LogLevel.error); showAppSnackbar( - title: "Error", - message: "Failed to add comment.", + title: "Submission Failed", + message: "Unable to add the comment. Please try again later.", type: SnackbarType.error, ); } } catch (e) { logSafe("Error while submitting comment: $e", level: LogLevel.error); showAppSnackbar( - title: "Error", - message: "Something went wrong.", + title: "Unexpected Error", + message: "Something went wrong while adding your comment.", type: SnackbarType.error, ); } finally { diff --git a/lib/model/directory/add_comment_bottom_sheet.dart b/lib/model/directory/add_comment_bottom_sheet.dart index e06b47e..c208d4c 100644 --- a/lib/model/directory/add_comment_bottom_sheet.dart +++ b/lib/model/directory/add_comment_bottom_sheet.dart @@ -23,7 +23,6 @@ class _AddCommentBottomSheetState extends State { void initState() { super.initState(); controller = Get.put(AddCommentController(contactId: widget.contactId)); - // Initialize empty editor for new comment quillController = quill.QuillController.basic(); } @@ -43,7 +42,11 @@ class _AddCommentBottomSheetState extends State { color: Theme.of(context).cardColor, borderRadius: const BorderRadius.vertical(top: Radius.circular(24)), boxShadow: const [ - BoxShadow(color: Colors.black12, blurRadius: 12, offset: Offset(0, -2)), + BoxShadow( + color: Colors.black12, + blurRadius: 12, + offset: Offset(0, -2), + ), ], ), child: Padding( @@ -67,12 +70,11 @@ class _AddCommentBottomSheetState extends State { CommentEditorCard( controller: quillController, onCancel: () => Get.back(), - onSave: (controller) async { - final delta = controller.document.toDelta(); + onSave: (editorController) async { + final delta = editorController.document.toDelta(); final htmlOutput = _convertDeltaToHtml(delta); - this.controller.updateNote(htmlOutput); - await this.controller.submitComment(); - if (mounted) Get.back(); + controller.updateNote(htmlOutput); + await controller.submitComment(); }, ), ], @@ -81,62 +83,54 @@ class _AddCommentBottomSheetState extends State { ), ); } -} -String _convertDeltaToHtml(dynamic delta) { - final buffer = StringBuffer(); - bool inList = false; + String _convertDeltaToHtml(dynamic delta) { + final buffer = StringBuffer(); + bool inList = false; - for (var op in delta.toList()) { - final data = op.data?.toString() ?? ''; - final attr = op.attributes ?? {}; + for (var op in delta.toList()) { + final data = op.data?.toString() ?? ''; + final attr = op.attributes ?? {}; - final isListItem = attr.containsKey('list'); + final isListItem = attr.containsKey('list'); + final trimmedData = data.trim(); - // Start
    if list item starts - if (isListItem && !inList) { - buffer.write('
      '); - inList = true; + if (isListItem && !inList) { + buffer.write('
        '); + inList = true; + } + + if (!isListItem && inList) { + buffer.write('
      '); + inList = false; + } + + if (isListItem && trimmedData.isEmpty) continue; + + if (isListItem) buffer.write('
    • '); + + if (attr.containsKey('bold')) buffer.write(''); + if (attr.containsKey('italic')) buffer.write(''); + if (attr.containsKey('underline')) buffer.write(''); + if (attr.containsKey('strike')) buffer.write(''); + if (attr.containsKey('link')) buffer.write(''); + + buffer.write(trimmedData.replaceAll('\n', '')); + + if (attr.containsKey('link')) buffer.write(''); + if (attr.containsKey('strike')) buffer.write(''); + if (attr.containsKey('underline')) buffer.write(''); + if (attr.containsKey('italic')) buffer.write(''); + if (attr.containsKey('bold')) buffer.write(''); + + if (isListItem) { + buffer.write('
    • '); + } else if (data.contains('\n')) { + buffer.write('
      '); + } } - // Close
        if list ended - if (!isListItem && inList) { - buffer.write('
      '); - inList = false; - } - - // Skip empty list items - final trimmedData = data.trim(); - if (isListItem && trimmedData.isEmpty) { - // don't write empty
    • - continue; - } - - if (isListItem) buffer.write('
    • '); - - if (attr.containsKey('bold')) buffer.write(''); - if (attr.containsKey('italic')) buffer.write(''); - if (attr.containsKey('underline')) buffer.write(''); - if (attr.containsKey('strike')) buffer.write(''); - if (attr.containsKey('link')) buffer.write(''); - - // Use trimmedData instead of raw data (removes trailing/leading spaces/newlines) - buffer.write(trimmedData.replaceAll('\n', '')); - - if (attr.containsKey('link')) buffer.write(''); - if (attr.containsKey('strike')) buffer.write(''); - if (attr.containsKey('underline')) buffer.write(''); - if (attr.containsKey('italic')) buffer.write(''); - if (attr.containsKey('bold')) buffer.write(''); - - if (isListItem) { - buffer.write('
    • '); - } else if (data.contains('\n')) { - buffer.write('
      '); - } + if (inList) buffer.write('
    '); + return buffer.toString(); } - - if (inList) buffer.write('
'); - - return buffer.toString(); }