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; 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 { Future<void> startPersonalWishlist(String message) async {
await _authenticationService.initialize(); await _authenticationService.initialize();

View File

@ -72,11 +72,13 @@ class ChatScreenState extends State<ChatScreen> {
bool isSendButtonEnabled = false; bool isSendButtonEnabled = false;
bool showButtonsContainer = true; bool showButtonsContainer = true;
final ScrollController _scrollController = ScrollController(); final ScrollController _scrollController = ScrollController();
late Widget appBarTitle;
String wishlistId = ''; String wishlistId = '';
void initState() { void initState() {
super.initState(); super.initState();
appBarTitle = Text('New Chat');
_searchService.sseStream.listen((event) { _searchService.sseStream.listen((event) {
_handleSSEMessage(Message(text: '${event.data}')); _handleSSEMessage(Message(text: '${event.data}'));
}); });
@ -100,6 +102,15 @@ class ChatScreenState extends State<ChatScreen> {
_scrollToBottom(); _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 { Future<void> _startPersonalWishlist(String message) async {
setState(() { setState(() {
@ -108,6 +119,7 @@ class ChatScreenState extends State<ChatScreen> {
}); });
await _searchService.initializeAuthenticationService(); await _searchService.initializeAuthenticationService();
await _searchService.startPersonalWishlist(message); await _searchService.startPersonalWishlist(message);
updateChatTitle(_searchService.wishlistId.toString());
_scrollToBottom(); _scrollToBottom();
} }
@ -172,7 +184,7 @@ class ChatScreenState extends State<ChatScreen> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text('New Chat'), title: appBarTitle,
centerTitle: true, centerTitle: true,
leading: IconButton( leading: IconButton(
icon: Icon(Icons.arrow_back), icon: Icon(Icons.arrow_back),