Restore local chat layouts and add compact or hidden chat sidebar
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../../../core/api_gateway.dart';
|
||||
import '../../domain/chat_cycle.dart';
|
||||
import '../../domain/chat_sessions.dart';
|
||||
import 'chat_adaptive.dart';
|
||||
import 'chat_sessions_body.dart';
|
||||
import 'chat_sessions_controller.dart';
|
||||
|
||||
/// A small, scrollable device-local rail. Full titles remain accessible.
|
||||
class ChatCompactSidebar extends StatelessWidget {
|
||||
const ChatCompactSidebar({
|
||||
super.key,
|
||||
required this.controller,
|
||||
required this.folds,
|
||||
required this.activeSessionId,
|
||||
required this.onOpen,
|
||||
required this.onExpand,
|
||||
});
|
||||
final ChatSessionsController controller;
|
||||
final ChatSectionFolds folds;
|
||||
final String? activeSessionId;
|
||||
final ValueChanged<JsonMap> onOpen;
|
||||
final VoidCallback onExpand;
|
||||
static const width = 72.0;
|
||||
|
||||
Widget _button(
|
||||
BuildContext context,
|
||||
String title,
|
||||
Widget icon,
|
||||
VoidCallback onPressed, {
|
||||
bool selected = false,
|
||||
}) {
|
||||
final cupertino =
|
||||
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
||||
return Semantics(
|
||||
selected: selected,
|
||||
child: cupertino
|
||||
? Tooltip(
|
||||
message: title,
|
||||
child: CupertinoButton(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
onPressed: onPressed,
|
||||
child: icon,
|
||||
),
|
||||
)
|
||||
: IconButton(
|
||||
tooltip: title,
|
||||
onPressed: onPressed,
|
||||
icon: icon,
|
||||
color: selected ? Theme.of(context).colorScheme.primary : null,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Align(
|
||||
alignment: AlignmentDirectional.topStart,
|
||||
child: SizedBox(
|
||||
width: width,
|
||||
child: Column(
|
||||
children: [
|
||||
_button(
|
||||
context,
|
||||
'Expand chat list',
|
||||
Icon(
|
||||
chatControlsStyleOf(context) == ChatControlsStyle.cupertino
|
||||
? CupertinoIcons.sidebar_left
|
||||
: Icons.menu_open,
|
||||
),
|
||||
onExpand,
|
||||
),
|
||||
Expanded(
|
||||
child: ListenableBuilder(
|
||||
listenable: Listenable.merge([controller, folds]),
|
||||
builder: (context, _) {
|
||||
final rows = chatSessionsShown(
|
||||
controller.sessions,
|
||||
query: '',
|
||||
isOpen: folds.isOpen,
|
||||
);
|
||||
return ListView(
|
||||
children: [
|
||||
for (final row in rows)
|
||||
_button(
|
||||
context,
|
||||
chatSessionTitle(row),
|
||||
Text(
|
||||
chatSessionTitle(row).characters.take(2).toString(),
|
||||
style: TextStyle(
|
||||
fontWeight: row['id'] == activeSessionId
|
||||
? FontWeight.bold
|
||||
: null,
|
||||
),
|
||||
),
|
||||
() {
|
||||
unawaited(controller.markOpened(row));
|
||||
onOpen(row);
|
||||
},
|
||||
selected: row['id'] == activeSessionId,
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user