Files
pipelines/app/lib/features/chat/files/files_header.dart
T
alan b8fb4d350c Upload files into the shown folder from the chat Files panel
The header gains an Upload button that uses the host file picker (disabled
with its reason where no picker exists), and the panel body becomes a drop
target: on web, document drag events are observed through a dart:js_interop
seam and a file drag over the panel shows a highlight naming the folder.
Each file is posted to POST /files?path=<folder> through an injectable
transport; refusals (exists, sign in, too large) stay visible until dismissed
and the folder reloads afterwards. The list/grid builders move to
files_entries.dart to keep the panel small.
2026-11-09 00:09:01 +00:00

160 lines
5.6 KiB
Dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../../ui/layout/app_overflow_menu.dart';
import '../data/directory_listing.dart';
import '../domain/chat_attachment_picker.dart';
import '../ui/sessions/chat_adaptive.dart';
import 'files_controller.dart';
import 'files_models.dart';
class FilesHeader extends StatelessWidget {
const FilesHeader({
super.key,
required this.controller,
required this.filter,
required this.picker,
required this.onUpload,
});
final FilesController controller;
final TextEditingController filter;
/// The host's file picker; an unsupported host disables Upload with its
/// reason in the tooltip.
final ChatAttachmentPicker picker;
final VoidCallback onUpload;
bool get _canUpload =>
picker.isSupported &&
controller.listing != null &&
!controller.loading &&
controller.uploading == 0;
@override
Widget build(BuildContext context) {
final listing = controller.listing;
return Padding(
padding: const EdgeInsets.fromLTRB(12, 8, 8, 4),
child: Column(
children: [
Row(
children: [
if (listing?.parent != null)
IconButton(
tooltip: 'Back',
onPressed: controller.loading
? null
: () => controller.open(listing!.parent),
icon: const Icon(Icons.arrow_back),
),
Expanded(
child: Text(
homeRelativeLabel(
listing?.home ?? '',
listing?.path ?? controller.initialPath,
),
overflow: TextOverflow.ellipsis,
),
),
IconButton(
tooltip: picker.isSupported
? 'Upload files'
: 'Upload files: ${picker.unsupportedMessage}',
onPressed: _canUpload ? onUpload : null,
icon: const Icon(Icons.upload_file),
),
IconButton(
tooltip: 'Refresh',
onPressed: controller.loading ? null : controller.retry,
icon: const Icon(Icons.refresh),
),
IconButton(
tooltip: controller.view == FilesViewMode.list
? 'Grid view'
: 'List view',
onPressed: () => controller.setView(
controller.view == FilesViewMode.list
? FilesViewMode.grid
: FilesViewMode.list,
),
icon: Icon(
controller.view == FilesViewMode.list
? Icons.grid_view
: Icons.view_list,
),
),
AppOverflowMenu<FilesSortKey>(
label: 'Sort',
onSelected: (_, key) =>
controller.setSort(controller.sort.reverseOr(key)),
actions: [
for (final key in FilesSortKey.values)
AppMenuAction(
value: key,
label:
'${key.name}${controller.sort.key == key ? (controller.sort.ascending ? ' ↑' : ' ↓') : ''}',
),
],
),
],
),
if (listing != null)
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: [
for (final crumb in folderCrumbs(listing.home, listing.path))
chatControlsStyleOf(context) == ChatControlsStyle.cupertino
? CupertinoButton(
padding: const EdgeInsets.symmetric(horizontal: 6),
onPressed: controller.loading
? null
: () => controller.open(crumb.path),
child: Text(crumb.label),
)
: TextButton(
onPressed: controller.loading
? null
: () => controller.open(crumb.path),
child: Text(crumb.label),
),
],
),
),
Row(
children: [
Expanded(
child:
chatControlsStyleOf(context) == ChatControlsStyle.cupertino
? CupertinoSearchTextField(
controller: filter,
onChanged: controller.setFilter,
placeholder: 'Filter files',
)
: TextField(
controller: filter,
onChanged: controller.setFilter,
decoration: const InputDecoration(
prefixIcon: Icon(Icons.search),
hintText: 'Filter files',
isDense: true,
),
),
),
IconButton(
tooltip: 'Show hidden files',
onPressed: () =>
controller.toggleHidden(!controller.showHidden),
icon: Icon(
controller.showHidden
? Icons.visibility
: Icons.visibility_off,
),
),
],
),
],
),
);
}
}