Skip to content

Commit dd59911

Browse files
committed
merge resolved
2 parents 6e7ba94 + 1e2ac25 commit dd59911

File tree

5 files changed

+164
-24
lines changed

5 files changed

+164
-24
lines changed

P05-Adding-React-Router/content.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ To work with React Router it helps to understand some terminology.
2020
- **Router** - A parent component that manages Routes
2121
- **Route** - A component that displays another component
2222

23-
Think of the Router as the manager, you only need one of these. The Router checks the URL in the address bar and passes this information to its descendant Routes.
23+
Think of the Router as the manager, you only need one of these. The Router checks the URL in the address bar and passes this information to its descendant Routes.
2424

25-
Imagine a website with three pages built with React using React Router. The Router and Route components might be arranged like this:
25+
Imagine a website with three pages built with React using React Router. The Router and Route components might be arranged like this:
2626

2727
- Router
2828
- Route - Home Page
@@ -31,7 +31,7 @@ Imagine a website with three pages built with React using React Router. The Rout
3131

3232
A Route is responsible for displaying components. Routes have a path property: when the path matches the URL in the address, the Route displays the appropriate component, otherwise not.
3333

34-
In code this might look like:
34+
In code this might look like:
3535

3636
```js
3737
<Router>
@@ -85,7 +85,7 @@ Router manages routes. It should be a top level component. For this reason you'l
8585
import { HashRouter as Router, Route } from 'react-router-dom'
8686
```
8787

88-
Why `HashRouter as Router`? This is an alias. You're importing HashRouter but using it under the name `Router` instead. This will make it easier to make changes in the future if needed.
88+
Why `HashRouter as Router`? This is an alias. You're importing HashRouter but using it under the name `Router` instead. This will make it easier to make changes in the future if needed.
8989

9090
> [action]
9191
>
@@ -460,9 +460,9 @@ const spaces = data.map(({ title, address, images, hours }, i) => {
460460
})
461461
```
462462

463-
On the first line there is a second parameter to:
463+
On the first line there is a second parameter to:
464464

465-
`map(obj, i)`, or
465+
`map(obj, i)`, or
466466

467467
`map({ ... }, i)`. here is the whole line as it is shown above:
468468

P06-Organizing-Files/content.md

+20-17
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,26 @@ Organizing components and their dependencies in folders is one way to keep compo
2323
>
2424
> Move all of your components into this folder. It should include all of the following files:
2525
>
26-
> - src
27-
> - components
28-
> - About.js
29-
> - App.css
30-
> - App.js
31-
> - App.test.js
32-
> - index.css
33-
> - index.js
34-
> - POPOSDetails.js
35-
> - POPOSList.css
36-
> - POPOSList.js
37-
> - POPOSSpace.css
38-
> - POPOSSpace.js
39-
> - serviceWorker.js
40-
> - setupTests.js
41-
> - Title.css
42-
> - Title.js
26+
```
27+
- src
28+
- App.css
29+
- App.js
30+
- App.test.js
31+
- components
32+
- About.js
33+
- POPOSDetails.js
34+
- POPOSList.css
35+
- POPOSList.js
36+
- POPOSSpace.css
37+
- POPOSSpace.js
38+
- serviceWorker.js
39+
- setupTests.js
40+
- Title.css
41+
- Title.js
42+
- index.css
43+
- index.js
44+
```
45+
>
4346
4447
All of your components should now be in the `components` folder, **except for index.js and index.css**. After this change, your folder structure should look like the following:
4548

P08-Styling-Spaces/content.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ Give it a try!
9999
> Edit `POPOSSpace.css `, set the position property of the parent element to relative.
100100
>
101101
```CSS
102-
.POPOSSpace-title {
102+
.POPOSSpace {
103103
position: relative;
104104
}
105105
```

P10-Search-Spaces/content.md

+108
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,114 @@ const spaces = data.filter((obj) => {
180180
})
181181
```
182182

183+
### ids out sync
184+
185+
At this point the List page will show the search results. Filter is returning a new array with the spaces that match your search results **the index of these new items won't match the position of those items in the data array.**
186+
187+
For example:
188+
189+
```JS
190+
const data = ['100 Pine', '50 Market', '101 California']
191+
// Note the indexes
192+
// 0:'100 Pine', 1:'50 Market', 2:'101 California'
193+
194+
const filteredData = data.filter((item) => item.includes('1'))
195+
// Note the indexes - Notice 50 market is removed and 101 California is now index 1!
196+
// 0:'100 Pine', 1:'101 California'
197+
```
198+
199+
The code in our detail page relies on the index to find the information in the source data.
200+
201+
In the example code above if we use the index from the filtered data the details page would show 50 market instead of 101 California.
202+
203+
To fix this let's add an id property to our data.
204+
205+
> [info]
206+
>
207+
> Add a new file: `sfpopos-data.js` put this in the same folder as `sfpopos-data.json`.
208+
>
209+
> Add the following code to `sfpopos-data.js`:
210+
>
211+
```JS
212+
import data from './sfpopos-data.json'
213+
214+
data.forEach((obj, i) => {
215+
obj.id = i
216+
})
217+
218+
export default data
219+
```
220+
>
221+
222+
What happened here? This file imports `./sfpopos-data.json`, loops over the data and adds a new id property to each object. Where the objects originally looked like this:
223+
224+
```JS
225+
{
226+
title: 'Transamerica Redwood Park',
227+
desc: 'Located in the shadow of the Transamerica Pyramid ...',
228+
address: '600 Montgomery St San ...',
229+
...
230+
}
231+
```
232+
233+
The objects now all look like this:
234+
235+
```js
236+
{
237+
id: 0, // NEW id added here matches the index of this element!
238+
title: 'Transamerica Redwood Park',
239+
desc: 'Located in the shadow of the Transamerica Pyramid ...',
240+
address: '600 Montgomery St San ...',
241+
...
242+
}
243+
```
244+
245+
The last line exports the data. Our other files can now import the data from this file. You'll need to edit any of the files that import `./sfpopos-data.json` and change the import to `./sfpopos-data.js` (notice the difference `.json` to `.js`.)
246+
247+
> [info]
248+
>
249+
> Edit the following follows changing:
250+
```JS
251+
// Change
252+
import data from '../../sfpopos-data.json'
253+
// to
254+
import data from '../../sfpopos-data.js'
255+
```
256+
>
257+
> `components/RandomSpace.js`
258+
> `POPOSDetails.js`
259+
> `POPOSList.js`
260+
>
261+
262+
> [info]
263+
>
264+
> Use the id from data rather than the index from map as the id for each space.
265+
>
266+
> Edit `./components/POPOSList.js`
267+
>
268+
```JS
269+
const spaces = data.filter(({ features, title, address }) => {
270+
...
271+
}).map((obj) => { // remove i here
272+
// Add id here!
273+
const { id, title, address, images, hours, features } = obj
274+
return (
275+
<POPOSSpace
276+
id={id} // use id here
277+
key={`${title}-${id}`} // use id here
278+
name={title}
279+
address={address}
280+
image={images[0]}
281+
hours={hours}
282+
/>
283+
)
284+
})
285+
...
286+
```
287+
>
288+
289+
Here you replaced the index of the element in the array with the id of that element. Where the index might change when the array is filtered each object will always use the same value for the id.
290+
183291
### Style the search field
184292

185293
Here are a few ideas to style the search field. What you do here depends on where you positioned the search field. In my example code it ended up in the first grid cell in the list and I decided to go with it.
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
title: "Publish to GitHub Pages"
3+
slug: publish-to-github-pages
4+
---
5+
6+
## Publishing your React Projects to GitHub
7+
8+
Sharing your work with world is a good thing. GitHub provides an easy way to publish your work. GitHub doesn't allow you to run backend code, upload files, or host a database. Within those limitations GitHub Pages provides a service for the reasonable cost of $0.
9+
10+
GitHub Pages allows you to publish static web sites with little more than the push of a button. The performance is also very good. The pages load quickly and are always available.
11+
12+
### Publishing react
13+
14+
React projects take a little more to publish. The React project source code doesn't run in the browser it must compiled/transpiled first. This process happen when you run your react code in the terminal with `yarn start` or `npm start`. If you want to publish your work you'll run `npm run build`. This will create a JS bundle and put it your public directly. This is the code that you would share with the world.
15+
16+
We can take this process one step further. Besides building the project we can build to a branch and publish that branch. This way your developer code that's in process can be worked on on the master branch while code that's been published can be served from another branch.
17+
18+
Luckily someone has made a library that automates the process.
19+
20+
> [info]
21+
>
22+
> Install the `gh-pages` package.
23+
>
24+
> `npm install --save-dev gh-pages`
25+
>
26+
27+
28+
29+

0 commit comments

Comments
 (0)