From 5cb47da5127a39848b4fd9caea894ec461b58cb2 Mon Sep 17 00:00:00 2001
From: HSoreide <sofie.scisly@gmail.com>
Date: Wed, 19 Apr 2023 12:36:41 +0200
Subject: [PATCH] Refactor Scene Switch for SuggestRecipes view

---
 .../controller/SuggestRecipesController.java  | 24 ++++++-------------
 src/main/resources/view/SuggestRecipes.fxml   |  4 ++--
 2 files changed, 9 insertions(+), 19 deletions(-)

diff --git a/src/main/java/no/ntnu/idatt1002/demo/controller/SuggestRecipesController.java b/src/main/java/no/ntnu/idatt1002/demo/controller/SuggestRecipesController.java
index b75c3666..3cee1a09 100644
--- a/src/main/java/no/ntnu/idatt1002/demo/controller/SuggestRecipesController.java
+++ b/src/main/java/no/ntnu/idatt1002/demo/controller/SuggestRecipesController.java
@@ -81,9 +81,6 @@ public class SuggestRecipesController implements Initializable {
             fridge = FXCollections.observableArrayList(ingredientsAtHand.getIngredientsAtHand().stream().map(foodItem -> foodItem.label).toList());
             fridgeList.setItems(fridge.sorted());
             setRecipeTiles();
-
-        }else if(clickedButton.get() == ButtonType.CANCEL) {
-
         }
     }
 
@@ -157,28 +154,21 @@ public class SuggestRecipesController implements Initializable {
 
 
     @FXML
-    private void goBack(ActionEvent event) throws IOException {
+    private void switchScene(ActionEvent event) throws IOException {
         FXMLLoader loader = new FXMLLoader();
-        loader.setLocation(getClass().getResource("/view/MainMenuNew.fxml"));
-
+        if (event.getSource() == showAllBtn) {
+            loader.setLocation(getClass().getResource("/view/AllRecipes.fxml"));
+        } else if (event.getSource() == goBackBtn) {
+            loader.setLocation(getClass().getResource("/view/MainMenuNew.fxml"));
+        }
         Parent root = loader.load();
         Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
         Scene scene = new Scene(root);
         stage.setScene(scene);
+        stage.setResizable(false);
         stage.show();
     }
 
-    @FXML
-    private void showAllRecipes(ActionEvent event) throws IOException {
-        FXMLLoader loader = new FXMLLoader();
-        loader.setLocation(getClass().getResource("/view/AllRecipes.fxml"));
-
-        Parent root = loader.load();
-        Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
-        Scene scene = new Scene(root);
-        stage.setScene(scene);
-        stage.show();
-    }
 
     @Override
     public void initialize(URL url, ResourceBundle resourceBundle) {
diff --git a/src/main/resources/view/SuggestRecipes.fxml b/src/main/resources/view/SuggestRecipes.fxml
index dde2ead5..da437245 100644
--- a/src/main/resources/view/SuggestRecipes.fxml
+++ b/src/main/resources/view/SuggestRecipes.fxml
@@ -70,7 +70,7 @@
                <left>
                   <Pane prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER">
                      <children>
-                        <Button id="button-style" fx:id="goBackBtn" alignment="CENTER" contentDisplay="CENTER" layoutX="62.0" layoutY="24.0" mnemonicParsing="false" onAction="#goBack" styleClass="button-style" stylesheets="@../style.css" text="Go Back" textAlignment="CENTER">
+                        <Button id="button-style" fx:id="goBackBtn" alignment="CENTER" contentDisplay="CENTER" layoutX="62.0" layoutY="24.0" mnemonicParsing="false" onAction="#switchScene" styleClass="button-style" stylesheets="@../style.css" text="Go Back" textAlignment="CENTER">
                            <font>
                               <Font size="14.0" />
                            </font>
@@ -88,7 +88,7 @@
                <right>
                   <VBox alignment="CENTER_LEFT" prefHeight="400.0" prefWidth="405.0" BorderPane.alignment="CENTER">
                      <children>
-                        <Button fx:id="showAllBtn" mnemonicParsing="false" onAction="#showAllRecipes" styleClass="button-style" stylesheets="@../style.css" text="Or show all recipes" textAlignment="CENTER">
+                        <Button fx:id="showAllBtn" mnemonicParsing="false" onAction="#switchScene" styleClass="button-style" stylesheets="@../style.css" text="Or show all recipes" textAlignment="CENTER">
                            <VBox.margin>
                               <Insets left="80.0" />
                            </VBox.margin>
-- 
GitLab