From 712e9e6d3c7160e1c9d4e4cfdbf9a1fed024e0d0 Mon Sep 17 00:00:00 2001 From: Alasdair Smith Date: Tue, 3 May 2022 17:26:49 +0100 Subject: [PATCH 1/2] Extract useExercise --- client/src/App.js | 29 ++--------------------------- client/src/Exercises/useExercise.js | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 27 deletions(-) create mode 100644 client/src/Exercises/useExercise.js diff --git a/client/src/App.js b/client/src/App.js index ae8ace5..54c669f 100644 --- a/client/src/App.js +++ b/client/src/App.js @@ -7,44 +7,19 @@ import "./Blocks/dom"; import "./Blocks/cyf"; import useBlockly from "./Blockly/useBlockly"; -import * as Exercise1 from "./Exercises/01-stuff"; -import * as Exercise2 from "./Exercises/02-more-stuff"; - import Split from "react-split-grid"; import TextPanel from "./TextPanel/TextPanel"; import Output from "./Output/Output"; import Header from "./Layout/Header/Header"; import Menu from "./Layout/Menu/Menu"; import Footer from "./Layout/Footer/Footer"; -import Button from "./Button/Button"; -import "./App.scss"; +import { useExercise } from "./Exercises/useExercise"; +import "./App.scss"; import { ReactComponent as Background } from "../src/svgs/Humaaans-Phone.svg"; Blockly.setLocale(locale); -// just left all this and presumed you will pass whatever you decide to do into the text panel -const exercises = [Exercise1, Exercise2]; - -function useExercise() { - const [exerciseIndex, setExerciseIndex] = useState(0); - - function nextExercise() { - setExerciseIndex(exerciseIndex + 1); - } - function prevExercise() { - setExerciseIndex(exerciseIndex - 1); - } - - return { - exercise: exercises[exerciseIndex], - hasNextExercise: exerciseIndex + 1 < exercises.length, - nextExercise, - hasPrevExercise: exerciseIndex - 1 >= 0, - prevExercise, - }; -} - export default function App() { const { exercise, diff --git a/client/src/Exercises/useExercise.js b/client/src/Exercises/useExercise.js new file mode 100644 index 0000000..b202879 --- /dev/null +++ b/client/src/Exercises/useExercise.js @@ -0,0 +1,25 @@ +import { useState } from "react"; + +import * as Exercise1 from "./01-stuff"; +import * as Exercise2 from "./02-more-stuff"; + +const exercises = [Exercise1, Exercise2]; + +export function useExercise() { + const [exerciseIndex, setExerciseIndex] = useState(0); + + function nextExercise() { + setExerciseIndex(exerciseIndex + 1); + } + function prevExercise() { + setExerciseIndex(exerciseIndex - 1); + } + + return { + exercise: exercises[exerciseIndex], + hasNextExercise: exerciseIndex + 1 < exercises.length, + nextExercise, + hasPrevExercise: exerciseIndex - 1 >= 0, + prevExercise, + }; +} \ No newline at end of file From cc54bb12ed2f440b320727df82f13286ed7b4fd9 Mon Sep 17 00:00:00 2001 From: Alasdair Smith Date: Tue, 3 May 2022 17:27:24 +0100 Subject: [PATCH 2/2] Fix invalid className prop --- client/src/Layout/Footer/Footer.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/Layout/Footer/Footer.jsx b/client/src/Layout/Footer/Footer.jsx index d361142..8d8e4ee 100644 --- a/client/src/Layout/Footer/Footer.jsx +++ b/client/src/Layout/Footer/Footer.jsx @@ -5,7 +5,7 @@ const Footer = () => ( );