diff --git a/assets/i18n/en-US.json b/assets/i18n/en-US.json index fa4d5b9d..bc88d44b 100644 --- a/assets/i18n/en-US.json +++ b/assets/i18n/en-US.json @@ -233,6 +233,9 @@ "pickFile": "Pick a file", "uploading": "Uploading", "uploadingProgress": "Uploading {} of {}", + "upload": "Upload", + "uploadSuccess": "Upload successful!", + "wouldYouLikeToViewFile": "Would you like to view the file?", "uploadAll": "Upload All", "stickerCopyPlaceholder": "Copy Placeholder", "realmSelection": "Select a Realm", @@ -1110,7 +1113,6 @@ "deleteRecycledFiles": "Delete Recycled Files", "recycledFilesDeleted": "Recycled files deleted successfully", "failedToDeleteRecycledFiles": "Failed to delete recycled files", - "upload": "Upload", "updateAvailable": "Update available", "noChangelogProvided": "No changelog provided.", "useSecondarySourceForDownload": "Use secondary source for download", diff --git a/lib/widgets/share/share_sheet.dart b/lib/widgets/share/share_sheet.dart index 366f7eac..9aa5405c 100644 --- a/lib/widgets/share/share_sheet.dart +++ b/lib/widgets/share/share_sheet.dart @@ -285,23 +285,10 @@ class _ShareSheetState extends ConsumerState { ); // Show navigation prompt - final shouldNavigate = await showDialog( - context: context, - builder: - (context) => AlertDialog( - title: Text('shareSuccess'.tr()), - content: Text('wouldYouLikeToGoToChat'.tr()), - actions: [ - TextButton( - onPressed: () => Navigator.of(context).pop(false), - child: Text('no'.tr()), - ), - TextButton( - onPressed: () => Navigator.of(context).pop(true), - child: Text('yes'.tr()), - ), - ], - ), + final shouldNavigate = await showConfirmAlert( + 'wouldYouLikeToGoToChat'.tr(), + 'shareSuccess'.tr(), + icon: Symbols.check_circle, ); // Close the share sheet @@ -367,6 +354,92 @@ class _ShareSheetState extends ConsumerState { } } + Future _uploadFiles() async { + if (widget.content.files == null || widget.content.files!.isEmpty) return; + + setState(() => _isLoading = true); + try { + final universalFiles = + widget.content.files!.map((file) { + UniversalFileType fileType; + if (file.mimeType?.startsWith('image/') == true) { + fileType = UniversalFileType.image; + } else if (file.mimeType?.startsWith('video/') == true) { + fileType = UniversalFileType.video; + } else if (file.mimeType?.startsWith('audio/') == true) { + fileType = UniversalFileType.audio; + } else { + fileType = UniversalFileType.file; + } + return UniversalFile(data: file, type: fileType); + }).toList(); + + // Initialize progress tracking + final messageId = DateTime.now().millisecondsSinceEpoch.toString(); + _fileUploadProgress[messageId] = List.filled(universalFiles.length, 0.0); + + List uploadedFiles = []; + + // Upload each file + for (var idx = 0; idx < universalFiles.length; idx++) { + final file = universalFiles[idx]; + final cloudFile = + await FileUploader.createCloudFile( + ref: ref, + fileData: file, + onProgress: (progress, _) { + if (mounted) { + setState(() { + _fileUploadProgress[messageId]?[idx] = progress ?? 0.0; + }); + } + }, + ).future; + + if (cloudFile == null) { + throw Exception('Failed to upload file: ${file.data.name}'); + } + uploadedFiles.add(cloudFile); + } + + if (mounted) { + // Show success message + showSnackBar('uploadSuccess'.tr()); + + // If single file, ask to view details + if (uploadedFiles.length == 1) { + final shouldView = await showConfirmAlert( + 'wouldYouLikeToViewFile'.tr(), + 'uploadSuccess'.tr(), + icon: Symbols.check_circle, + ); + + if (mounted) { + Navigator.of(context).pop(); // Close share sheet + if (shouldView == true) { + context.pushNamed( + 'fileDetail', + pathParameters: {'id': uploadedFiles.first.id}, + extra: uploadedFiles.first, + ); + } + } + } else { + // Just close for multiple files + Navigator.of(context).pop(); + } + } + } catch (e) { + if (mounted) { + showErrorAlert(e); + } + } finally { + if (mounted) { + setState(() => _isLoading = false); + } + } + } + Future _copyToClipboard() async { try { String textToCopy = ''; @@ -456,6 +529,15 @@ class _ShareSheetState extends ConsumerState { onTap: _isLoading ? null : _shareToPost, ), const SizedBox(width: 12), + if (widget.content.type == + ShareContentType.file) ...[ + _CompactShareOption( + icon: Symbols.cloud_upload, + title: 'upload'.tr(), + onTap: _isLoading ? null : _uploadFiles, + ), + const SizedBox(width: 12), + ], _CompactShareOption( icon: Symbols.content_copy, title: 'copy'.tr(),