From aaa3f0253a1372f861b3d842287c6fb6ce6d9a65 Mon Sep 17 00:00:00 2001
From: HSoreide <sofie.scisly@gmail.com>
Date: Wed, 19 Apr 2023 12:59:59 +0200
Subject: [PATCH] Make searchbar active and searchbutton defaut when opening
 the view to add ingredients to fridge

---
 .../controller/AddIngredientController.java   | 21 ++++++++++++-------
 src/main/resources/recipes/Fridge.register    |  1 +
 src/main/resources/view/AddIngredient.fxml    |  2 +-
 3 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/src/main/java/no/ntnu/idatt1002/demo/controller/AddIngredientController.java b/src/main/java/no/ntnu/idatt1002/demo/controller/AddIngredientController.java
index 585ddf65..28e95e9f 100644
--- a/src/main/java/no/ntnu/idatt1002/demo/controller/AddIngredientController.java
+++ b/src/main/java/no/ntnu/idatt1002/demo/controller/AddIngredientController.java
@@ -1,5 +1,6 @@
 package no.ntnu.idatt1002.demo.controller;
 
+import javafx.application.Platform;
 import javafx.collections.FXCollections;
 import javafx.collections.ObservableList;
 import javafx.fxml.FXML;
@@ -54,6 +55,14 @@ public class AddIngredientController implements Initializable {
 
     }
 
+
+    private List<String> searchList(String searchWords, String[] listOfStrings) {
+        String[] searchWordsArray = searchWords.trim().split(" ");
+        return Arrays.stream(listOfStrings).filter((in) -> {
+            return Arrays.stream(searchWordsArray).allMatch((word) ->
+                    in.toLowerCase().contains(word.toLowerCase()));
+        }).collect(Collectors.toList());
+    }
     @Override
     public void initialize(URL url, ResourceBundle resourceBundle) {
 
@@ -65,16 +74,12 @@ public class AddIngredientController implements Initializable {
         ingredientsList = stringIngredients.stream().toArray(String[] ::new);
         ingredients = FXCollections.observableArrayList(stringIngredients);
         // Fill list with ingredients
-        listView.setItems(ingredients.sorted());
+        listView.setItems(ingredients);
 
-    }
+        Platform.runLater(() -> searchBar.requestFocus());
 
-    private List<String> searchList(String searchWords, String[] listOfStrings) {
-        String[] searchWordsArray = searchWords.trim().split(" ");
-        return Arrays.stream(listOfStrings).filter((in) -> {
-            return Arrays.stream(searchWordsArray).allMatch((word) ->
-                in.toLowerCase().contains(word.toLowerCase()));
-        }).collect(Collectors.toList());
     }
 
+
+
 }
diff --git a/src/main/resources/recipes/Fridge.register b/src/main/resources/recipes/Fridge.register
index 73f83537..fb896692 100644
--- a/src/main/resources/recipes/Fridge.register
+++ b/src/main/resources/recipes/Fridge.register
@@ -18,3 +18,4 @@ BUTTER
 GARLIC_CLOVE
 HAM
 BROCCOLI
+OIL
diff --git a/src/main/resources/view/AddIngredient.fxml b/src/main/resources/view/AddIngredient.fxml
index f0b53fc5..a000e3bf 100644
--- a/src/main/resources/view/AddIngredient.fxml
+++ b/src/main/resources/view/AddIngredient.fxml
@@ -47,7 +47,7 @@
                   </ListView>
                   <Pane prefHeight="81.0" prefWidth="600.0">
                      <children>
-                        <Button id="button-style" fx:id="addBtn" defaultButton="true" layoutX="275.0" layoutY="7.0" mnemonicParsing="false" onAction="#addToFridge" styleClass="button-style" stylesheets="@../style.css" text="ADD">
+                        <Button id="button-style" fx:id="addBtn" layoutX="275.0" layoutY="7.0" mnemonicParsing="false" onAction="#addToFridge" styleClass="button-style" stylesheets="@../style.css" text="ADD">
                            <font>
                               <Font size="14.0" />
                            </font>
-- 
GitLab