|
|
|
|
@ -3,8 +3,10 @@ import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
import 'package:test_sa/extensions/context_extension.dart';
|
|
|
|
|
import 'package:test_sa/extensions/int_extensions.dart';
|
|
|
|
|
import 'package:test_sa/extensions/string_extensions.dart';
|
|
|
|
|
import 'package:test_sa/extensions/text_extensions.dart';
|
|
|
|
|
import 'package:test_sa/extensions/widget_extensions.dart';
|
|
|
|
|
import 'package:test_sa/helper/utils.dart';
|
|
|
|
|
import 'package:test_sa/modules/copilot/model/copilot_message_model.dart';
|
|
|
|
|
import 'package:test_sa/new_views/app_style/app_color.dart';
|
|
|
|
|
import 'package:test_sa/new_views/common_widgets/app_filled_button.dart';
|
|
|
|
|
@ -38,38 +40,37 @@ class _CopilotHistoryPageState extends State<CopilotHistoryPage> {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _openConversation(String threadId) {
|
|
|
|
|
Navigator.push(
|
|
|
|
|
context,
|
|
|
|
|
CupertinoPageRoute(
|
|
|
|
|
builder: (_) => const CopilotChatPage(
|
|
|
|
|
isNewConversation: false,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
).then(
|
|
|
|
|
(_) => context.read<CopilotProvider>().loadHistory(),
|
|
|
|
|
);
|
|
|
|
|
// Navigator.push(
|
|
|
|
|
// context,
|
|
|
|
|
// CupertinoPageRoute(
|
|
|
|
|
// builder: (_) => const CopilotChatPage(
|
|
|
|
|
// isNewConversation: false,
|
|
|
|
|
// ),
|
|
|
|
|
// ),
|
|
|
|
|
// ).then(
|
|
|
|
|
// (_) => context.read<CopilotProvider>().loadHistory(),
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
|
|
context.read<CopilotProvider>().loadConversation(threadId);
|
|
|
|
|
Navigator.pop(context);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _startNewConversation() {
|
|
|
|
|
context.read<CopilotProvider>().startNewConversation();
|
|
|
|
|
|
|
|
|
|
Navigator.push(
|
|
|
|
|
context,
|
|
|
|
|
CupertinoPageRoute(
|
|
|
|
|
builder: (_) => const CopilotChatPage(
|
|
|
|
|
isNewConversation: true,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
).then(
|
|
|
|
|
(_) => context.read<CopilotProvider>().loadHistory(),
|
|
|
|
|
);
|
|
|
|
|
Navigator.pop(context);
|
|
|
|
|
// Navigator.push(
|
|
|
|
|
// context,
|
|
|
|
|
// CupertinoPageRoute(
|
|
|
|
|
// builder: (_) => const CopilotChatPage(
|
|
|
|
|
// isNewConversation: true,
|
|
|
|
|
// ),
|
|
|
|
|
// ),
|
|
|
|
|
// ).then(
|
|
|
|
|
// (_) => context.read<CopilotProvider>().loadHistory(),
|
|
|
|
|
// );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<CopilotHistoryItem> _filteredHistory(
|
|
|
|
|
List<CopilotHistoryItem> history,
|
|
|
|
|
) {
|
|
|
|
|
List<CopilotHistoryItem> _filteredHistory(List<CopilotHistoryItem> history) {
|
|
|
|
|
final query = _searchQuery.trim().toLowerCase();
|
|
|
|
|
|
|
|
|
|
if (query.isEmpty) {
|
|
|
|
|
@ -88,8 +89,10 @@ class _CopilotHistoryPageState extends State<CopilotHistoryPage> {
|
|
|
|
|
title: "Copilot History",
|
|
|
|
|
actions: [
|
|
|
|
|
IconButton(
|
|
|
|
|
icon: const Icon(Icons.chat_bubble),
|
|
|
|
|
onPressed: _startNewConversation,
|
|
|
|
|
style: const ButtonStyle(tapTargetSize: MaterialTapTargetSize.shrinkWrap),
|
|
|
|
|
icon: Icon(Icons.chat_bubble, color: AppColor.icon2Color(context)),
|
|
|
|
|
constraints: const BoxConstraints(),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
@ -106,12 +109,6 @@ class _CopilotHistoryPageState extends State<CopilotHistoryPage> {
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
|
children: [
|
|
|
|
|
const Icon(
|
|
|
|
|
Icons.chat_bubble_outline,
|
|
|
|
|
size: 56,
|
|
|
|
|
color: AppColor.neutral120,
|
|
|
|
|
),
|
|
|
|
|
16.height,
|
|
|
|
|
Text(
|
|
|
|
|
"No conversations yet",
|
|
|
|
|
style: AppTextStyles.heading6.copyWith(
|
|
|
|
|
@ -135,27 +132,20 @@ class _CopilotHistoryPageState extends State<CopilotHistoryPage> {
|
|
|
|
|
final filteredHistory = _filteredHistory(provider.history);
|
|
|
|
|
|
|
|
|
|
return Column(
|
|
|
|
|
spacing: 8,
|
|
|
|
|
children: [
|
|
|
|
|
8.height,
|
|
|
|
|
_buildSearchBar(context),
|
|
|
|
|
8.height,
|
|
|
|
|
if (filteredHistory.isEmpty)
|
|
|
|
|
Expanded(
|
|
|
|
|
child: Column(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
|
children: [
|
|
|
|
|
const Icon(
|
|
|
|
|
Icons.search_off,
|
|
|
|
|
size: 48,
|
|
|
|
|
color: AppColor.neutral120,
|
|
|
|
|
),
|
|
|
|
|
Icon(Icons.search_off, color: AppColor.icon2Color(context), size: 20),
|
|
|
|
|
12.height,
|
|
|
|
|
Text(
|
|
|
|
|
"No conversations found",
|
|
|
|
|
style: AppTextStyles.heading6.copyWith(
|
|
|
|
|
color: AppColor.neutral120,
|
|
|
|
|
),
|
|
|
|
|
style: AppTextStyles.heading6.copyWith(color: AppColor.lightTextColor(context)),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
).center,
|
|
|
|
|
@ -163,18 +153,13 @@ class _CopilotHistoryPageState extends State<CopilotHistoryPage> {
|
|
|
|
|
else
|
|
|
|
|
Expanded(
|
|
|
|
|
child: ListView.separated(
|
|
|
|
|
padding: const EdgeInsets.symmetric(
|
|
|
|
|
horizontal: 16,
|
|
|
|
|
),
|
|
|
|
|
padding: const EdgeInsets.all(16),
|
|
|
|
|
itemCount: filteredHistory.length,
|
|
|
|
|
separatorBuilder: (context, index) => 12.height,
|
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
|
final item = filteredHistory[index];
|
|
|
|
|
|
|
|
|
|
return messageHistoryCard(
|
|
|
|
|
item: item,
|
|
|
|
|
provider: provider,
|
|
|
|
|
);
|
|
|
|
|
return messageHistoryCard(item: item, provider: provider);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
@ -186,91 +171,56 @@ class _CopilotHistoryPageState extends State<CopilotHistoryPage> {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget _buildSearchBar(BuildContext context) {
|
|
|
|
|
return AppTextFormField(
|
|
|
|
|
labelText: "",
|
|
|
|
|
hintText: context.translation.search,
|
|
|
|
|
showBorder: false,
|
|
|
|
|
showShadow: false,
|
|
|
|
|
// backgroundColor: AppColor.fieldBgColor(context),
|
|
|
|
|
prefixIcon: Icon(
|
|
|
|
|
Icons.search,
|
|
|
|
|
color: context.isDark ? AppColor.neutral10 : AppColor.neutral20,
|
|
|
|
|
size: 19,
|
|
|
|
|
return SearchBar(
|
|
|
|
|
// focusNode: searchFocusNode,
|
|
|
|
|
elevation: WidgetStateProperty.all<double>(0),
|
|
|
|
|
backgroundColor: WidgetStateProperty.all<Color?>(AppColor.background(context)),
|
|
|
|
|
leading: Icon(Icons.search, color: AppColor.iconColor(context)),
|
|
|
|
|
textStyle: WidgetStateProperty.all<TextStyle>(
|
|
|
|
|
TextStyle(color: AppColor.textColor(context), fontSize: 16.0),
|
|
|
|
|
),
|
|
|
|
|
textInputType: TextInputType.text,
|
|
|
|
|
contentPadding: EdgeInsets.zero,
|
|
|
|
|
hintStyle: AppTextStyles.bodyText.copyWith(
|
|
|
|
|
color: context.isDark ? AppColor.neutral10 : AppColor.neutral20,
|
|
|
|
|
hintStyle: WidgetStateProperty.all<TextStyle>(
|
|
|
|
|
TextStyle(color: AppColor.textColor(context), fontSize: 14.0),
|
|
|
|
|
),
|
|
|
|
|
style: AppTextStyles.bodyText.copyWith(
|
|
|
|
|
color: AppColor.textStyleColor(context),
|
|
|
|
|
),
|
|
|
|
|
onChange: (value) {
|
|
|
|
|
setState(() {
|
|
|
|
|
_searchQuery = value;
|
|
|
|
|
});
|
|
|
|
|
hintText: 'Search',
|
|
|
|
|
onChanged: (queryString) {
|
|
|
|
|
_searchQuery = queryString;
|
|
|
|
|
setState(() {});
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
.toShadowContainer(
|
|
|
|
|
context,
|
|
|
|
|
showShadow: false,
|
|
|
|
|
)
|
|
|
|
|
.paddingOnly(start: 16, end: 16);
|
|
|
|
|
).paddingOnly(top: 16, start: 16, end: 16);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget messageHistoryCard({
|
|
|
|
|
required CopilotHistoryItem item,
|
|
|
|
|
required CopilotProvider provider,
|
|
|
|
|
}) {
|
|
|
|
|
Widget messageHistoryCard({required CopilotHistoryItem item, required CopilotProvider provider}) {
|
|
|
|
|
return Row(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
|
spacing: 12,
|
|
|
|
|
children: [
|
|
|
|
|
Row(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
|
Icon(
|
|
|
|
|
Icons.chat_bubble,
|
|
|
|
|
color: AppColor.icon2Color(context),
|
|
|
|
|
),
|
|
|
|
|
Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
spacing: 4,
|
|
|
|
|
children: [
|
|
|
|
|
Icon(
|
|
|
|
|
Icons.chat_bubble,
|
|
|
|
|
color: AppColor.icon2Color(context),
|
|
|
|
|
),
|
|
|
|
|
16.width,
|
|
|
|
|
Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
InfoHeaderWidget(
|
|
|
|
|
item.firstHumanMessage,
|
|
|
|
|
),
|
|
|
|
|
4.height,
|
|
|
|
|
InfoTextLabelWidget(
|
|
|
|
|
label: _formatDate(item.updatedAt),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
InfoHeaderWidget(item.firstHumanMessage),
|
|
|
|
|
InfoTextLabelWidget(label: item.updatedAt.toServiceRequestDetailsFormat),
|
|
|
|
|
],
|
|
|
|
|
).expanded,
|
|
|
|
|
IconButton(
|
|
|
|
|
onPressed: () async {
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
await provider.deleteHistory(item.threadId);
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
},
|
|
|
|
|
style: const ButtonStyle(tapTargetSize: MaterialTapTargetSize.shrinkWrap),
|
|
|
|
|
icon: "delete_icon".toSvgAsset(width: 20, height: 20),
|
|
|
|
|
constraints: const BoxConstraints(),
|
|
|
|
|
),
|
|
|
|
|
"delete_icon"
|
|
|
|
|
.toSvgAsset(
|
|
|
|
|
height: 20,
|
|
|
|
|
width: 20,
|
|
|
|
|
)
|
|
|
|
|
.onPress(
|
|
|
|
|
() => provider.deleteHistory(item.threadId),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
.toShadowContainer(
|
|
|
|
|
context,
|
|
|
|
|
showShadow: false,
|
|
|
|
|
)
|
|
|
|
|
.onPress(() {
|
|
|
|
|
).toShadowContainer(context).onPress(() {
|
|
|
|
|
_openConversation(item.threadId);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String _formatDate(DateTime date) {
|
|
|
|
|
return "${date.day.toString().padLeft(2, '0')}/"
|
|
|
|
|
"${date.month.toString().padLeft(2, '0')}/"
|
|
|
|
|
"${date.year} "
|
|
|
|
|
"${date.hour.toString().padLeft(2, '0')}:"
|
|
|
|
|
"${date.minute.toString().padLeft(2, '0')}";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|