-
Notifications
You must be signed in to change notification settings - Fork 67
setup #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
setup #27
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,26 @@ | ||||||||||||||||||||||||||||||||||||||||||||
| package com.example; | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| import javafx.fxml.FXML; | ||||||||||||||||||||||||||||||||||||||||||||
| import javafx.scene.control.ListView; | ||||||||||||||||||||||||||||||||||||||||||||
| import javafx.scene.control.TextField; | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| public class ChatController { | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| @FXML | ||||||||||||||||||||||||||||||||||||||||||||
| private ListView<String> messagesList; | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| @FXML | ||||||||||||||||||||||||||||||||||||||||||||
| private TextField inputField; | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| private final ChatModel model = new ChatModel(); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| @FXML | ||||||||||||||||||||||||||||||||||||||||||||
| private void onSend() { | ||||||||||||||||||||||||||||||||||||||||||||
| String message = inputField.getText().trim(); | ||||||||||||||||||||||||||||||||||||||||||||
| if (!message.isEmpty()) { | ||||||||||||||||||||||||||||||||||||||||||||
| messagesList.getItems().add("Me: " + message); | ||||||||||||||||||||||||||||||||||||||||||||
| model.sendMessage(message); | ||||||||||||||||||||||||||||||||||||||||||||
| inputField.clear(); | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+20
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add error handling for model.sendMessage(). The Apply this diff to add error handling: @FXML
private void onSend() {
String message = inputField.getText().trim();
if (!message.isEmpty()) {
- messagesList.getItems().add("Me: " + message);
- model.sendMessage(message);
- inputField.clear();
+ try {
+ messagesList.getItems().add("Me: " + message);
+ model.sendMessage(message);
+ inputField.clear();
+ } catch (Exception e) {
+ System.err.println("Failed to send message: " + e.getMessage());
+ // TODO: Show error dialog to user
+ }
}
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,9 @@ | ||||||||||||||||||||||||
| package com.example; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| public class ChatModel { | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| public void sendMessage(String message) { | ||||||||||||||||||||||||
| // TODO: send POST JSON to ntfy | ||||||||||||||||||||||||
| System.out.println("Sending message: " + message); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
Comment on lines
+34
to
+55
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major Add input validation to prevent null or empty messages. The method should validate the input parameter to avoid processing invalid messages. Apply this diff to add validation: public void sendMessage(String message) {
+ if (message == null || message.isBlank()) {
+ throw new IllegalArgumentException("Message cannot be null or empty");
+ }
// TODO: send POST JSON to ntfy
System.out.println("Sending message: " + message);
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
|
|
||
| <?import javafx.scene.layout.BorderPane?> | ||
| <?import javafx.scene.control.ListView?> | ||
| <?import javafx.scene.control.TextField?> | ||
| <?import javafx.scene.control.Button?> | ||
| <?import javafx.scene.layout.HBox?> | ||
|
|
||
| <BorderPane xmlns="http://javafx.com/javafx" | ||
| xmlns:fx="http://javafx.com/fxml" | ||
| fx:controller="com.example.ChatController"> | ||
|
|
||
| <center> | ||
| <ListView fx:id="messagesList"/> | ||
| </center> | ||
|
|
||
| <bottom> | ||
| <HBox spacing="8" style="-fx-padding: 10;"> | ||
| <TextField fx:id="inputField" HBox.hgrow="ALWAYS"/> | ||
| <Button text="Send" onAction="#onSend"/> | ||
| </HBox> | ||
| </bottom> | ||
|
|
||
| </BorderPane> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major
Prefer dependency injection over direct instantiation for better testability.
The direct instantiation of
ChatModelcreates tight coupling and makes the controller difficult to unit test.Consider using constructor injection:
This allows you to inject a mock
ChatModelduring testing.🤖 Prompt for AI Agents