mirror of
https://codeberg.org/shroff/phylum.git
synced 2026-01-05 19:21:23 -06:00
[client] Local conflict resolution for mkdir
This commit is contained in:
@@ -72,13 +72,16 @@ class ResourceMkdirAction extends ResourceCreateAction with JsonApiAction {
|
||||
Future<void> applyOptimisticUpdate() async {
|
||||
await account.db.createResource(resourceId, parent, localName, true, timestamp);
|
||||
if (deletedId != null) {
|
||||
account.db.updateResource(deletedId!, (u) => u(parent: Value(null)));
|
||||
await account.db.updateResource(deletedId!, (u) => u(parent: Value(null)));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> revertOptimisticUpdate() {
|
||||
return account.db.deleteResource(resourceId);
|
||||
Future<void> revertOptimisticUpdate() async {
|
||||
await account.db.deleteResource(resourceId);
|
||||
if (deletedId != null) {
|
||||
await account.db.updateResource(deletedId!, (u) => u(parent: Value(parent)));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -19,7 +19,7 @@ final illegalChars = <int>{
|
||||
bool validateName(String name) =>
|
||||
!name.startsWith(' ') && name != '.' && name != '..' && name.trim().isNotEmpty && !name.runes.any((c) => c < 31 || illegalChars.contains(c));
|
||||
|
||||
void createDirectory(BuildContext context, String folderId) async {
|
||||
Future<void> createDirectory(BuildContext context, String folderId) async {
|
||||
final account = context.read<PhylumAccount>();
|
||||
final dirName = await showInputDialog(
|
||||
context,
|
||||
@@ -28,7 +28,44 @@ void createDirectory(BuildContext context, String folderId) async {
|
||||
validate: validateName,
|
||||
);
|
||||
if (dirName == null || dirName == "") return;
|
||||
account.resourceRepository.mkdir(parent: folderId, name: dirName);
|
||||
try {
|
||||
await account.resourceRepository.mkdir(parent: folderId, name: dirName);
|
||||
} on NameConflictException {
|
||||
if (!context.mounted) return;
|
||||
final conflictResolution = await showDialog<NameConflictResolution>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('Name Conflict'),
|
||||
content: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 360),
|
||||
child: Text(
|
||||
'There is already another item with the name \'$dirName\' in this folder.',
|
||||
softWrap: true,
|
||||
),
|
||||
),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
child: Text('Delete'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop(nameConflictDelete);
|
||||
},
|
||||
),
|
||||
ElevatedButton(
|
||||
autofocus: true,
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop(nameConflictRename);
|
||||
},
|
||||
child: Text('Rename'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
if (conflictResolution == null) return;
|
||||
await account.resourceRepository.mkdir(parent: folderId, name: dirName, conflictResolution: conflictResolution);
|
||||
} catch (e) {
|
||||
if (!context.mounted) return;
|
||||
await showAlertDialog(context, title: 'Error while creating directory', message: e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
void pickAndUploadFiles(BuildContext context, String folderId) async {
|
||||
|
||||
Reference in New Issue
Block a user