mirror of
https://codeberg.org/shroff/phylum.git
synced 2026-02-21 04:58:55 -06:00
[client] Remove current location provider
This commit is contained in:
@@ -56,7 +56,7 @@ class _PhylumAppState extends State<PhylumApp> {
|
||||
path: '/home',
|
||||
pageBuilder: (context, state) => NoTransitionPage(
|
||||
name: state.name,
|
||||
child: AppScaffold(folderId: account.userHome),
|
||||
child: AppLayout(folderId: account.userHome),
|
||||
arguments: account.userHome,
|
||||
),
|
||||
),
|
||||
@@ -65,7 +65,7 @@ class _PhylumAppState extends State<PhylumApp> {
|
||||
path: '/folders/:id',
|
||||
pageBuilder: (context, state) => NoTransitionPage(
|
||||
name: state.name,
|
||||
child: AppScaffold(folderId: state.pathParameters['id']!),
|
||||
child: AppLayout(folderId: state.pathParameters['id']!),
|
||||
arguments: state.pathParameters['id'],
|
||||
),
|
||||
),
|
||||
|
||||
@@ -2,33 +2,29 @@ import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:phylum/app_shortcuts.dart';
|
||||
import 'package:phylum/libphylum/phylum_account.dart';
|
||||
import 'package:phylum/ui/app/app_layout.dart';
|
||||
import 'package:phylum/ui/app/nav_forward.dart';
|
||||
import 'package:phylum/util/upload_utils.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class AppActions extends StatelessWidget {
|
||||
final String folderId;
|
||||
final Widget child;
|
||||
const AppActions({super.key, required this.child});
|
||||
const AppActions({super.key, required this.child, required this.folderId});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Actions(
|
||||
actions: {
|
||||
NewFolderIntent: CallbackAction<NewFolderIntent>(onInvoke: (intent) {
|
||||
final folderId = context.read<CurrentLocation>().folderId;
|
||||
return createDirectory(context, folderId);
|
||||
}),
|
||||
UploadFilesIntent: CallbackAction<UploadFilesIntent>(onInvoke: (intent) {
|
||||
final folderId = context.read<CurrentLocation>().folderId;
|
||||
return pickAndUploadFiles(context, folderId);
|
||||
}),
|
||||
UploadFolderIntent: CallbackAction<UploadFolderIntent>(onInvoke: (intent) {
|
||||
final folderId = context.read<CurrentLocation>().folderId;
|
||||
return pickAndUploadDirectory(context, folderId);
|
||||
}),
|
||||
NavUpIntent: CallbackAction<NavUpIntent>(onInvoke: (i) async {
|
||||
final folderId = context.read<CurrentLocation>().folderId;
|
||||
final r = await context.read<PhylumAccount>().resourceRepository.getResource(folderId);
|
||||
final parent = r?.parent;
|
||||
if (parent != null && context.mounted) {
|
||||
|
||||
@@ -4,71 +4,53 @@ import 'package:phylum/ui/app/app_actions.dart';
|
||||
import 'package:phylum/ui/common/expandable_fab.dart';
|
||||
import 'package:phylum/ui/app/nav_list.dart';
|
||||
import 'package:phylum/ui/folder/folder_view.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class CurrentLocation {
|
||||
final String folderId;
|
||||
|
||||
CurrentLocation({required this.folderId});
|
||||
}
|
||||
|
||||
class AppScaffold extends StatelessWidget {
|
||||
final String folderId;
|
||||
|
||||
const AppScaffold({super.key, required this.folderId});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Provider<CurrentLocation>(
|
||||
key: ValueKey(folderId),
|
||||
create: (context) => CurrentLocation(folderId: folderId),
|
||||
builder: (context, child) => AppActions(child: child!),
|
||||
child: const AppLayout(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class AppLayout extends StatelessWidget {
|
||||
const AppLayout({super.key});
|
||||
final String folderId;
|
||||
|
||||
const AppLayout({super.key, required this.folderId});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final expandedLayout = MediaQuery.of(context).size.width > 800;
|
||||
|
||||
return Scaffold(
|
||||
appBar: expandedLayout ? null : AppBar(title: const Text('Phylum')),
|
||||
drawer: expandedLayout
|
||||
? null
|
||||
: const Drawer(
|
||||
child: NavList(
|
||||
showFab: false,
|
||||
)),
|
||||
floatingActionButton: expandedLayout
|
||||
? null
|
||||
: ExpandableFab(
|
||||
distance: 112,
|
||||
children: [
|
||||
ActionButton(
|
||||
icon: const Icon(Icons.create_new_folder),
|
||||
onPressed: () async {
|
||||
Actions.maybeInvoke(context, const NewFolderIntent());
|
||||
},
|
||||
),
|
||||
ActionButton(
|
||||
icon: const Icon(Icons.upload_file),
|
||||
onPressed: () async {
|
||||
Actions.maybeInvoke(context, const UploadFilesIntent());
|
||||
},
|
||||
),
|
||||
ActionButton(
|
||||
icon: const Icon(Icons.drive_folder_upload_outlined),
|
||||
onPressed: () {
|
||||
Actions.maybeInvoke(context, const UploadFolderIntent());
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
body: expandedLayout ? buildExpandedBody() : buildContents(),
|
||||
return AppActions(
|
||||
folderId: folderId,
|
||||
child: Scaffold(
|
||||
appBar: expandedLayout ? null : AppBar(title: const Text('Phylum')),
|
||||
drawer: expandedLayout
|
||||
? null
|
||||
: const Drawer(
|
||||
child: NavList(
|
||||
showFab: false,
|
||||
)),
|
||||
floatingActionButton: expandedLayout
|
||||
? null
|
||||
: ExpandableFab(
|
||||
distance: 112,
|
||||
children: [
|
||||
ActionButton(
|
||||
icon: const Icon(Icons.create_new_folder),
|
||||
onPressed: () async {
|
||||
Actions.maybeInvoke(context, const NewFolderIntent());
|
||||
},
|
||||
),
|
||||
ActionButton(
|
||||
icon: const Icon(Icons.upload_file),
|
||||
onPressed: () async {
|
||||
Actions.maybeInvoke(context, const UploadFilesIntent());
|
||||
},
|
||||
),
|
||||
ActionButton(
|
||||
icon: const Icon(Icons.drive_folder_upload_outlined),
|
||||
onPressed: () {
|
||||
Actions.maybeInvoke(context, const UploadFolderIntent());
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
body: expandedLayout ? buildExpandedBody() : buildContents(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -85,12 +67,12 @@ class AppLayout extends StatelessWidget {
|
||||
}
|
||||
|
||||
Widget buildContents() {
|
||||
return const Column(
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// FolderHeriarchyView(),
|
||||
Expanded(child: FolderView()),
|
||||
Expanded(child: FolderView(folderId: folderId)),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@ class FolderContentsView extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _FolderContentsViewState extends State<FolderContentsView> {
|
||||
final Map<String, FocusNode> nodes = {};
|
||||
late List<Resource> resources;
|
||||
int focusIndex = -1;
|
||||
int selectionStartIndex = -1;
|
||||
@@ -61,9 +60,6 @@ class _FolderContentsViewState extends State<FolderContentsView> {
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
for (final n in nodes.values) {
|
||||
n.dispose();
|
||||
}
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@@ -190,6 +186,7 @@ class _FolderContentsViewState extends State<FolderContentsView> {
|
||||
return ResourceDetailsRow(
|
||||
r: r,
|
||||
onTapDown: (details) {
|
||||
Focus.maybeOf(context)?.requestFocus();
|
||||
final mode = HardwareKeyboard.instance.isControlPressed
|
||||
? SelectionMode.toggle
|
||||
: HardwareKeyboard.instance.isShiftPressed
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
import 'package:state_notifier/state_notifier.dart';
|
||||
|
||||
class FolderNavigatorState {
|
||||
final String root;
|
||||
final String name;
|
||||
final List<(String, String)> _stack;
|
||||
List<(String, String)> get stack => _stack;
|
||||
|
||||
bool get isRoot => _stack.isEmpty;
|
||||
|
||||
String get folderId => isRoot ? root : _stack.last.$1;
|
||||
|
||||
const FolderNavigatorState({required this.root, required this.name, required List<(String, String)> stack}) : _stack = stack;
|
||||
}
|
||||
|
||||
class FolderNavigatorStack extends StateNotifier<FolderNavigatorState> {
|
||||
FolderNavigatorStack(String root, String name) : super(FolderNavigatorState(root: root, name: name, stack: const []));
|
||||
|
||||
bool pop() {
|
||||
return popTo(state._stack.length - 1);
|
||||
}
|
||||
|
||||
bool popTo(int index) {
|
||||
if (state._stack.length <= index) return false;
|
||||
state = FolderNavigatorState(root: state.root, name: state.name, stack: state._stack.sublist(0, index).toList(growable: false));
|
||||
return true;
|
||||
}
|
||||
|
||||
void push(String id, String name) {
|
||||
state = FolderNavigatorState(root: state.root, name: state.name, stack: [...state._stack, (id, name)]);
|
||||
}
|
||||
}
|
||||
@@ -4,14 +4,15 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_state_notifier/flutter_state_notifier.dart';
|
||||
import 'package:phylum/libphylum/db/db.dart';
|
||||
import 'package:phylum/libphylum/phylum_account.dart';
|
||||
import 'package:phylum/ui/app/app_layout.dart';
|
||||
import 'package:phylum/ui/folder/folder_contents_view.dart';
|
||||
import 'package:phylum/ui/folder/folder_empty_view.dart';
|
||||
import 'package:phylum/ui/folder/folder_selection_manager.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class FolderView extends StatelessWidget {
|
||||
const FolderView({super.key});
|
||||
final String folderId;
|
||||
|
||||
const FolderView({super.key, required this.folderId});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -28,7 +29,7 @@ class FolderView extends StatelessWidget {
|
||||
mouseCursor: const WidgetStatePropertyAll(SystemMouseCursors.basic),
|
||||
selectedTileColor: theme.colorScheme.primaryContainer,
|
||||
),
|
||||
child: const FolderWatcher(),
|
||||
child: FolderWatcher(folderId: folderId),
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -36,16 +37,18 @@ class FolderView extends StatelessWidget {
|
||||
}
|
||||
|
||||
class FolderWatcher extends StatelessWidget {
|
||||
const FolderWatcher({super.key});
|
||||
final String folderId;
|
||||
|
||||
const FolderWatcher({super.key, required this.folderId});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => FolderContentsListener(id: context.watch<CurrentLocation>().folderId);
|
||||
Widget build(BuildContext context) => FolderContentsListener(folderId: folderId);
|
||||
}
|
||||
|
||||
class FolderContentsListener extends StatefulWidget {
|
||||
final String id;
|
||||
final String folderId;
|
||||
|
||||
FolderContentsListener({required this.id}) : super(key: ValueKey(id));
|
||||
FolderContentsListener({required this.folderId}) : super(key: ValueKey(folderId));
|
||||
|
||||
@override
|
||||
State<FolderContentsListener> createState() => _FolderContentsListenerState();
|
||||
@@ -62,8 +65,8 @@ class _FolderContentsListenerState extends State<FolderContentsListener> {
|
||||
super.initState();
|
||||
_refresh();
|
||||
final account = context.read<PhylumAccount>();
|
||||
resourceSubscription = account.resourceRepository.watchResource(widget.id).listen((e) => setState(() => resource = e));
|
||||
childrenSubscription = account.resourceRepository.watchChildren(widget.id).listen((e) => setState(() => children = e));
|
||||
resourceSubscription = account.resourceRepository.watchResource(widget.folderId).listen((e) => setState(() => resource = e));
|
||||
childrenSubscription = account.resourceRepository.watchChildren(widget.folderId).listen((e) => setState(() => children = e));
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -74,7 +77,7 @@ class _FolderContentsListenerState extends State<FolderContentsListener> {
|
||||
}
|
||||
|
||||
Future _refresh() {
|
||||
return context.read<PhylumAccount>().resourceRepository.requestResource(widget.id);
|
||||
return context.read<PhylumAccount>().resourceRepository.requestResource(widget.folderId);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -88,7 +91,7 @@ class _FolderContentsListenerState extends State<FolderContentsListener> {
|
||||
return RefreshIndicator(
|
||||
onRefresh: _refresh,
|
||||
child: FolderContentsView(
|
||||
folderId: widget.id,
|
||||
folderId: widget.folderId,
|
||||
resources: children,
|
||||
));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user