mirror of
https://codeberg.org/shroff/phylum.git
synced 2026-01-06 19:49:56 -06:00
[client] Delete shortcut, fix delete/rename optimistic updateS
This commit is contained in:
@@ -33,6 +33,10 @@ class OpenIntent extends Intent {
|
||||
const OpenIntent();
|
||||
}
|
||||
|
||||
class DeleteIntent extends Intent {
|
||||
const DeleteIntent();
|
||||
}
|
||||
|
||||
class NavUpIntent extends Intent {
|
||||
const NavUpIntent();
|
||||
}
|
||||
@@ -46,9 +50,10 @@ Map<ShortcutActivator, Intent> getAppShortcuts() {
|
||||
SingleActivator(LogicalKeyboardKey.arrowDown, shift: true): FocusDownIntent(SelectionMode.range),
|
||||
SingleActivator(LogicalKeyboardKey.arrowDown, control: true): FocusDownIntent(SelectionMode.multi),
|
||||
SingleActivator(LogicalKeyboardKey.space, control: true): ToggleSelectionIntent(),
|
||||
SingleActivator(LogicalKeyboardKey.enter): OpenIntent(),
|
||||
SingleActivator(LogicalKeyboardKey.arrowUp, alt: true): NavUpIntent(),
|
||||
SingleActivator(LogicalKeyboardKey.escape): ClearSelectionIntent(),
|
||||
SingleActivator(LogicalKeyboardKey.keyA, control: true): SelectAllIntent(),
|
||||
SingleActivator(LogicalKeyboardKey.arrowUp, alt: true): NavUpIntent(),
|
||||
SingleActivator(LogicalKeyboardKey.enter): OpenIntent(),
|
||||
SingleActivator(LogicalKeyboardKey.delete): DeleteIntent(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -47,12 +47,12 @@ class ResourceDeleteAction extends ApiAction<PhylumAccount> with JsonApiAction {
|
||||
|
||||
@override
|
||||
FutureOr<void> applyOptimisticUpdate(PhylumAccount account) {
|
||||
account.datastore.db.managers.resources.update((o) => o(deleted: const Value(true)));
|
||||
account.datastore.db.managers.resources.filter((f) => f.id.equals(id)).update((o) => o(deleted: const Value(true)));
|
||||
}
|
||||
|
||||
@override
|
||||
FutureOr<void> revertOptimisticUpdate(PhylumAccount account) {
|
||||
account.datastore.db.managers.resources.update((o) => o(deleted: const Value(false)));
|
||||
account.datastore.db.managers.resources.filter((f) => f.id.equals(id)).update((o) => o(deleted: const Value(false)));
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -53,12 +53,12 @@ class ResourceRenameAction extends ApiAction<PhylumAccount> with JsonApiAction {
|
||||
|
||||
@override
|
||||
FutureOr<void> applyOptimisticUpdate(PhylumAccount account) {
|
||||
account.datastore.db.managers.resources.update((o) => o(name: Value(newName)));
|
||||
account.datastore.db.managers.resources.filter((f) => f.id.equals(id)).update((o) => o(name: Value(newName)));
|
||||
}
|
||||
|
||||
@override
|
||||
FutureOr<void> revertOptimisticUpdate(PhylumAccount account) {
|
||||
account.datastore.db.managers.resources.update((o) => o(name: Value(oldName)));
|
||||
account.datastore.db.managers.resources.filter((f) => f.id.equals(id)).update((o) => o(name: Value(oldName)));
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -2,11 +2,15 @@ import 'dart:math';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:phylum/app.dart';
|
||||
import 'package:phylum/app_shortcuts.dart';
|
||||
import 'package:phylum/libphylum/actions/action_resource_delete.dart';
|
||||
import 'package:phylum/libphylum/db/db.dart';
|
||||
import 'package:phylum/libphylum/phylum_account.dart';
|
||||
import 'package:phylum/ui/folder/folder_navigator_stack.dart';
|
||||
import 'package:phylum/ui/folder/folder_selection_manager.dart';
|
||||
import 'package:phylum/ui/folder/resource_details_row.dart';
|
||||
import 'package:phylum/util/dialogs.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class FolderContentsView extends StatefulWidget {
|
||||
@@ -76,12 +80,16 @@ class _FolderContentsViewState extends State<FolderContentsView> {
|
||||
context.read<FolderSelectionManager>().setSelected(const {});
|
||||
return null;
|
||||
}),
|
||||
NavUpIntent: CallbackAction<NavUpIntent>(onInvoke: (i) {
|
||||
context.read<FolderNavigatorStack>().pop();
|
||||
return null;
|
||||
}),
|
||||
OpenIntent: CallbackAction<OpenIntent>(onInvoke: (i) {
|
||||
open(resources[focusIndex]);
|
||||
return null;
|
||||
}),
|
||||
NavUpIntent: CallbackAction<NavUpIntent>(onInvoke: (i) {
|
||||
context.read<FolderNavigatorStack>().pop();
|
||||
DeleteIntent: CallbackAction<DeleteIntent>(onInvoke: (i) {
|
||||
deleteSelected();
|
||||
return null;
|
||||
}),
|
||||
},
|
||||
@@ -142,6 +150,21 @@ class _FolderContentsViewState extends State<FolderContentsView> {
|
||||
if (r.dir) context.read<FolderNavigatorStack>().push(r.id, r.name);
|
||||
}
|
||||
|
||||
void deleteSelected() async {
|
||||
final selectedIds = context.read<FolderSelectionState>().selected;
|
||||
if (selectedIds.isEmpty) return;
|
||||
final account = context.read<PhylumAccount>();
|
||||
final selected = resources.where((r) => selectedIds.contains(r.id)).toList(growable: false);
|
||||
final confirm = await showAlertDialog(context,
|
||||
title: 'Delete ${selectedIds.length} files?', barrierDismissible: true, positiveText: 'YES', negativeText: 'NO') ??
|
||||
false;
|
||||
|
||||
if (!confirm) return;
|
||||
for (final r in selected) {
|
||||
account.addAction(ResourceDeleteAction(r: r));
|
||||
}
|
||||
}
|
||||
|
||||
FocusNode getFocusNode(Resource r) {
|
||||
return nodes.putIfAbsent(r.id, () => FocusNode(descendantsAreTraversable: false));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user