Skip to content

A couple of minor React tweaks #79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: react
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 2 additions & 27 deletions client/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
25 changes: 25 additions & 0 deletions client/src/Exercises/useExercise.js
Original file line number Diff line number Diff line change
@@ -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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need to use an update callback here?

}
function prevExercise() {
setExerciseIndex(exerciseIndex - 1);
}

return {
exercise: exercises[exerciseIndex],
hasNextExercise: exerciseIndex + 1 < exercises.length,
nextExercise,
hasPrevExercise: exerciseIndex - 1 >= 0,
prevExercise,
};
}
2 changes: 1 addition & 1 deletion client/src/Layout/Footer/Footer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const Footer = () => (
<footer className="c-layout__footer c-footer">
<h3 className="c-footer__title">
<Logo width="180px" />
<span class="invisible">Code Your Future</span>
<span className="invisible">Code Your Future</span>
</h3>
</footer>
);
Expand Down