138 lines
4.1 KiB
Dart
138 lines
4.1 KiB
Dart
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 '../../domain/chat_colors.dart';
|
|
import 'chat_color_palette.dart';
|
|
import 'chat_visibility_marker.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,
|
|
this.visibleSessionIds = const {},
|
|
required this.onOpen,
|
|
required this.onExpand,
|
|
});
|
|
final ChatSessionsController controller;
|
|
final ChatSectionFolds folds;
|
|
final String? activeSessionId;
|
|
final Set<String> visibleSessionIds;
|
|
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,
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _session(BuildContext context, JsonMap row) {
|
|
final id = '${row['id'] ?? ''}';
|
|
final selected = id == activeSessionId;
|
|
final color =
|
|
chatColorShade(context, chatSessionColor(row)) ??
|
|
(chatControlsStyleOf(context) == ChatControlsStyle.cupertino
|
|
? CupertinoTheme.of(context).primaryColor
|
|
: Theme.of(context).colorScheme.primary);
|
|
return ChatVisibilityMarker(
|
|
sessionId: id,
|
|
color: color,
|
|
visible: visibleSessionIds.contains(id),
|
|
active: selected,
|
|
child: AnimatedContainer(
|
|
duration: MediaQuery.disableAnimationsOf(context)
|
|
? Duration.zero
|
|
: const Duration(milliseconds: 200),
|
|
color: selected ? Colors.transparent : color.withValues(alpha: .07),
|
|
child: _button(
|
|
context,
|
|
chatSessionTitle(row),
|
|
CircleAvatar(
|
|
foregroundColor: color,
|
|
backgroundColor: color.withValues(alpha: selected ? .26 : .12),
|
|
child: Text(
|
|
chatSessionTitle(row).characters.take(2).toString(),
|
|
style: TextStyle(fontWeight: selected ? FontWeight.bold : null),
|
|
),
|
|
),
|
|
() {
|
|
unawaited(controller.markOpened(row));
|
|
onOpen(row);
|
|
},
|
|
selected: selected,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
@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) _session(context, row)],
|
|
);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|