fig for name changer

This commit is contained in:
stasex 2023-11-24 00:16:34 +02:00
parent 06ae71960b
commit 4754a2b07c
2 changed files with 38 additions and 3 deletions

View File

@ -37,6 +37,29 @@ class SearchService {
String? wishlistId;
Future<String?> generateNameForPersonalWishlist(String wishlistId) async {
final options = MutationOptions(
document: gql('''
mutation GenerateNameForPersonalWishlist(\$wishlistId: String!) {
generateNameForPersonalWishlist(wishlistId: \$wishlistId) {
id
name
}
}
'''),
variables: {'wishlistId': wishlistId},
);
final result = await client.mutate(options);
if (result != null && result.containsKey('generateNameForPersonalWishlist')) {
final name = result['generateNameForPersonalWishlist']['name'];
return name;
}
return null;
}
Future<void> startPersonalWishlist(String message) async {
await _authenticationService.initialize();

View File

@ -46,8 +46,8 @@ class MessageBubble extends StatelessWidget {
print('View Product button pressed');
},
style: ElevatedButton.styleFrom(
primary: Colors.indigo,
onPrimary: Colors.white,
primary: Colors.indigo,
onPrimary: Colors.white,
minimumSize: Size(300, 50)
),
child: Text('View Product'),
@ -72,11 +72,13 @@ class ChatScreenState extends State<ChatScreen> {
bool isSendButtonEnabled = false;
bool showButtonsContainer = true;
final ScrollController _scrollController = ScrollController();
late Widget appBarTitle;
String wishlistId = '';
void initState() {
super.initState();
appBarTitle = Text('New Chat');
_searchService.sseStream.listen((event) {
_handleSSEMessage(Message(text: '${event.data}'));
});
@ -100,6 +102,15 @@ class ChatScreenState extends State<ChatScreen> {
_scrollToBottom();
}
Future<void> updateChatTitle(String wishlistId) async {
final wishlistName = await _searchService.generateNameForPersonalWishlist(wishlistId);
if (wishlistName != null) {
setState(() {
// Оновіть назву чату з результатом методу generateNameForPersonalWishlist
appBarTitle = Text(wishlistName);
});
}
}
Future<void> _startPersonalWishlist(String message) async {
setState(() {
@ -108,6 +119,7 @@ class ChatScreenState extends State<ChatScreen> {
});
await _searchService.initializeAuthenticationService();
await _searchService.startPersonalWishlist(message);
updateChatTitle(_searchService.wishlistId.toString());
_scrollToBottom();
}
@ -172,7 +184,7 @@ class ChatScreenState extends State<ChatScreen> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('New Chat'),
title: appBarTitle,
centerTitle: true,
leading: IconButton(
icon: Icon(Icons.arrow_back),