Skip to content

Commit

Permalink
Fix for InAnYan#118
Browse files Browse the repository at this point in the history
  • Loading branch information
InAnYan committed Aug 7, 2024
1 parent 8b7fff1 commit a38c439
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</ScrollPane>
</children>
</StackPane>
<HBox alignment="CENTER" spacing="10.0">
<HBox fx:id="promptHBox" alignment="CENTER" spacing="10.0">
<children>
<ExpandingTextArea fx:id="userPromptTextArea" HBox.hgrow="ALWAYS" />
<Button fx:id="submitButton" mnemonicParsing="false" onAction="#onSendMessage" text="%Submit" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import javafx.scene.control.ScrollPane;
import javafx.scene.input.KeyCode;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
Expand Down Expand Up @@ -39,6 +40,7 @@ public class AiChatComponent extends VBox {

@FXML private ScrollPane scrollPane;
@FXML private VBox chatVBox;
@FXML private HBox promptHBox;
@FXML private ExpandingTextArea userPromptTextArea;
@FXML private Button submitButton;
@FXML private StackPane stackPane;
Expand Down Expand Up @@ -114,6 +116,8 @@ private void onSendMessage() {
} else {
addError(e.getMessage());
}

switchToErrorState(userPrompt);
});

task.titleProperty().set(Localization.lang("Waiting for AI reply for %0...", citationKey));
Expand All @@ -122,6 +126,41 @@ private void onSendMessage() {
}
}

private void switchToErrorState(String userMessage) {
promptHBox.getChildren().clear();

Button retryButton = new Button(Localization.lang("Retry"));

retryButton.setOnAction(event -> {
userPromptTextArea.setText(userMessage);

chatVBox.getChildren().removeLast();
chatVBox.getChildren().removeLast();

switchToNormalState();

onSendMessage();
});

Button cancelButton = new Button(Localization.lang("Cancel"));

cancelButton.setOnAction(event -> {
chatVBox.getChildren().removeLast();
chatVBox.getChildren().removeLast();

switchToNormalState();
});

promptHBox.getChildren().add(retryButton);
promptHBox.getChildren().add(cancelButton);
}

private void switchToNormalState() {
promptHBox.getChildren().clear();
promptHBox.getChildren().add(userPromptTextArea);
promptHBox.getChildren().add(submitButton);
}

private void setLoading(boolean loading) {
userPromptTextArea.setDisable(loading);
submitButton.setDisable(loading);
Expand Down

0 comments on commit a38c439

Please sign in to comment.