feat(app): create, rename, star, close and hide chat sessions
This commit is contained in:
@@ -2,57 +2,123 @@ import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/core/transport/connection_state.dart';
|
||||
import 'package:pipelines_app/features/chat/session_screen.dart';
|
||||
|
||||
/// Stateful chat-session fixture for the real-browser probe: every accepted
|
||||
/// mutation changes the list the next `chat_sessions` read returns, so the
|
||||
/// screen must refresh from the server rather than guess. A title of
|
||||
/// `Refused title` is refused with the server's words; `No session title`
|
||||
/// returns a create reply without `chat_session`; `?unseen=1` reports newer
|
||||
/// recency after the first read so the `New` marker can be observed.
|
||||
class _FixtureGateway implements ApiGateway {
|
||||
_FixtureGateway({this.bumpAfterFirstRead = false});
|
||||
|
||||
/// `?unseen=1`: the first list read seeds the device watermark and later
|
||||
/// reads report newer activity, so the browser can prove the `New` marker.
|
||||
final bool bumpAfterFirstRead;
|
||||
int _reads = 0;
|
||||
|
||||
final _sessions = <JsonMap>[
|
||||
{
|
||||
'id': 'probe-open',
|
||||
'title': 'Open fixture',
|
||||
'directory': '/workspace/demo',
|
||||
'starred': true,
|
||||
},
|
||||
{
|
||||
'id': 'probe-closed',
|
||||
'title': 'Closed fixture',
|
||||
'directory': '/workspace/archive',
|
||||
'closed_at': '2026-01-01',
|
||||
},
|
||||
{
|
||||
'id': 'probe-stream',
|
||||
'title': 'Streaming fixture',
|
||||
'directory': '/workspace/demo',
|
||||
'running': true,
|
||||
},
|
||||
];
|
||||
int _nextId = 1;
|
||||
|
||||
@override
|
||||
Stream<JsonMap> get frames => const Stream.empty();
|
||||
|
||||
@override
|
||||
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async {
|
||||
if (type == 'chat_sessions') {
|
||||
return {
|
||||
'chat_sessions': [
|
||||
{
|
||||
'id': 'probe-open',
|
||||
'title': 'Open fixture',
|
||||
'directory': '/workspace/demo',
|
||||
'starred': true,
|
||||
},
|
||||
{
|
||||
'id': 'probe-closed',
|
||||
'title': 'Closed fixture',
|
||||
'directory': '/workspace/archive',
|
||||
'closed_at': '2026-01-01',
|
||||
},
|
||||
{
|
||||
'id': 'probe-stream',
|
||||
'title': 'Streaming fixture',
|
||||
'directory': '/workspace/demo',
|
||||
'running': true,
|
||||
},
|
||||
],
|
||||
};
|
||||
switch (type) {
|
||||
case 'chat_sessions':
|
||||
_reads++;
|
||||
return {
|
||||
'chat_sessions': [for (final session in _sessions) _row(session)],
|
||||
};
|
||||
case 'chat_directories':
|
||||
return {
|
||||
'chat_directories': [
|
||||
'/workspace/demo',
|
||||
'/workspace/archive',
|
||||
'/Users/alan/repos/pipelines/tmp/flutter-chat-list',
|
||||
],
|
||||
};
|
||||
case 'chat_backends':
|
||||
return {
|
||||
'chat_backends': ['opencode', 'codex'],
|
||||
};
|
||||
case 'chat_create':
|
||||
final body = fields['chat_create']! as JsonMap;
|
||||
// The web's exact refusal for a reply without a created session.
|
||||
if ('${body['title']}' == 'No session title') return const {};
|
||||
final session = {
|
||||
'id': 'probe-new-${_nextId++}',
|
||||
'title': body['title'],
|
||||
'directory': body['directory'],
|
||||
};
|
||||
_sessions.insert(0, session);
|
||||
return {'chat_session': Map<String, dynamic>.from(session)};
|
||||
case 'chat_rename':
|
||||
final body = fields['chat_rename']! as JsonMap;
|
||||
if ('${body['title']}' == 'Refused title') {
|
||||
throw const ProtocolError('a title with usable text is required');
|
||||
}
|
||||
_update('${body['session_id']}', 'title', body['title']);
|
||||
return const {};
|
||||
case 'chat_star':
|
||||
final body = fields['chat_query']! as JsonMap;
|
||||
_update('${body['session_id']}', 'starred', body['starred']);
|
||||
return const {};
|
||||
case 'chat_close':
|
||||
final body = fields['chat_query']! as JsonMap;
|
||||
_update('${body['session_id']}', 'closed_at', '2026-01-02');
|
||||
return const {};
|
||||
case 'chat_reopen':
|
||||
final body = fields['chat_query']! as JsonMap;
|
||||
// A refusal long enough to need several lines at 320px with 2x text.
|
||||
if ('${body['session_id']}' == 'probe-closed') {
|
||||
throw const ProtocolError(
|
||||
'the chat is locked by another operator and cannot be reopened '
|
||||
'from here; refresh the list to see its current state',
|
||||
);
|
||||
}
|
||||
_update('${body['session_id']}', 'closed_at', null);
|
||||
return const {};
|
||||
default:
|
||||
return {'chat_session': {}};
|
||||
}
|
||||
if (type == 'chat_directories') {
|
||||
return {
|
||||
'chat_directories': ['/workspace/demo', '/workspace/archive'],
|
||||
};
|
||||
}
|
||||
|
||||
void _update(String id, String key, Object? value) {
|
||||
for (final session in _sessions) {
|
||||
if (session['id'] == id) session[key] = value;
|
||||
}
|
||||
if (type == 'chat_backends') {
|
||||
return {
|
||||
'chat_backends': ['opencode', 'codex'],
|
||||
};
|
||||
}
|
||||
|
||||
JsonMap _row(JsonMap session) {
|
||||
final row = Map<String, dynamic>.from(session);
|
||||
if (bumpAfterFirstRead &&
|
||||
(row['id'] == 'probe-open' || row['id'] == 'probe-closed')) {
|
||||
row['updated_at'] = _reads > 1 ? 2000 : 1000;
|
||||
}
|
||||
if (type == 'chat_create') {
|
||||
return {
|
||||
'chat_session': {
|
||||
'id': 'probe-new',
|
||||
'title': 'New fixture',
|
||||
'directory': '/workspace/demo',
|
||||
},
|
||||
};
|
||||
}
|
||||
return {'chat_session': {}};
|
||||
return row;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,14 +128,29 @@ const _probeStyle = String.fromEnvironment(
|
||||
);
|
||||
|
||||
void main() {
|
||||
final home = ChatSessionsScreen(gateway: _FixtureGateway(), onOpen: (_) {});
|
||||
final dark = Uri.base.queryParameters['dark'] == '1';
|
||||
final unseen = Uri.base.queryParameters['unseen'] == '1';
|
||||
final home = ChatSessionsScreen(
|
||||
gateway: _FixtureGateway(bumpAfterFirstRead: unseen),
|
||||
onOpen: (_) {},
|
||||
);
|
||||
if (_probeStyle == 'cupertino') {
|
||||
runApp(CupertinoApp(home: home));
|
||||
runApp(
|
||||
CupertinoApp(
|
||||
theme: CupertinoThemeData(
|
||||
brightness: dark ? Brightness.dark : Brightness.light,
|
||||
),
|
||||
home: home,
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
runApp(
|
||||
MaterialApp(
|
||||
theme: ThemeData(platform: TargetPlatform.android),
|
||||
theme: ThemeData(
|
||||
platform: TargetPlatform.android,
|
||||
brightness: dark ? Brightness.dark : Brightness.light,
|
||||
),
|
||||
home: home,
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user