From 09455aa1357b88a3f607c2259b146dc9f9149117 Mon Sep 17 00:00:00 2001 From: Thiago Carvalho Date: Mon, 15 Jan 2024 15:21:22 -0300 Subject: [PATCH 1/7] feat(rename) - warn the user when a file get the extension updated - update extension if desired --- .../fs_entry_rename_cubit.dart | 66 +++++++++++++++++-- .../fs_entry_rename_state.dart | 12 ++++ lib/components/fs_entry_rename_form.dart | 39 +++++++++++ 3 files changed, 112 insertions(+), 5 deletions(-) diff --git a/lib/blocs/fs_entry_rename/fs_entry_rename_cubit.dart b/lib/blocs/fs_entry_rename/fs_entry_rename_cubit.dart index aea1ea0bc4..c86c961751 100644 --- a/lib/blocs/fs_entry_rename/fs_entry_rename_cubit.dart +++ b/lib/blocs/fs_entry_rename/fs_entry_rename_cubit.dart @@ -4,6 +4,8 @@ import 'package:ardrive/models/models.dart'; import 'package:ardrive/services/services.dart'; import 'package:ardrive/turbo/services/upload_service.dart'; import 'package:ardrive/utils/logger.dart'; +import 'package:ardrive_io/ardrive_io.dart'; +import 'package:drift/drift.dart'; import 'package:equatable/equatable.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:reactive_forms/reactive_forms.dart'; @@ -26,6 +28,9 @@ class FsEntryRenameCubit extends Cubit { bool get _isRenamingFolder => folderId != null; + bool _dontVerifyExtension = false; + String? _newFileExtension; + FsEntryRenameCubit({ required this.driveId, this.folderId, @@ -47,7 +52,10 @@ class FsEntryRenameCubit extends Cubit { emit(FsEntryRenameInitialized(isRenamingFolder: _isRenamingFolder)); } - Future submit({required String newName}) async { + Future submit({ + required String newName, + bool updateExtension = false, + }) async { try { late bool hasEntityWithSameName; @@ -114,13 +122,31 @@ class FsEntryRenameCubit extends Cubit { emit(const FolderEntryRenameSuccess()); } else { + var file = await _driveDao + .fileById(driveId: driveId, fileId: fileId!) + .getSingle(); + final hasExtensionChanged = + verifyExtensionAndReturnIfExtensionWasUpdated( + newName, + file, + ); + + if (!updateExtension && !_dontVerifyExtension && hasExtensionChanged) { + return; + } + emit(const FileEntryRenameInProgress()); await _driveDao.transaction(() async { - var file = await _driveDao - .fileById(driveId: driveId, fileId: fileId!) - .getSingle(); - file = file.copyWith(name: newName, lastUpdated: DateTime.now()); + file = file.copyWith( + name: newName, + lastUpdated: DateTime.now(), + ); + + if (updateExtension) { + file = + file.copyWith(dataContentType: Value(lookupMimeType(newName))); + } final fileKey = driveKey != null ? await _crypto.deriveFileKey(driveKey, file.id) @@ -148,6 +174,9 @@ class FsEntryRenameCubit extends Cubit { fileEntity.txId = fileTx.id; } + logger.i( + 'Updating file ${file.id} with txId ${fileEntity.txId}. Data content type: ${fileEntity.dataContentType}'); + await _driveDao.writeToFile(file); await _driveDao.insertFileRevision(fileEntity.toRevisionCompanion( @@ -161,6 +190,29 @@ class FsEntryRenameCubit extends Cubit { } } + bool verifyExtensionAndReturnIfExtensionWasUpdated( + String newName, FileEntry file) { + _newFileExtension = + getFileExtension(name: newName, contentType: file.dataContentType!); + + final currentExtension = + getFileExtension(name: file.name, contentType: file.dataContentType!); + + if (currentExtension == _newFileExtension) { + return false; + } + + emit( + UpdatingEntityExtension( + previousExtension: currentExtension, + entityName: newName, + newExtension: _newFileExtension!, + ), + ); + + return true; + } + Future _folderWithSameNameExists(String newFolderName) async { final folder = await _driveDao .folderById(driveId: driveId, folderId: folderId!) @@ -188,6 +240,10 @@ class FsEntryRenameCubit extends Cubit { return entityWithSameNameExists; } + void dontVerifyExtension() { + _dontVerifyExtension = true; + } + @override void onError(Object error, StackTrace stackTrace) { if (_isRenamingFolder) { diff --git a/lib/blocs/fs_entry_rename/fs_entry_rename_state.dart b/lib/blocs/fs_entry_rename/fs_entry_rename_state.dart index b3166812a7..896329af63 100644 --- a/lib/blocs/fs_entry_rename/fs_entry_rename_state.dart +++ b/lib/blocs/fs_entry_rename/fs_entry_rename_state.dart @@ -40,6 +40,18 @@ class EntityAlreadyExists extends FsEntryRenameState { final String entityName; } +class UpdatingEntityExtension extends FsEntryRenameState { + const UpdatingEntityExtension({ + required this.entityName, + required this.newExtension, + required this.previousExtension, + }) : super(isRenamingFolder: false); + + final String entityName; + final String newExtension; + final String previousExtension; +} + class FolderEntryRenameWalletMismatch extends FsEntryRenameState { const FolderEntryRenameWalletMismatch() : super(isRenamingFolder: true); } diff --git a/lib/components/fs_entry_rename_form.dart b/lib/components/fs_entry_rename_form.dart index 8cc7217c8a..8551d982ca 100644 --- a/lib/components/fs_entry_rename_form.dart +++ b/lib/components/fs_entry_rename_form.dart @@ -8,6 +8,7 @@ import 'package:ardrive/turbo/services/upload_service.dart'; import 'package:ardrive/utils/app_localizations_wrapper.dart'; import 'package:ardrive/utils/show_general_dialog.dart'; import 'package:ardrive/utils/validate_folder_name.dart'; +import 'package:ardrive_io/ardrive_io.dart'; import 'package:ardrive_ui/ardrive_ui.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -105,6 +106,44 @@ class _FsEntryRenameFormState extends State { ), ), ); + } else if (state is UpdatingEntityExtension) { + showArDriveDialog( + context, + content: ArDriveStandardModal( + title: 'Do you want to change the file extension?', + description: 'The file extension will be changed from ' + '${state.previousExtension} to ${getFileExtension(name: state.entityName, contentType: state.newExtension)}', + actions: [ + ModalAction( + action: () { + Navigator.of(context).pop(); + Navigator.of(context).pop(); + }, + title: appLocalizationsOf(context).cancelEmphasized, + ), + ModalAction( + action: () { + context.read().dontVerifyExtension(); + context + .read() + .submit(newName: _nameController.text); + Navigator.of(context).pop(); + }, + title: 'Don\'t change', + ), + ModalAction( + action: () => context + .read() + .submit( + newName: _nameController.text, + updateExtension: true) + .then((value) => Navigator.of(context).pop()), + title: 'Submit', + isEnable: _validForm, + ), + ], + ), + ); } }, builder: (context, state) { From be3bf723115f4f09643f940937779ace3e2710c4 Mon Sep 17 00:00:00 2001 From: Thiago Carvalho Date: Mon, 15 Jan 2024 16:09:58 -0300 Subject: [PATCH 2/7] Update fs_entry_rename_form.dart remove unintended then --- lib/components/fs_entry_rename_form.dart | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/components/fs_entry_rename_form.dart b/lib/components/fs_entry_rename_form.dart index 8551d982ca..808d250bf8 100644 --- a/lib/components/fs_entry_rename_form.dart +++ b/lib/components/fs_entry_rename_form.dart @@ -132,12 +132,11 @@ class _FsEntryRenameFormState extends State { title: 'Don\'t change', ), ModalAction( - action: () => context - .read() - .submit( - newName: _nameController.text, - updateExtension: true) - .then((value) => Navigator.of(context).pop()), + action: () { + context.read().submit( + newName: _nameController.text, updateExtension: true); + Navigator.of(context).pop(); + }, title: 'Submit', isEnable: _validForm, ), From b111ff295f80522bb35d248fcf22c17638483c7f Mon Sep 17 00:00:00 2001 From: Thiago Carvalho Date: Fri, 19 Jan 2024 10:39:29 -0300 Subject: [PATCH 3/7] feat(file extension) - remove duplicated pop --- .../fs_entry_rename_cubit.dart | 43 +++++++------------ lib/components/fs_entry_rename_form.dart | 1 - 2 files changed, 15 insertions(+), 29 deletions(-) diff --git a/lib/blocs/fs_entry_rename/fs_entry_rename_cubit.dart b/lib/blocs/fs_entry_rename/fs_entry_rename_cubit.dart index c86c961751..0338955b1b 100644 --- a/lib/blocs/fs_entry_rename/fs_entry_rename_cubit.dart +++ b/lib/blocs/fs_entry_rename/fs_entry_rename_cubit.dart @@ -125,13 +125,23 @@ class FsEntryRenameCubit extends Cubit { var file = await _driveDao .fileById(driveId: driveId, fileId: fileId!) .getSingle(); - final hasExtensionChanged = - verifyExtensionAndReturnIfExtensionWasUpdated( - newName, - file, - ); + _newFileExtension = + getFileExtension(name: newName, contentType: file.dataContentType!); + + final currentExtension = getFileExtension( + name: file.name, contentType: file.dataContentType!); + + final hasExtensionChanged = currentExtension != _newFileExtension; if (!updateExtension && !_dontVerifyExtension && hasExtensionChanged) { + emit( + UpdatingEntityExtension( + previousExtension: currentExtension, + entityName: newName, + newExtension: _newFileExtension!, + ), + ); + return; } @@ -190,29 +200,6 @@ class FsEntryRenameCubit extends Cubit { } } - bool verifyExtensionAndReturnIfExtensionWasUpdated( - String newName, FileEntry file) { - _newFileExtension = - getFileExtension(name: newName, contentType: file.dataContentType!); - - final currentExtension = - getFileExtension(name: file.name, contentType: file.dataContentType!); - - if (currentExtension == _newFileExtension) { - return false; - } - - emit( - UpdatingEntityExtension( - previousExtension: currentExtension, - entityName: newName, - newExtension: _newFileExtension!, - ), - ); - - return true; - } - Future _folderWithSameNameExists(String newFolderName) async { final folder = await _driveDao .folderById(driveId: driveId, folderId: folderId!) diff --git a/lib/components/fs_entry_rename_form.dart b/lib/components/fs_entry_rename_form.dart index 808d250bf8..2769f54bf3 100644 --- a/lib/components/fs_entry_rename_form.dart +++ b/lib/components/fs_entry_rename_form.dart @@ -117,7 +117,6 @@ class _FsEntryRenameFormState extends State { ModalAction( action: () { Navigator.of(context).pop(); - Navigator.of(context).pop(); }, title: appLocalizationsOf(context).cancelEmphasized, ), From dc66695fd17fc44f24794be65f6cad0477e052d0 Mon Sep 17 00:00:00 2001 From: atticusofsparta Date: Thu, 25 Jan 2024 17:26:51 -0600 Subject: [PATCH 4/7] fix(confirm modal): remove do not change button, use cancel and confirm only --- .vscode/settings.json | 2 +- lib/components/fs_entry_rename_form.dart | 10 -- packages/pst/pubspec.lock | 218 +---------------------- pubspec.lock | 16 +- 4 files changed, 14 insertions(+), 232 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index fdfe3b0268..8c4ccf2184 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,6 @@ { "editor.codeActionsOnSave": { - "source.organizeImports": true + "source.organizeImports": "explicit" }, "bloc.newBlocTemplate": "equatable", "bloc.newCubitTemplate": "equatable", diff --git a/lib/components/fs_entry_rename_form.dart b/lib/components/fs_entry_rename_form.dart index 2769f54bf3..1be18e0e92 100644 --- a/lib/components/fs_entry_rename_form.dart +++ b/lib/components/fs_entry_rename_form.dart @@ -120,16 +120,6 @@ class _FsEntryRenameFormState extends State { }, title: appLocalizationsOf(context).cancelEmphasized, ), - ModalAction( - action: () { - context.read().dontVerifyExtension(); - context - .read() - .submit(newName: _nameController.text); - Navigator.of(context).pop(); - }, - title: 'Don\'t change', - ), ModalAction( action: () { context.read().submit( diff --git a/packages/pst/pubspec.lock b/packages/pst/pubspec.lock index d6f6d59ddf..3280096c79 100644 --- a/packages/pst/pubspec.lock +++ b/packages/pst/pubspec.lock @@ -1,22 +1,6 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: - _fe_analyzer_shared: - dependency: transitive - description: - name: _fe_analyzer_shared - sha256: ae92f5d747aee634b87f89d9946000c2de774be1d6ac3e58268224348cd0101a - url: "https://pub.dev" - source: hosted - version: "61.0.0" - analyzer: - dependency: transitive - description: - name: analyzer - sha256: ea3d8652bda62982addfd92fdc2d0214e5f82e43325104990d4f4c4a2a313562 - url: "https://pub.dev" - source: hosted - version: "5.13.0" ardrive_http: dependency: "direct main" description: @@ -33,23 +17,15 @@ packages: relative: true source: path version: "0.0.1" - args: - dependency: transitive - description: - name: args - sha256: eef6c46b622e0494a36c5a12d10d77fb4e855501a91c1b9ef9339326e58f0596 - url: "https://pub.dev" - source: hosted - version: "2.4.2" arweave: dependency: "direct main" description: path: "." - ref: "v3.8.2" - resolved-ref: "363d4b69be03d2e67390e7c70eb7c3a230377001" + ref: "v3.8.3" + resolved-ref: "41d590687cecafc316b3c83da20274a29d3e2833" url: "https://github.com/ardriveapp/arweave-dart.git" source: git - version: "3.8.2" + version: "3.8.3" async: dependency: transitive description: @@ -146,14 +122,6 @@ packages: url: "https://pub.dev" source: hosted version: "3.1.1" - coverage: - dependency: transitive - description: - name: coverage - sha256: "595a29b55ce82d53398e1bcc2cba525d7bd7c59faeb2d2540e9d42c390cfeeeb" - url: "https://pub.dev" - source: hosted - version: "1.6.4" crypto: dependency: transitive description: @@ -298,22 +266,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.1.0" - frontend_server_client: - dependency: transitive - description: - name: frontend_server_client - sha256: "408e3ca148b31c20282ad6f37ebfa6f4bdc8fede5b74bc2f08d9d92b55db3612" - url: "https://pub.dev" - source: hosted - version: "3.2.0" - glob: - dependency: transitive - description: - name: glob - sha256: "0e7014b3b7d4dac1ca4d6114f82bf1782ee86745b9b42a92c9289c23d8a0ab63" - url: "https://pub.dev" - source: hosted - version: "2.1.2" hash: dependency: transitive description: @@ -354,14 +306,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.1.1" - http_multi_server: - dependency: transitive - description: - name: http_multi_server - sha256: "97486f20f9c2f7be8f514851703d0119c3596d14ea63227af6f7a481ef2b2f8b" - url: "https://pub.dev" - source: hosted - version: "3.2.1" http_parser: dependency: transitive description: @@ -370,14 +314,6 @@ packages: url: "https://pub.dev" source: hosted version: "4.0.2" - io: - dependency: transitive - description: - name: io - sha256: "2ec25704aba361659e10e3e5f5d672068d332fc8ac516421d483a11e5cbd061e" - url: "https://pub.dev" - source: hosted - version: "1.0.4" isolated_worker: dependency: transitive description: @@ -418,14 +354,6 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.1" - logging: - dependency: transitive - description: - name: logging - sha256: "623a88c9594aa774443aa3eb2d41807a48486b5613e67599fb4c41c0ad47c340" - url: "https://pub.dev" - source: hosted - version: "1.2.0" matcher: dependency: transitive description: @@ -450,22 +378,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.10.0" - mime: - dependency: transitive - description: - name: mime - sha256: e4ff8e8564c03f255408decd16e7899da1733852a9110a58fe6d1b817684a63e - url: "https://pub.dev" - source: hosted - version: "1.0.4" mocktail: dependency: "direct main" description: name: mocktail - sha256: "80a996cd9a69284b3dc521ce185ffe9150cde69767c2d3a0720147d93c0cef53" + sha256: c4b5007d91ca4f67256e720cb1b6d704e79a510183a12fa551021f652577dce6 url: "https://pub.dev" source: hosted - version: "0.3.0" + version: "1.0.3" mutex: dependency: transitive description: @@ -474,22 +394,6 @@ packages: url: "https://pub.dev" source: hosted version: "3.1.0" - node_preamble: - dependency: transitive - description: - name: node_preamble - sha256: "6e7eac89047ab8a8d26cf16127b5ed26de65209847630400f9aefd7cd5c730db" - url: "https://pub.dev" - source: hosted - version: "2.0.2" - package_config: - dependency: transitive - description: - name: package_config - sha256: "1c5b77ccc91e4823a5af61ee74e6b972db1ef98c2ff5a18d3161c982a55448bd" - url: "https://pub.dev" - source: hosted - version: "2.1.0" package_info_plus: dependency: transitive description: @@ -538,22 +442,6 @@ packages: url: "https://pub.dev" source: hosted version: "3.7.3" - pool: - dependency: transitive - description: - name: pool - sha256: "20fe868b6314b322ea036ba325e6fc0711a22948856475e2c2b6306e8ab39c2a" - url: "https://pub.dev" - source: hosted - version: "1.5.1" - pub_semver: - dependency: transitive - description: - name: pub_semver - sha256: "40d3ab1bbd474c4c2328c91e3a7df8c6dd629b79ece4c4bd04bee496a224fb0c" - url: "https://pub.dev" - source: hosted - version: "2.1.4" retry: dependency: "direct main" description: @@ -570,14 +458,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.4.1" - shelf_packages_handler: - dependency: transitive - description: - name: shelf_packages_handler - sha256: "89f967eca29607c933ba9571d838be31d67f53f6e4ee15147d5dc2934fee1b1e" - url: "https://pub.dev" - source: hosted - version: "3.0.2" shelf_router: dependency: transitive description: @@ -586,43 +466,11 @@ packages: url: "https://pub.dev" source: hosted version: "1.1.4" - shelf_static: - dependency: transitive - description: - name: shelf_static - sha256: a41d3f53c4adf0f57480578c1d61d90342cd617de7fc8077b1304643c2d85c1e - url: "https://pub.dev" - source: hosted - version: "1.1.2" - shelf_web_socket: - dependency: transitive - description: - name: shelf_web_socket - sha256: "9ca081be41c60190ebcb4766b2486a7d50261db7bd0f5d9615f2d653637a84c1" - url: "https://pub.dev" - source: hosted - version: "1.0.4" sky_engine: dependency: transitive description: flutter source: sdk version: "0.0.99" - source_map_stack_trace: - dependency: transitive - description: - name: source_map_stack_trace - sha256: "84cf769ad83aa6bb61e0aa5a18e53aea683395f196a6f39c4c881fb90ed4f7ae" - url: "https://pub.dev" - source: hosted - version: "2.1.1" - source_maps: - dependency: transitive - description: - name: source_maps - sha256: "708b3f6b97248e5781f493b765c3337db11c5d2c81c3094f10904bfa8004c703" - url: "https://pub.dev" - source: hosted - version: "0.10.12" source_span: dependency: transitive description: @@ -663,14 +511,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.2.1" - test: - dependency: transitive - description: - name: test - sha256: a1f7595805820fcc05e5c52e3a231aedd0b72972cb333e8c738a8b1239448b6f - url: "https://pub.dev" - source: hosted - version: "1.24.9" test_api: dependency: transitive description: @@ -679,14 +519,6 @@ packages: url: "https://pub.dev" source: hosted version: "0.6.1" - test_core: - dependency: transitive - description: - name: test_core - sha256: a757b14fc47507060a162cc2530d9a4a2f92f5100a952c7443b5cad5ef5b106a - url: "https://pub.dev" - source: hosted - version: "0.5.9" typed_data: dependency: transitive description: @@ -719,22 +551,6 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.4" - vm_service: - dependency: transitive - description: - name: vm_service - sha256: c538be99af830f478718b51630ec1b6bee5e74e52c8a802d328d9e71d35d2583 - url: "https://pub.dev" - source: hosted - version: "11.10.0" - watcher: - dependency: transitive - description: - name: watcher - sha256: "3d2ad6751b3c16cf07c7fca317a1413b3f26530319181b37e3b9039b84fc01d8" - url: "https://pub.dev" - source: hosted - version: "1.1.0" web: dependency: transitive description: @@ -743,22 +559,6 @@ packages: url: "https://pub.dev" source: hosted version: "0.3.0" - web_socket_channel: - dependency: transitive - description: - name: web_socket_channel - sha256: d88238e5eac9a42bb43ca4e721edba3c08c6354d4a53063afaa568516217621b - url: "https://pub.dev" - source: hosted - version: "2.4.0" - webkit_inspection_protocol: - dependency: transitive - description: - name: webkit_inspection_protocol - sha256: "87d3f2333bb240704cd3f1c6b5b7acd8a10e7f0bc28c28dcf14e782014f4a572" - url: "https://pub.dev" - source: hosted - version: "1.2.1" win32: dependency: transitive description: @@ -775,14 +575,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.1.2" - yaml: - dependency: transitive - description: - name: yaml - sha256: "75769501ea3489fca56601ff33454fe45507ea3bfb014161abc3b43ae25989d5" - url: "https://pub.dev" - source: hosted - version: "3.1.2" sdks: dart: ">=3.2.0-194.0.dev <4.0.0" flutter: ">=3.7.12" diff --git a/pubspec.lock b/pubspec.lock index 847565dc22..aa2b56179e 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1231,10 +1231,10 @@ packages: dependency: transitive description: name: jovial_svg - sha256: "5fd52a96fe3d2b69082c53374364649f51cb1b3e06ca6be3601ed8cae537bc7b" + sha256: "7162d9fce53e284782f6178e175c9e07dde695779392eaa2542c1f795658eb3d" url: "https://pub.dev" source: hosted - version: "1.1.17" + version: "1.1.20" js: dependency: "direct main" description: @@ -1407,10 +1407,10 @@ packages: dependency: transitive description: name: mutex - sha256: "03116a4e46282a671b46c12de649d72c0ed18188ffe12a8d0fc63e83f4ad88f4" + sha256: "8827da25de792088eb33e572115a5eb0d61d61a3c01acbc8bcbe76ed78f1a1f2" url: "https://pub.dev" source: hosted - version: "3.0.1" + version: "3.1.0" nested: dependency: transitive description: @@ -1867,18 +1867,18 @@ packages: dependency: transitive description: name: sqflite - sha256: "591f1602816e9c31377d5f008c2d9ef7b8aca8941c3f89cc5fd9d84da0c38a9a" + sha256: c2c32eb0c74021d987336522acc3b6bf0082fbd0c540c36a9cf4ddb8ba891ddc url: "https://pub.dev" source: hosted - version: "2.3.0" + version: "2.3.1" sqflite_common: dependency: transitive description: name: sqflite_common - sha256: "1b92f368f44b0dee2425bb861cfa17b6f6cf3961f762ff6f941d20b33355660a" + sha256: "28d8c66baee4968519fb8bd6cdbedad982d6e53359091f0b74544a9f32ec72d5" url: "https://pub.dev" source: hosted - version: "2.5.0" + version: "2.5.3" sqlite3: dependency: transitive description: From 653a55fcbfc6746f63c55ae5a5f932e730a37f0e Mon Sep 17 00:00:00 2001 From: atticusofsparta Date: Thu, 25 Jan 2024 21:41:20 -0600 Subject: [PATCH 5/7] fix(modal state type): reset modal state type on back --- .../fs_entry_rename/fs_entry_rename_cubit.dart | 15 ++++++++------- lib/components/fs_entry_rename_form.dart | 13 +++++++++---- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/lib/blocs/fs_entry_rename/fs_entry_rename_cubit.dart b/lib/blocs/fs_entry_rename/fs_entry_rename_cubit.dart index 0338955b1b..ce1feb9fe4 100644 --- a/lib/blocs/fs_entry_rename/fs_entry_rename_cubit.dart +++ b/lib/blocs/fs_entry_rename/fs_entry_rename_cubit.dart @@ -134,13 +134,14 @@ class FsEntryRenameCubit extends Cubit { final hasExtensionChanged = currentExtension != _newFileExtension; if (!updateExtension && !_dontVerifyExtension && hasExtensionChanged) { - emit( - UpdatingEntityExtension( - previousExtension: currentExtension, - entityName: newName, - newExtension: _newFileExtension!, - ), - ); + // if (state is UpdatingEntityExtension) { + // emit(FsEntryRenameInitialized(isRenamingFolder: _isRenamingFolder)); + // } + emit(UpdatingEntityExtension( + previousExtension: currentExtension, + entityName: newName, + newExtension: _newFileExtension!, + )); return; } diff --git a/lib/components/fs_entry_rename_form.dart b/lib/components/fs_entry_rename_form.dart index 1be18e0e92..af57a9e68d 100644 --- a/lib/components/fs_entry_rename_form.dart +++ b/lib/components/fs_entry_rename_form.dart @@ -116,7 +116,10 @@ class _FsEntryRenameFormState extends State { actions: [ ModalAction( action: () { - Navigator.of(context).pop(); + context.read().emit( + FsEntryRenameInitialized( + isRenamingFolder: state.isRenamingFolder)); + Navigator.of(context).pop(context); }, title: appLocalizationsOf(context).cancelEmphasized, ), @@ -172,9 +175,11 @@ class _FsEntryRenameFormState extends State { title: appLocalizationsOf(context).cancelEmphasized, ), ModalAction( - action: () => context - .read() - .submit(newName: _nameController.text), + action: () { + context + .read() + .submit(newName: _nameController.text); + }, title: appLocalizationsOf(context).renameEmphasized, isEnable: _validForm, ), From 88df2d498b1d152233af50c013bcdc56466f8b3c Mon Sep 17 00:00:00 2001 From: atticusofsparta Date: Thu, 25 Jan 2024 22:32:43 -0600 Subject: [PATCH 6/7] fix(lint): move reset logic to cubit --- lib/blocs/fs_entry_rename/fs_entry_rename_cubit.dart | 7 ++++--- lib/components/fs_entry_rename_form.dart | 4 +--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/blocs/fs_entry_rename/fs_entry_rename_cubit.dart b/lib/blocs/fs_entry_rename/fs_entry_rename_cubit.dart index ce1feb9fe4..5ba4e604ef 100644 --- a/lib/blocs/fs_entry_rename/fs_entry_rename_cubit.dart +++ b/lib/blocs/fs_entry_rename/fs_entry_rename_cubit.dart @@ -52,6 +52,10 @@ class FsEntryRenameCubit extends Cubit { emit(FsEntryRenameInitialized(isRenamingFolder: _isRenamingFolder)); } + Future reset() async { + emit(FsEntryRenameInitialized(isRenamingFolder: _isRenamingFolder)); + } + Future submit({ required String newName, bool updateExtension = false, @@ -134,9 +138,6 @@ class FsEntryRenameCubit extends Cubit { final hasExtensionChanged = currentExtension != _newFileExtension; if (!updateExtension && !_dontVerifyExtension && hasExtensionChanged) { - // if (state is UpdatingEntityExtension) { - // emit(FsEntryRenameInitialized(isRenamingFolder: _isRenamingFolder)); - // } emit(UpdatingEntityExtension( previousExtension: currentExtension, entityName: newName, diff --git a/lib/components/fs_entry_rename_form.dart b/lib/components/fs_entry_rename_form.dart index af57a9e68d..67df937fc8 100644 --- a/lib/components/fs_entry_rename_form.dart +++ b/lib/components/fs_entry_rename_form.dart @@ -116,9 +116,7 @@ class _FsEntryRenameFormState extends State { actions: [ ModalAction( action: () { - context.read().emit( - FsEntryRenameInitialized( - isRenamingFolder: state.isRenamingFolder)); + context.read().reset(); Navigator.of(context).pop(context); }, title: appLocalizationsOf(context).cancelEmphasized, From 8b28f94487d25b01f192f77ccb974cfe1b0f541a Mon Sep 17 00:00:00 2001 From: Thiago Carvalho Date: Mon, 29 Jan 2024 20:34:50 -0300 Subject: [PATCH 7/7] feat(rename) - if the extension did not change, or is not present, dont update mime type - if the file got the extension changed, update to the new one --- .../fs_entry_rename_cubit.dart | 34 ++++++++++++------- pubspec.lock | 4 +-- pubspec.yaml | 2 +- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/lib/blocs/fs_entry_rename/fs_entry_rename_cubit.dart b/lib/blocs/fs_entry_rename/fs_entry_rename_cubit.dart index 5ba4e604ef..8a0d2d7331 100644 --- a/lib/blocs/fs_entry_rename/fs_entry_rename_cubit.dart +++ b/lib/blocs/fs_entry_rename/fs_entry_rename_cubit.dart @@ -29,7 +29,6 @@ class FsEntryRenameCubit extends Cubit { bool get _isRenamingFolder => folderId != null; bool _dontVerifyExtension = false; - String? _newFileExtension; FsEntryRenameCubit({ required this.driveId, @@ -129,22 +128,31 @@ class FsEntryRenameCubit extends Cubit { var file = await _driveDao .fileById(driveId: driveId, fileId: fileId!) .getSingle(); - _newFileExtension = - getFileExtension(name: newName, contentType: file.dataContentType!); - final currentExtension = getFileExtension( - name: file.name, contentType: file.dataContentType!); + if (!updateExtension && !_dontVerifyExtension) { + final newFileExtension = + getFileExtensionFromFileName(fileName: newName); - final hasExtensionChanged = currentExtension != _newFileExtension; + if (newFileExtension.isNotEmpty) { + bool hasExtensionChanged; - if (!updateExtension && !_dontVerifyExtension && hasExtensionChanged) { - emit(UpdatingEntityExtension( - previousExtension: currentExtension, - entityName: newName, - newExtension: _newFileExtension!, - )); + final currentExtension = getFileExtension( + name: file.name, contentType: file.dataContentType!); - return; + hasExtensionChanged = currentExtension != newFileExtension; + + if (hasExtensionChanged) { + emit( + UpdatingEntityExtension( + previousExtension: currentExtension, + entityName: newName, + newExtension: newFileExtension, + ), + ); + + return; + } + } } emit(const FileEntryRenameInProgress()); diff --git a/pubspec.lock b/pubspec.lock index aa2b56179e..39d0be1133 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -84,8 +84,8 @@ packages: dependency: "direct main" description: path: "." - ref: "v1.4.5" - resolved-ref: "286d6366ceffe44e21d1257507090f8b6ec8beaa" + ref: PE-5529-txt-file-extension-changes-incorrectly-in-edit-modal + resolved-ref: "9e43c831ed30c0a2985bc6288c8ae3a4ef4f290d" url: "https://github.com/ar-io/ardrive_io.git" source: git version: "1.4.5" diff --git a/pubspec.yaml b/pubspec.yaml index dfe7d0ff22..aecadf5113 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -160,7 +160,7 @@ dependency_overrides: ardrive_io: git: url: https://github.com/ar-io/ardrive_io.git - ref: v1.4.5 + ref: PE-5529-txt-file-extension-changes-incorrectly-in-edit-modal dev_dependencies: integration_test: