feat: one project sheet for sessions and scheduled tasks
- the scheduled-task scope dropdown becomes the same project sheet the
new-session composer opens: Chat row, project icons, paths, the current
check mark, and one row per checkout
- a filesystem root ("/") no longer reads as a blank row: pathLeaf falls
back to the path itself instead of an empty last segment
- the sheet opens at once and refreshes the project list behind it; an
empty list shows "Loading projects…" until the answer arrives, so the
project chip no longer waits before anything appears
- bump to 0.5.5
This commit is contained in:
1 parent
545778c6f3
commit
a70e9290ef
9 files changed
+338
-127
No files matched your search
@@ -4,13 +4,13 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import '../api/models.dart';
|
||||
import '../state.dart';
|
||||
import '../widgets/composer_attachment.dart';
|
||||
import '../widgets/composer_box.dart';
|
||||
import '../widgets/model_controls.dart';
|
||||
import '../widgets/pet_sprite.dart';
|
||||
import '../widgets/project_icon.dart';
|
||||
import '../widgets/project_picker.dart';
|
||||
import '../widgets/slash_palette.dart';
|
||||
import 'files_panel.dart';
|
||||
import '../l10n.dart';
|
||||
@@ -462,98 +462,18 @@ class _NewSessionScreenState extends State<NewSessionScreen> {
|
||||
|
||||
Future<void> _pickProject() async {
|
||||
final app = widget.app;
|
||||
await Future.wait([app.refreshProjects(), app.refreshFsHome()]);
|
||||
if (!mounted) return;
|
||||
final draft = app.draft;
|
||||
if (draft == null) return;
|
||||
final projects = _selectableProjects(app.projects);
|
||||
await showModalBottomSheet<void>(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
builder: (context) => DraggableScrollableSheet(
|
||||
expand: false,
|
||||
initialChildSize: 0.6,
|
||||
maxChildSize: 0.9,
|
||||
builder: (context, controller) => Column(
|
||||
children: [
|
||||
const Padding(
|
||||
padding: EdgeInsets.fromLTRB(16, 14, 16, 6),
|
||||
child: AppText('Choose project',
|
||||
style:
|
||||
TextStyle(fontSize: 17, fontWeight: FontWeight.w600)),
|
||||
),
|
||||
Expanded(
|
||||
child: ListView(
|
||||
controller: controller,
|
||||
children: [
|
||||
ListTile(
|
||||
dense: true,
|
||||
leading: ProjectIcon(
|
||||
app: widget.app, chat: true, size: 20),
|
||||
title: const AppText('Chat'),
|
||||
subtitle: const AppText('Not tied to a project, saved in OpenChamber\'s chat directory'),
|
||||
trailing: draft.directory == AppState.chatTarget
|
||||
? Icon(Icons.check,
|
||||
size: 18,
|
||||
color: Theme.of(context).colorScheme.primary)
|
||||
: null,
|
||||
onTap: () {
|
||||
app.updateDraftTarget(AppState.chatTarget);
|
||||
_slashLoaded = false;
|
||||
_slashItems = [];
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
for (final project in projects)
|
||||
ListTile(
|
||||
dense: true,
|
||||
leading:
|
||||
ProjectIcon(app: widget.app, project: project, size: 20),
|
||||
title: Text(project.label,
|
||||
maxLines: 1, overflow: TextOverflow.ellipsis),
|
||||
subtitle: Text(project.canonical,
|
||||
maxLines: 1, overflow: TextOverflow.ellipsis),
|
||||
trailing: project.canonical == draft.directory
|
||||
? Icon(Icons.check,
|
||||
size: 18,
|
||||
color: Theme.of(context).colorScheme.primary)
|
||||
: null,
|
||||
onTap: () {
|
||||
app.updateDraftTarget(project.canonical);
|
||||
_slashLoaded = false;
|
||||
_slashItems = [];
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
if (projects.isEmpty)
|
||||
const Padding(
|
||||
padding: EdgeInsets.all(24),
|
||||
child: AppText('No projects available', textAlign: TextAlign.center),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
// The sheet opens right away; it refreshes the project list inside.
|
||||
final choice = await showProjectPicker(
|
||||
context,
|
||||
app: app,
|
||||
selected: draft.directory,
|
||||
);
|
||||
if (choice == null || !mounted) return;
|
||||
app.updateDraftTarget(choice.canonical);
|
||||
_slashLoaded = false;
|
||||
_slashItems = [];
|
||||
}
|
||||
|
||||
/// The picker shows checkouts, not the server's chat folders (those are
|
||||
/// reached by just starting a chat, not by choosing a project). The server
|
||||
/// can list the same path twice (a project record and a sandbox), so one
|
||||
/// path is one row, preferring the one that knows its VCS.
|
||||
List<ProjectInfo> _selectableProjects(List<ProjectInfo> projects) {
|
||||
final byPath = <String, ProjectInfo>{};
|
||||
for (final project in projects) {
|
||||
if (project.canonical.isEmpty) continue;
|
||||
if (widget.app.isChatDirectory(project.canonical)) continue;
|
||||
final existing = byPath[project.canonical];
|
||||
if (existing == null ||
|
||||
(existing.vcs.isEmpty && project.vcs.isNotEmpty)) {
|
||||
byPath[project.canonical] = project;
|
||||
}
|
||||
}
|
||||
return byPath.values.toList();
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import '../api/client.dart';
|
||||
import '../api/models.dart';
|
||||
import '../api/scheduled_tasks.dart';
|
||||
import '../state.dart';
|
||||
import '../widgets/project_picker.dart';
|
||||
import '../widgets/scheduled_task_editor.dart';
|
||||
import '../l10n.dart';
|
||||
|
||||
@@ -49,21 +50,23 @@ class _ScheduledTasksScreenState extends State<ScheduledTasksScreen> {
|
||||
|
||||
List<_TaskScope> _buildScopes() {
|
||||
return [
|
||||
for (final project in app.projects)
|
||||
// A chat's own directory is not a project of its own: every chat
|
||||
// schedules into the chats scope below.
|
||||
if (project.canonical.isNotEmpty && !app.isChatDirectory(project.canonical))
|
||||
_TaskScope(
|
||||
project.metaId.isNotEmpty
|
||||
? project.metaId
|
||||
: Client.projectIdFor(project.canonical),
|
||||
project.label,
|
||||
project.canonical,
|
||||
),
|
||||
_TaskScope(Client.scheduledChatsScope, tr('Chat')),
|
||||
for (final project in selectableProjects(app))
|
||||
_scopeFor(project),
|
||||
_chatsScope,
|
||||
];
|
||||
}
|
||||
|
||||
static _TaskScope _scopeFor(ProjectInfo project) => _TaskScope(
|
||||
project.metaId.isNotEmpty
|
||||
? project.metaId
|
||||
: Client.projectIdFor(project.canonical),
|
||||
project.label,
|
||||
project.canonical,
|
||||
);
|
||||
|
||||
_TaskScope get _chatsScope =>
|
||||
_TaskScope(Client.scheduledChatsScope, tr('Chat'));
|
||||
|
||||
_TaskScope? _defaultScope() {
|
||||
if (_scopes.isEmpty) return null;
|
||||
final directory = app.directory;
|
||||
@@ -260,6 +263,28 @@ class _ScheduledTasksScreenState extends State<ScheduledTasksScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
/// The same sheet the new-session composer uses: checkouts and the Chat
|
||||
/// scope, with the project list refreshed behind it.
|
||||
Future<void> _pickScope() async {
|
||||
final selected =
|
||||
_scope == null || _scope!.directory.isEmpty ? AppState.chatTarget : _scope!.directory;
|
||||
final choice = await showProjectPicker(
|
||||
context,
|
||||
app: app,
|
||||
selected: selected,
|
||||
);
|
||||
if (choice == null || !mounted) return;
|
||||
final next = choice.isChat ? _chatsScope : _scopeFor(choice.project!);
|
||||
if (next.id == _scope?.id) return;
|
||||
setState(() {
|
||||
_scope = next;
|
||||
_tasks = const [];
|
||||
_loading = true;
|
||||
_error = null;
|
||||
});
|
||||
_load();
|
||||
}
|
||||
|
||||
Widget _scopeBar(ThemeData theme) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 6, 8, 6),
|
||||
@@ -270,30 +295,27 @@ class _ScheduledTasksScreenState extends State<ScheduledTasksScreen> {
|
||||
AppText('Runs in', style: TextStyle(fontSize: 13, color: theme.hintColor)),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: DropdownButtonHideUnderline(
|
||||
child: DropdownButton<String>(
|
||||
value: _scope?.id,
|
||||
isExpanded: true,
|
||||
items: [
|
||||
for (final scope in _scopes)
|
||||
DropdownMenuItem(
|
||||
value: scope.id,
|
||||
child: Text(scope.label,
|
||||
maxLines: 1, overflow: TextOverflow.ellipsis),
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
onTap: _pickScope,
|
||||
child: Padding(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 8, vertical: 6),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
_scope?.label ?? tr('Choose project'),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 13.5,
|
||||
color: theme.colorScheme.onSurface),
|
||||
),
|
||||
),
|
||||
],
|
||||
onChanged: (id) {
|
||||
final scope =
|
||||
_scopes.where((s) => s.id == id).cast<_TaskScope?>().firstOrNull;
|
||||
if (scope == null || scope.id == _scope?.id) return;
|
||||
setState(() {
|
||||
_scope = scope;
|
||||
_tasks = const [];
|
||||
_loading = true;
|
||||
_error = null;
|
||||
});
|
||||
_load();
|
||||
},
|
||||
Icon(Icons.expand_more, size: 18, color: theme.hintColor),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
Reference in new issue
Block a user