Skip to content

Commit 716d8d4

Browse files
authored
Merge pull request #1 from boostup/new-version
some styling and some nesting for demo purposes
2 parents 72c6bbd + 0a15c08 commit 716d8d4

File tree

8 files changed

+166
-30
lines changed

8 files changed

+166
-30
lines changed

src/App.js

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
1-
/**
2-
*
3-
* Original: https://codesandbox.io/s/usereactsaga-usereducer-exercise-stuctured-into-files-context-api-pnsdk?file=/src/App.js
4-
*/
5-
61
import React from "react";
72

83
import ButtonComponent from "./components/ButtonComponent";
9-
10-
import DisplayStateComponent from "./components/DisplayStateComponent";
11-
12-
import PrettyPrint from "./components/PrettyPrint";
4+
import FooterComponent from "./components/FooterComponent";
5+
import HeaderComponent from "./components/HeaderComponent";
136

147
import { useDataLayerValue } from "./context/DataLayer";
158

169
import "./styles.css";
1710

1811
export default function App() {
19-
const { state, put } = useDataLayerValue();
12+
const {
13+
// state,//so es-lint does not brag!
14+
put,
15+
} = useDataLayerValue();
2016

2117
function handleClick1() {
2218
put({ type: "INCREMENT_COUNTER_1_START" });
@@ -28,23 +24,31 @@ export default function App() {
2824

2925
return (
3026
<div className="App">
31-
{/* Imagine this is in the header of your website */}
32-
Header <DisplayStateComponent />
33-
<hr />
34-
<ButtonComponent
35-
instructions="Increment counter 1"
36-
onClick={handleClick1}
37-
/>
38-
<hr />
39-
<ButtonComponent
40-
instructions="Increment counter 2"
41-
onClick={handleClick2}
42-
/>
43-
<hr />
44-
State: <PrettyPrint toPrint={state} />
45-
<hr />
46-
{/* and this the footer */}
47-
Footer <DisplayStateComponent />
27+
<p>
28+
Imagine this is an actual website, where components need to display some
29+
state, or let's be crazy: even set some state !
30+
</p>
31+
32+
<HeaderComponent />
33+
34+
<p>
35+
We, buttons below, live on the ground floor, level 0, in the App.js file
36+
directly but, we're cool!
37+
</p>
38+
39+
<p className="App__groundFloor">
40+
<ButtonComponent
41+
instructions="Press me to increment counter 1"
42+
onClick={handleClick1}
43+
/>
44+
<hr />
45+
<ButtonComponent
46+
instructions="No no, press me to increment counter 2, he's much better ;)"
47+
onClick={handleClick2}
48+
/>
49+
</p>
50+
51+
<FooterComponent />
4852
</div>
4953
);
5054
}

src/components/DisplayStateComponent.jsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
import React from "react";
22
import { useDataLayerValue } from "../context/DataLayer";
33
import PrettyPrint from "./PrettyPrint";
4+
import SomeNestedComponent from "./SomeNestedComponent";
45

56
const DisplayStateComponent = () => {
67
const { state } = useDataLayerValue();
78
return (
89
<div>
10+
<p>
11+
I have access to everything: I'm the king of the world! Look at all that
12+
state :
13+
</p>
914
<PrettyPrint toPrint={state} />
15+
<SomeNestedComponent />
1016
</div>
1117
);
1218
};

src/components/FooterComponent.jsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import React from "react";
2+
import { useDataLayerValue } from "../context/DataLayer";
3+
import ButtonComponent from "./ButtonComponent";
4+
import DisplayStateComponent from "./DisplayStateComponent";
5+
6+
function FooterComponent() {
7+
const { put } = useDataLayerValue();
8+
9+
function handleClick2() {
10+
put({ type: "INCREMENT_COUNTER_2_START" });
11+
}
12+
13+
return (
14+
<div>
15+
<p>
16+
Hey, dude, Footer here. Don't mean to brag, but my children too have
17+
access to the state, and I'm not even passing any props to them!{" "}
18+
</p>
19+
20+
<DisplayStateComponent />
21+
22+
<p>
23+
<ButtonComponent
24+
instructions="Increment counter 2"
25+
onClick={handleClick2}
26+
/>
27+
</p>
28+
</div>
29+
);
30+
}
31+
32+
export default FooterComponent;

src/components/HeaderComponent.jsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from "react";
2+
import { useDataLayerValue } from "../context/DataLayer";
3+
import PrettyPrint from "./PrettyPrint";
4+
5+
function HeaderComponent() {
6+
const { state } = useDataLayerValue();
7+
8+
return (
9+
<div>
10+
<p>
11+
Hey! what's up!? I'm the Header of this website. Look at my pretty
12+
state:
13+
</p>
14+
15+
<PrettyPrint toPrint={state} />
16+
</div>
17+
);
18+
}
19+
20+
export default HeaderComponent;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import React from "react";
2+
import ButtonComponent from "./ButtonComponent";
3+
4+
import { useDataLayerValue } from "../context/DataLayer";
5+
6+
function SomeNestedComponent() {
7+
const { put } = useDataLayerValue();
8+
9+
function handleClick() {
10+
put({ type: "INCREMENT_COUNTER_1_START" });
11+
}
12+
13+
return (
14+
<div>
15+
<p>
16+
Some Nested Component - but no Prop drilling is allowed here
17+
<span role="img" aria-label="pulling my tongue">
18+
👅
19+
</span>
20+
</p>
21+
<ButtonComponent
22+
instructions="Press me also to increment counter 1"
23+
onClick={handleClick}
24+
/>
25+
</div>
26+
);
27+
}
28+
29+
export default SomeNestedComponent;

src/sagas/counter1/counter1.sagas.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function* incrementAsync() {
77
"I AM STARTING TO INCREMENT FROM",
88
previousState.counter1
99
);
10-
yield delay(2000);
10+
yield delay(1000);
1111
yield put({ type: "INCREMENT_COUNTER_1" });
1212
const state = yield select();
1313
yield call(console.log, "I AM FINISHED INCREMENTING TO", state.counter1);

src/sagas/counter2/counter2.sagas.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function* incrementAsync() {
77
"I AM STARTING TO INCREMENT FROM",
88
previousState.counter2
99
);
10-
yield delay(2000);
10+
yield delay(1000);
1111
yield put({ type: "INCREMENT_COUNTER_2" });
1212
const state = yield select();
1313
yield call(console.log, "I AM FINISHED INCREMENTING TO", state.counter2);

src/styles.css

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,49 @@
1-
.App {
1+
* {
2+
box-sizing: border-box;
3+
}
4+
5+
button {
6+
padding: 1rem;
7+
}
8+
9+
.App,
10+
.App > div,
11+
App > div > div {
12+
position: relative;
213
font-family: sans-serif;
314
text-align: center;
15+
display: flex;
16+
flex-direction: column;
17+
justify-content: center;
18+
align-items: center;
19+
}
20+
21+
.App > div,
22+
.App > div > div {
23+
position: relative;
24+
border: 5px solid hotpink;
25+
width: 95vw;
26+
padding: 1rem;
27+
}
28+
29+
.App > div > div {
30+
width: 80%;
31+
border: 5px solid teal;
32+
}
33+
34+
.App > div::before,
35+
.App > div > div::before {
36+
content: "Depth: Level 1";
37+
position: absolute;
38+
top: 0;
39+
left: 0;
40+
padding: 1rem;
41+
border: 5px dotted rebeccapurple;
42+
}
43+
44+
.App > div > div::before {
45+
content: "Depth: Level 2";
46+
}
47+
48+
.App__groundFloor {
449
}

0 commit comments

Comments
 (0)