Skip to content

Commit

Permalink
fix(WFCNG-16393): Message input no longer renames file by default (#55)
Browse files Browse the repository at this point in the history
refactor: Removed duplicate ZdsMessageInput file
fix: Removed default behaviour for upload errors on ZdsMessageInput
fix: Toasts will now display above the ZdsFilePicker sheet from ZdsMessageInput
  • Loading branch information
mikecoomber authored Dec 30, 2024
1 parent fa0578e commit a304840
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 492 deletions.
111 changes: 56 additions & 55 deletions lib/src/components/organisms/chat/message_input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class ZdsMessageInput extends StatefulWidget {
this.onChange,
this.onSubmit,
this.onUploadFiles,
this.onUploadError,
this.initialValue = '',
this.allowAttachments = false,
this.msgLimit,
Expand All @@ -27,6 +28,7 @@ class ZdsMessageInput extends StatefulWidget {
this.maxVoiceNoteDuration = const Duration(minutes: 1),
this.voiceNoteFileName,
this.allowVoiceNotes = false,
this.postProcessors = const [ZdsFileCompressPostProcessor()],
super.key,
}) : assert(
(allowVoiceNotes && voiceNoteFileName != null) || !allowVoiceNotes,
Expand Down Expand Up @@ -55,6 +57,14 @@ class ZdsMessageInput extends StatefulWidget {
/// Called whenever a file is uploaded.
final void Function(List<XFile> file)? onUploadFiles;

/// Called when file uploading fales.
final void Function(BuildContext context, ZdsFilePickerConfig config, Exception exception)? onUploadError;

/// List of processes a file should undergo post getting picked from file picker
///
/// Defaults to [ZdsFileCompressPostProcessor()]
final List<ZdsFilePostProcessor> postProcessors;

/// Enables voice notes to be sent as messages
///
/// Does not currently work on web.
Expand Down Expand Up @@ -113,7 +123,14 @@ class ZdsMessageInput extends StatefulWidget {
..add(IntProperty('msgLimit', msgLimit))
..add(IntProperty('maxAttachSize', maxAttachSize))
..add(IterableProperty<String>('allowedFileTypes', allowedFileTypes))
..add(IntProperty('maxPixelSize', maxPixelSize));
..add(IntProperty('maxPixelSize', maxPixelSize))
..add(
ObjectFlagProperty<void Function(BuildContext context, ZdsFilePickerConfig config, Exception exception)?>.has(
'onUploadError',
onUploadError,
),
)
..add(IterableProperty<ZdsFilePostProcessor>('postProcessors', postProcessors));
}
}

Expand Down Expand Up @@ -176,23 +193,6 @@ class ZdsMessageInputState extends State<ZdsMessageInput> with SingleTickerProvi
super.dispose();
}

void _showErrorToast(String message) {
ScaffoldMessenger.of(context).showZdsToast(
ZdsToast(
title: Text(message),
actions: [
IconButton(
onPressed: () {
ScaffoldMessenger.of(context).hideCurrentSnackBar();
},
icon: const Icon(ZdsIcons.close),
),
],
color: ZdsToastColors.error,
),
);
}

void _onFileSelected(XFile? file) {
if (file != null) {
widget.onUploadFiles?.call([file]);
Expand Down Expand Up @@ -331,6 +331,8 @@ class ZdsMessageInputState extends State<ZdsMessageInput> with SingleTickerProvi
controller: _inlineController,
optionDisplay: ZdsOptionDisplay.plain,
displayStyle: ZdsFilePickerDisplayStyle.horizontal,
postProcessors: widget.postProcessors,
onError: widget.onUploadError,
onChange: (files) {
_onFilesChanged([...files]);
_inlineController.items.clear();
Expand Down Expand Up @@ -387,44 +389,43 @@ class ZdsMessageInputState extends State<ZdsMessageInput> with SingleTickerProvi
backgroundColor: zetaColors.surfacePrimary,
context: context,
builder: (_) {
return Material(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
height: 48,
padding: const EdgeInsets.symmetric(horizontal: 24),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
IconButton(
icon: const Icon(ZdsIcons.close, size: 24),
onPressed: Navigator.of(context).pop,
color: zetaColors.iconSubtle,
),
Text(
ComponentStrings.of(context).get('ATTACHMENTS', 'Attachments'),
style: themeData.textTheme.headlineMedium,
),
const SizedBox(width: 48),
],
return Scaffold(
body: Material(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
height: 48,
padding: const EdgeInsets.symmetric(horizontal: 24),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
IconButton(
icon: const Icon(ZdsIcons.close, size: 24),
onPressed: Navigator.of(context).pop,
color: zetaColors.iconSubtle,
),
Text(
ComponentStrings.of(context).get('ATTACHMENTS', 'Attachments'),
style: themeData.textTheme.headlineMedium,
),
const SizedBox(width: 48),
],
),
),
),
ZdsFilePicker(
useCard: false,
config: _moreConfig,
showSelected: false,
controller: modalController,
onChange: (files) {
if (files.isNotEmpty) Navigator.of(context).pop(files.first);
},
onError: (context, fileConfig, exception) {
if (exception is FilePickerException) {
_showErrorToast(exception.type.message(context, args: exception.args));
}
},
).paddingOnly(top: 24, bottom: 24),
],
ZdsFilePicker(
useCard: false,
config: _moreConfig,
showSelected: false,
controller: modalController,
onChange: (files) {
if (files.isNotEmpty) Navigator.of(context).pop(files.first);
},
onError: widget.onUploadError,
postProcessors: widget.postProcessors,
).paddingOnly(top: 24, bottom: 24),
],
),
),
);
},
Expand Down
Loading

0 comments on commit a304840

Please sign in to comment.