UI fixes for new groups, form validation for discussion topic

pull/1428/head
ggurdin 1 year ago
parent 689252c17f
commit 3a6d6de7c5
No known key found for this signature in database
GPG Key ID: A01CB41737CBB478

@ -4359,5 +4359,6 @@
"enterPrompt": "Please enter a system prompt", "enterPrompt": "Please enter a system prompt",
"selectBotLanguage": "Select bot language", "selectBotLanguage": "Select bot language",
"chooseVoice": "Choose a voice", "chooseVoice": "Choose a voice",
"enterLanguageLevel": "Please enter a language level" "enterLanguageLevel": "Please enter a language level",
"enterDiscussionTopic": "Please enter a discussion topic"
} }

@ -106,6 +106,20 @@ class NewGroupController extends State<NewGroup> {
// #Pangea // #Pangea
// validate init bot options // validate init bot options
if (addConversationBotKey.currentState?.formKey.currentState != null) {
final isValid = addConversationBotKey
.currentState!.formKey.currentState!
.validate();
if (isValid == false) {
setState(() {
error = L10n.of(context)!
.conversationBotCustomZone_customSystemPromptEmptyError;
loading = false;
});
return;
}
}
addConversationBotKey.currentState?.updateAllBotOptions();
final addBot = addConversationBotKey.currentState?.addBot ?? false; final addBot = addConversationBotKey.currentState?.addBot ?? false;
if (addBot) { if (addBot) {
final botOptions = addConversationBotKey.currentState!.botOptions; final botOptions = addConversationBotKey.currentState!.botOptions;

@ -29,6 +29,9 @@ class ConversationBotModeDynamicZone extends StatelessWidget {
.conversationBotDiscussionZone_discussionTopicPlaceholder, .conversationBotDiscussionZone_discussionTopicPlaceholder,
), ),
controller: discussionTopicController, controller: discussionTopicController,
validator: (value) => value == null || value.isEmpty
? L10n.of(context)!.enterDiscussionTopic
: null,
), ),
const SizedBox(height: 12), const SizedBox(height: 12),
TextFormField( TextFormField(

@ -99,6 +99,12 @@ class ConversationBotSettingsState extends State<ConversationBotSettings> {
); );
} }
void updateAllBotOptions() {
botOptions.discussionTopic = discussionTopicController.text;
botOptions.discussionKeywords = discussionKeywordsController.text;
botOptions.customSystemPrompt = customSystemPromptController.text;
}
Future<void> showBotOptionsDialog() async { Future<void> showBotOptionsDialog() async {
if (isCreating) return; if (isCreating) return;
final bool? confirm = await showDialog<bool>( final bool? confirm = await showDialog<bool>(
@ -135,10 +141,7 @@ class ConversationBotSettingsState extends State<ConversationBotSettings> {
); );
if (confirm == true) { if (confirm == true) {
botOptions.discussionTopic = discussionTopicController.text; updateAllBotOptions();
botOptions.discussionKeywords = discussionKeywordsController.text;
botOptions.customSystemPrompt = customSystemPromptController.text;
updateBotOption(() => botOptions = botOptions); updateBotOption(() => botOptions = botOptions);
final bool isBotRoomMember = await widget.room?.botIsInRoom ?? false; final bool isBotRoomMember = await widget.room?.botIsInRoom ?? false;
@ -241,12 +244,34 @@ class ConversationBotSettingsState extends State<ConversationBotSettings> {
onTap: showBotOptionsDialog, onTap: showBotOptionsDialog,
), ),
if (isCreating && addBot) if (isCreating && addBot)
ConversationBotSettingsForm( Padding(
botOptions: botOptions, padding: const EdgeInsets.all(16),
formKey: formKey, child: Column(
discussionKeywordsController: discussionKeywordsController, children: [
discussionTopicController: discussionTopicController, Align(
customSystemPromptController: customSystemPromptController, alignment: Alignment.centerLeft,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 12),
child: Text(
L10n.of(context)!.botConfig,
style: Theme.of(context).textTheme.titleLarge,
),
),
),
Form(
key: formKey,
child: ConversationBotSettingsForm(
botOptions: botOptions,
formKey: formKey,
discussionKeywordsController:
discussionKeywordsController,
discussionTopicController: discussionTopicController,
customSystemPromptController:
customSystemPromptController,
),
),
],
),
), ),
], ],
), ),

@ -95,7 +95,7 @@ class ConversationBotSettingsFormState
validator: (value) => validator: (value) =>
value == null ? L10n.of(context)!.enterLanguageLevel : null, value == null ? L10n.of(context)!.enterLanguageLevel : null,
), ),
const SizedBox(height: 20), const SizedBox(height: 12),
Align( Align(
alignment: Alignment.centerLeft, alignment: Alignment.centerLeft,
child: Padding( child: Padding(
@ -106,7 +106,6 @@ class ConversationBotSettingsFormState
), ),
), ),
), ),
const SizedBox(height: 12),
ConversationBotModeSelect( ConversationBotModeSelect(
initialMode: botOptions.mode, initialMode: botOptions.mode,
onChanged: (String? mode) => { onChanged: (String? mode) => {

Loading…
Cancel
Save