Skip to content

Commit

Permalink
Merge pull request #260 from ardriveapp/dev
Browse files Browse the repository at this point in the history
Release 1.2.4
  • Loading branch information
javdhu authored Nov 4, 2021
2 parents 79017b4 + 65a1ae3 commit 3ae2925
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 25 deletions.
61 changes: 45 additions & 16 deletions lib/blocs/fs_entry_move/fs_entry_move_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,21 @@ class FsEntryMoveCubit extends Cubit<FsEntryMoveState> {
);
}

Future<bool> entityNameExists({
required String name,
required String parentFolderId,
}) async {
final foldersWithName = await _driveDao
.foldersInFolderWithName(
driveId: driveId, parentFolderId: parentFolderId, name: name)
.get();
final filesWithName = await _driveDao
.filesInFolderWithName(
driveId: driveId, parentFolderId: parentFolderId, name: name)
.get();
return foldersWithName.isNotEmpty || filesWithName.isNotEmpty;
}

Future<void> submit() async {
try {
final state = this.state as FsEntryMoveFolderLoadSuccess;
Expand All @@ -81,15 +96,23 @@ class FsEntryMoveCubit extends Cubit<FsEntryMoveState> {
}
if (_isMovingFolder) {
emit(FolderEntryMoveInProgress());

var folder = await _driveDao
.folderById(driveId: driveId, folderId: folderId!)
.getSingle();

if (await entityNameExists(
name: folder.name,
parentFolderId: parentFolder!.id,
)) {
emit(FsEntryMoveNameConflict(name: folder.name));
return;
}
await _driveDao.transaction(() async {
var folder = await _driveDao
.folderById(driveId: driveId, folderId: folderId!)
.getSingle();
folder = folder.copyWith(
parentFolderId: parentFolder!.id,
path: '${parentFolder.path}/${folder.name}',
lastUpdated: DateTime.now());
parentFolderId: parentFolder.id,
path: '${parentFolder.path}/${folder.name}',
lastUpdated: DateTime.now(),
);

final folderEntity = folder.asEntity();

Expand All @@ -109,16 +132,22 @@ class FsEntryMoveCubit extends Cubit<FsEntryMoveState> {
emit(FolderEntryMoveSuccess());
} else {
emit(FileEntryMoveInProgress());

var file = await _driveDao
.fileById(driveId: driveId, fileId: fileId!)
.getSingle();
file = file.copyWith(
parentFolderId: parentFolder!.id,
path: '${parentFolder.path}/${file.name}',
lastUpdated: DateTime.now());

if (await entityNameExists(
name: file.name,
parentFolderId: parentFolder.id,
)) {
emit(FsEntryMoveNameConflict(name: file.name));
return;
}
await _driveDao.transaction(() async {
var file = await _driveDao
.fileById(driveId: driveId, fileId: fileId!)
.getSingle();
file = file.copyWith(
parentFolderId: parentFolder!.id,
path: '${parentFolder.path}/${file.name}',
lastUpdated: DateTime.now());

final fileKey =
driveKey != null ? await deriveFileKey(driveKey, file.id) : null;

Expand Down
11 changes: 11 additions & 0 deletions lib/blocs/fs_entry_move/fs_entry_move_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ class FsEntryMoveFolderLoadSuccess extends FsEntryMoveState {
[viewingRootFolder, viewingFolder, movingEntryId, isMovingFolder];
}

class FsEntryMoveNameConflict extends FsEntryMoveState {
final String name;
FsEntryMoveNameConflict({
required this.name,
}) : super(
isMovingFolder: true,
);
@override
List<Object> get props => [name];
}

class FolderEntryMoveInProgress extends FsEntryMoveState {
FolderEntryMoveInProgress() : super(isMovingFolder: true);
}
Expand Down
45 changes: 38 additions & 7 deletions lib/components/fs_entry_move_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,35 @@ class FsEntryMoveForm extends StatelessWidget {
} else if (state is FolderEntryMoveWalletMismatch ||
state is FileEntryMoveWalletMismatch) {
Navigator.pop(context);
} else if (state is FsEntryMoveNameConflict) {
Navigator.pop(context);
Navigator.pop(context);
showDialog(
context: context,
builder: (BuildContext context) => AppDialog(
dismissable: true,
title: 'Name Conflict',
content: SizedBox(
width: kSmallDialogWidth,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Center(
child: Text(
'Entity with name ${state.name} already exists at move destination! '
'Please rename the file or folder you are moving and try again.',
),
),
],
),
),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: Text('OK')),
],
),
);
}
},
builder: (context, state) {
Expand Down Expand Up @@ -108,19 +137,21 @@ class FsEntryMoveForm extends StatelessWidget {
const SizedBox(height: 16),
if (!state.viewingRootFolder)
Padding(
padding: const EdgeInsets.only(
left: 16, right: 16, bottom: 8),
child: TextButton.icon(
padding: const EdgeInsets.only(bottom: 8),
child: TextButton(
style: TextButton.styleFrom(
textStyle:
Theme.of(context).textTheme.subtitle2,
padding: const EdgeInsets.all(16)),
icon: const Icon(Icons.arrow_back),
label: Text(
'Back to "${state.viewingFolder.folder!.name}" folder'),
onPressed: () => context
.read<FsEntryMoveCubit>()
.loadParentFolder()),
.loadParentFolder(),
child: ListTile(
dense: true,
leading: const Icon(Icons.arrow_back),
title: Text(
'Back to "${state.viewingFolder.folder!.name}" folder'),
)),
),
Expanded(
child: Padding(
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ publish_to: 'none'
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.2.3
version: 1.2.4

environment:
sdk: '>=2.12.0 <3.0.0'
Expand Down
2 changes: 1 addition & 1 deletion web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
</script>
<script defer src="pst.min.js"></script>
<script defer src="sql-wasm.js"></script>
<script src="main.dart.js?version=23" type="application/javascript"></script>
<script src="main.dart.js?version=24" type="application/javascript"></script>

</body>

Expand Down

0 comments on commit 3ae2925

Please sign in to comment.