Skip to content

Commit 15ce786

Browse files
committed
update Context and remove warnings
1 parent 3884172 commit 15ce786

File tree

34 files changed

+332
-404
lines changed

34 files changed

+332
-404
lines changed

src/components/App.jsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ class App extends React.Component {
5252
<div id="page-wrap">
5353
<Menu isOpen={isMenuOpen} toggleMenu={this.toggleMenu}>
5454
<p className="text-center">
55-
<a target="_blank" href="https://reactgraphql.academy">
55+
<a
56+
target="_blank"
57+
rel="noopener noreferrer"
58+
href="https://reactgraphql.academy"
59+
>
5660
<RGALogo />
5761
</a>
5862
</p>

src/components/Root.jsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
import React from "react";
22
import { BrowserRouter as Router } from "react-router-dom";
3-
import { createStore } from "redux";
43
import Modal from "./patterns/Context/example/Modal";
5-
import { counter } from "./patterns/HigherOrderComponents/exercise_bonus/utils/redux-counter";
6-
import { Provider } from "./patterns/Context/xbonus/Provider";
4+
import { GraphQLProvider } from "./patterns/Context/exercise/GraphQLProvider";
5+
import { createClient } from "./patterns/Context/exercise/utils";
76

8-
// Don't do window.__store ever!! this is only to avoid using the Provider until the context exercise
9-
// where you'll implement the Provider
10-
window.__store = createStore(counter);
7+
const client = createClient({ url: "https://rickandmortyapi.com/graphql/" });
118

129
const Root = ({ children }) => (
13-
<Router>
14-
<Modal>{children}</Modal>
15-
</Router>
10+
<GraphQLProvider client={client}>
11+
<Router>
12+
<Modal>{children}</Modal>
13+
</Router>
14+
</GraphQLProvider>
1615
);
1716

1817
export default Root;

src/components/functional-programming/closure/exercise.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable no-unused-vars */
2+
13
// Open the console on your browser and type [closure exercise] in the console filter.
24
// You should see on the console the console.log() for this exercise.
35

src/components/functional-programming/composition/Page.jsx

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,18 @@ import React from "react";
33
import { transformText } from "./example";
44
import FormExercise from "./exercise";
55

6-
const exampleText = "1 2 3 ReactJS Academy is a m a z i n g";
6+
const exampleText = "1 2 3 React GraphQL Academy is a m a z i n g";
77

88
const Page = () => (
99
<React.Fragment>
1010
<h2>Function composition</h2>
1111
<h3>Example</h3>
12-
<p>
13-
<a
14-
target="_blank"
15-
rel="noopener noreferrer"
16-
href="https://github.com/reactjsacademy/advanced-react-patterns/blob/master/src/components/functional-programming/composition/example/index.js"
17-
>
18-
source code exercise branch &#187;
19-
</a>
20-
</p>
2112
Tranform the following text: "{exampleText}" so it becomes
2213
<strong> REACTJSACADEMYISAMAZING</strong>
2314
<p>
2415
Result: <strong>{transformText(exampleText)}</strong>
2516
</p>
2617
<h3>Exercise</h3>
27-
<p>
28-
<a
29-
target="_blank"
30-
rel="noopener noreferrer"
31-
href="https://github.com/reactjsacademy/advanced-react-patterns/tree/master/src/components/functional-programming/composition/exercise"
32-
>
33-
source code exercise branch &#187;
34-
</a>
35-
</p>
3618
<p>
3719
Validate the following form composing the validators defined in
3820
`src/components/functional-programming/composition/exercise/valiators`. To
@@ -48,13 +30,17 @@ const Page = () => (
4830
<a
4931
target="_blank"
5032
rel="noopener noreferrer"
51-
href="https://github.com/reactjsacademy/reactjsacademy/blob/master/src/components/payment/checkout/CheckoutForm.js#L230"
33+
href="https://github.com/reactgraphqlacademy/reactgraphql.academy/blob/master/www/src/components/payment/checkout/CheckoutForm.js#L383"
5234
>
5335
source code
5436
</a>{" "}
5537
of the checkout of the{" "}
56-
<a href="https://reactjs.academy/react-redux-graphql-bootcamp-lisbon/#pricing">
57-
ReactJS Academy website
38+
<a
39+
href="https://reactgraphql.academy/"
40+
target="_blank"
41+
rel="noopener noreferrer"
42+
>
43+
React GraphQL Academy website
5844
</a>
5945
</p>
6046
</React.Fragment>
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
export const compose = (...functions) => initialValue =>
1+
/* eslint-disable no-unused-vars */
2+
3+
export const compose = (...functions) => (initialValue) =>
24
functions.reduceRight(
35
(accumulatedValue, fn) => fn(accumulatedValue),
46
initialValue
57
);
68

7-
const toUpperCase = text => text.toUpperCase();
9+
const toUpperCase = (text) => text.toUpperCase();
810

9-
const removeSpaces = text => text.replace(/\s/g, "");
11+
const removeSpaces = (text) => text.replace(/\s/g, "");
1012

11-
const removeNumbers = text => text.replace(/[0-9]/g, "");
13+
const removeNumbers = (text) => text.replace(/[0-9]/g, "");
1214

1315
// export const transformText = compose(
1416
// toUpperCase,
1517
// removeNumbers,
1618
// removeSpaces
1719
// );
1820

19-
export const transformText = text => text;
21+
export const transformText = (text) => text;
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
export const required = value => (value ? undefined : "Required");
1+
export const required = (value) => (value ? undefined : "Required");
22

3-
export const mustBeEmail = value => {
4-
const reEmail = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
3+
export const mustBeEmail = (value) => {
4+
const reEmail = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; // eslint-disable-line
55
return reEmail.test(value) ? undefined : "Email format is not correct";
66
};
77

8-
export const atLeastFiveCharacters = value =>
8+
export const atLeastFiveCharacters = (value) =>
99
value && value.length >= 5
1010
? undefined
1111
: "You need to type at least 5 characters";

src/components/functional-programming/memoization/Page.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ const Page = () => (
2222
<p>
2323
1. Pair up and explain to each other how the memoize function works with
2424
the doEasyWork function.
25-
<ul>
26-
<li>Where is the closure? Between line X and Y</li>
27-
<li>What variable/s are captured in the closure?</li>
28-
</ul>
2925
</p>
26+
<ul>
27+
<li>Where is the closure? Between line X and Y</li>
28+
<li>What variable/s are captured in the closure?</li>
29+
</ul>
3030

3131
<p>
3232
2. Explain to each other how the memoize function works with doHardWork.

src/components/functional-programming/memoization/exercise.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,25 @@ You should see on the console the console.log() for this exercise.
1515
You can use the function doAnyWork to test your refactored memoize function
1616
*/
1717

18-
async function doEasyWork(amount) {
18+
export async function doEasyWork(amount) {
1919
console.log(`[memoization exercise] ${amount} easy units produced`);
2020
}
2121

22-
async function doHardWork(amount) {
22+
export async function doHardWork(amount) {
2323
console.log("[memoization exercise] doing work");
24-
await new Promise(resolve => setTimeout(resolve, amount));
24+
await new Promise((resolve) => setTimeout(resolve, amount));
2525
console.log(`[memoization exercise] ${amount} units of hard work produced!`);
2626

2727
return amount;
2828
}
2929

30-
function doAnyWork(amount = 1, amount2 = 1, amount3 = 1) {
30+
export function doAnyWork(amount = 1, amount2 = 1, amount3 = 1) {
3131
return amount + amount2 + amount3;
3232
}
3333

3434
function memoize(fn) {
3535
let cache = {};
36-
return amount => {
36+
return (amount) => {
3737
if (amount in cache) {
3838
console.log("[memoization exercise] output from cache");
3939
return cache[amount];

src/components/patterns/Context/Page.jsx

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Example from "./example";
33
import Exercise from "./exercise";
44

55
const Page = () => (
6-
<div>
6+
<React.Fragment>
77
<h2>Context</h2>
88
<blockquote>
99
Accepts a context object (the value returned from React.createContext) and
@@ -12,54 +12,17 @@ const Page = () => (
1212
&lt;MyContext.Provider&gt; above the calling component in the tree.{" "}
1313
<a
1414
target="_blank"
15+
rel="noopener noreferrer"
1516
href="https://reactjs.org/docs/hooks-reference.html#usecontext"
1617
>
1718
React docs
1819
</a>
1920
</blockquote>
2021
<h3>Example</h3>
2122
<Example />
22-
<p>
23-
File: <code>src/components/patterns/Context/example/Modal.jsx</code>
24-
</p>
25-
<h3>Exercise</h3>
26-
<p>
27-
We are going to create a <strong>Theme Switcher</strong> component using
28-
Context. If you see{" "}
29-
<code>src/components/patterns/Context/exercise/theme.js</code>, there are{" "}
30-
<strong>2 themes defined</strong>. You should be able to toggle between
31-
these 2 themes.
32-
</p>
33-
<p>This component should:</p>
34-
<ul>
35-
<li>
36-
Track the current <code>theme</code> in the state
37-
</li>
38-
<li>Implement a fucntion to toggle the theme</li>
39-
<li>
40-
pass the current theme to the <code>ThemeProvider</code> from{" "}
41-
<code>styled-components</code>
42-
</li>
43-
</ul>
44-
<p>
45-
In order to check if the theme is actually changing, you can refactor the{" "}
46-
<code>Hero</code> component (
47-
<code>src/components/patterns/Context/exercise/components/Hero.jsx</code>)
48-
</p>
49-
<p>
50-
Also, in order to toggle the theme, you need to use the{" "}
51-
<code>ThemeContext.Consumer</code> in order to get access to the function
52-
that toggles the state in your ThemeProvider.
53-
</p>
54-
<Exercise />
5523
<hr />
56-
<h3>Bonus Exercise</h3>
57-
<p>
58-
Implement the Redux Provider in
59-
<code>src/components/patterns/Context/xbonus/Provider.js</code>. Once
60-
implemented, use it in Root.js
61-
</p>
62-
</div>
24+
<Exercise />
25+
</React.Fragment>
6326
);
6427

6528
export default Page;

src/components/patterns/Context/example/Modal.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import { Modal as BootstrapModal } from "react-bootstrap";
44
const ModalContext = React.createContext();
55

66
const Modal = ({ children }) => {
7-
const [modalChildren, displayModal] = React.useState(null);
8-
const hideModal = () => displayModal(null);
7+
const [modalChildren, showModal] = React.useState(null);
8+
const hideModal = () => showModal(null);
99
const isOpen = !!modalChildren;
1010

1111
return (
12-
<ModalContext.Provider value={{ isOpen, displayModal, hideModal }}>
12+
<ModalContext.Provider value={{ isOpen, showModal, hideModal }}>
1313
<BootstrapModal backdrop={true} show={isOpen} onHide={hideModal}>
1414
{modalChildren}
1515
</BootstrapModal>

0 commit comments

Comments
 (0)