diff --git a/frontend/public/images/bg2.jpg b/frontend/public/images/bg2.jpg new file mode 100644 index 0000000..55f8f15 Binary files /dev/null and b/frontend/public/images/bg2.jpg differ diff --git a/frontend/src/App.js b/frontend/src/App.js index 31682c0..4ef5f68 100644 --- a/frontend/src/App.js +++ b/frontend/src/App.js @@ -1,4 +1,4 @@ -import React, { useState } from "react"; +import React, { useState, useEffect } from "react"; import Header from "./components/Header"; import Footer from "./components/Footer"; import Tentang from "./components/Tentang"; @@ -32,6 +32,7 @@ const ratingDescriptions = { const App = () => { const [gameName, setGameName] = useState(""); + const [suggestions, setSuggestions] = useState([]); const [step, setStep] = useState(0); const [answers, setAnswers] = useState([]); const [rating, setRating] = useState(null); @@ -39,6 +40,22 @@ const App = () => { const [isConfirmPopupOpen, setIsConfirmPopupOpen] = useState(false); const [selectedOption, setSelectedOption] = useState(""); + useEffect(() => { + if (gameName.length > 1) { + fetch(`http://127.0.0.1:5000/autocomplete?query=${gameName}`) + .then(res => res.json()) + .then(data => setSuggestions(data.slice(0, 4))) + .catch(err => console.error("Error fetching autocomplete:", err)); + } else { + setSuggestions([]); + } + }, [gameName]); + + const handleSelectGame = (selectedGame) => { + setGameName(selectedGame); + setSuggestions([]); + }; + const checkGame = async () => { const response = await fetch("http://127.0.0.1:5000/check_game", { method: "POST", @@ -122,6 +139,19 @@ const App = () => { onChange={(e) => setGameName(e.target.value)} className="border border-gray-600 bg-gray-100 p-2 w-full mt-2 focus:bg-gray-200 focus:border-black rounded mt-1" /> + {suggestions.length > 0 && ( +