diff --git a/src/App.jsx b/src/App.jsx
index f3ca9cc..80e70d0 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -4,12 +4,12 @@ import React, { useState } from "react";
import "./App.css";
import HomePage from "./components/HomePage/HomePage";
import RecommendationPage from "./components/Recommendation/RecommendationPage";
+import { IsHomeProvider } from "./contexts/IsHomeContext";
function App() {
- const [page, setPage] = useState("home");
const [recommendations, setRecommendations] = useState([]);
- const handleSend = (data) => {
+ const handleAPICall = (data) => {
// Simulez des données recommandées
const simulatedRecommendations = [
{ artistName: "Becky G", songName: "Arranca (feat. Omega)" },
@@ -23,25 +23,15 @@ function App() {
{ artistName: "Calvin Harris & Sam Smith", songName: "Desire" },
{ artistName: "Doja Cat", songName: "Paint The Town Red" },
];
-
setRecommendations(simulatedRecommendations);
- console.log('done')
- };
-
- const handleBack = () => {
- setPage("home");
};
return (
+
- {page === "home" && }
- {page === "recommendation" && (
-
- )}
+
+
);
}
diff --git a/src/components/ButtonSubmit/ButtonSubmit.jsx b/src/components/ButtonSubmit/ButtonSubmit.jsx
index b7819f4..50f1fdb 100644
--- a/src/components/ButtonSubmit/ButtonSubmit.jsx
+++ b/src/components/ButtonSubmit/ButtonSubmit.jsx
@@ -1,21 +1,22 @@
-import React, { useState } from 'react';
+import React, { useState, useContext } from 'react';
import './ButtonSubmit.css';
import BeatLoader from "react-spinners/BeatLoader";
+import { useIsHome, useIsHomeUpdate } from '../../contexts/IsHomeContext';
-function ButtonSubmit({ song, artist, onSubmit, placeholder}) {
-
+function ButtonSubmit({ parentOnClick, placeholder}) {
const [isDisabled, setIsDisabled] = useState(false);
-
- const handleSubmit = () => {
- setIsDisabled(() => true);
- onSubmit({ song, artist });
+ const isHome = useIsHome();
+
+ const handleMouseUp = () => {
+ parentOnClick();
+ setIsDisabled(true);
}
return (
diff --git a/src/components/HomePage/HomePage.jsx b/src/components/HomePage/HomePage.jsx
index 1078f0c..f39cdc0 100644
--- a/src/components/HomePage/HomePage.jsx
+++ b/src/components/HomePage/HomePage.jsx
@@ -4,16 +4,23 @@ import React, { useState } from 'react';
import './HomePage.css';
import TextInput from '../TextInput/TextInput';
import ButtonSubmit from '../ButtonSubmit/ButtonSubmit';
+import { useIsHome, useIsHomeUpdate } from '../../contexts/IsHomeContext';
-function HomePage({ onSend }) {
+function HomePage({ parentOnClick }) {
const [artist, setArtist] = useState('');
const [song, setSong] = useState('');
+ const toggleIsHome = useIsHomeUpdate();
+
+ // TODO: add a proper API call
const handleSubmit = () => {
- //wait 2s
setTimeout(() => {
- onSend({ artist, song });
+ parentOnClick(artist, song);
+ console.log('API responded')
+ toggleIsHome();
}, 2000);
+
+
};
return (
@@ -28,7 +35,7 @@ function HomePage({ onSend }) {
-
+
diff --git a/src/contexts/IsHomeContext.jsx b/src/contexts/IsHomeContext.jsx
new file mode 100644
index 0000000..929e554
--- /dev/null
+++ b/src/contexts/IsHomeContext.jsx
@@ -0,0 +1,28 @@
+import React, { useState, createContext, useContext} from "react";
+
+const IsHomeContext = createContext();
+const IsHomeUpdateContext = createContext();
+
+export const useIsHome = () => {
+ return useContext(IsHomeContext);
+}
+
+export const useIsHomeUpdate = () => {
+ return useContext(IsHomeUpdateContext);
+}
+
+export const IsHomeProvider = ({ children }) => {
+ const [isHome, setIsHome] = useState(true);
+
+ const toggleIsHome = () => {
+ setIsHome(isHome => !isHome);
+ }
+
+ return (
+
+
+ {children}
+
+
+ )
+}
\ No newline at end of file