Skip to content

Commit 7943799

Browse files
committed
had MVP working and broke it before I could commit
1 parent f7e058c commit 7943799

File tree

12 files changed

+38454
-213
lines changed

12 files changed

+38454
-213
lines changed

package-lock.json

Lines changed: 38092 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
"react-bootstrap": "^1.4.0",
1414
"react-dom": "^16.12.0",
1515
"react-redux": "^7.2.2",
16-
"react-scripts": "3.4.0",
16+
"react-scripts": "^3.4.0",
1717
"redux": "^4.0.5",
18+
"redux-logger": "^3.0.6",
1819
"redux-thunk": "^2.3.0"
1920
},
2021
"scripts": {

public/mockServiceWorker.js

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Mock Service Worker.
33
* @see https://github.com/mswjs/msw
4-
* - Please do NOT modify this file.
4+
*-Please do NOT modify this filerror.
55
* - Please do NOT serve this file on production.
66
*/
77
/* eslint-disable */
@@ -21,7 +21,7 @@ self.addEventListener("activate", async function (event) {
2121
});
2222

2323
self.addEventListener("message", async function (event) {
24-
const clientId = event.source.id;
24+
const clientId = event.sourcerror.id;
2525
const client = await event.currentTarget.clients.get(clientId);
2626
const allClients = await self.clients.matchAll();
2727
const allClientIds = allClients.map((client) => client.id);
@@ -101,8 +101,8 @@ self.addEventListener("fetch", async function (event) {
101101
}
102102

103103
// Bypass requests with the explicit bypass header
104-
if (requestClone.headers.get(bypassHeaderName) === "true") {
105-
const modifiedHeaders = serializeHeaders(requestClone.headers);
104+
if ( requestClonerror.headers.get( bypassHeaderName ) === "true" ) {
105+
const modifiedHeaders = serializeHeaders( requestClonerror.headers );
106106
// Remove the bypass header to comply with the CORS preflight check
107107
delete modifiedHeaders[bypassHeaderName];
108108

@@ -138,11 +138,11 @@ self.addEventListener("fetch", async function (event) {
138138

139139
const clientMessage = rawClientMessage;
140140

141-
switch (clientMessage.type) {
141+
switch ( clientMessagerror.type ) {
142142
case "MOCK_SUCCESS": {
143143
setTimeout(
144-
resolve.bind(this, createResponse(clientMessage)),
145-
clientMessage.payload.delay
144+
resolverror.bind( this, createResponse( clientMessage ) ),
145+
clientMessagerror.payload.delay
146146
);
147147
break;
148148
}
@@ -152,7 +152,10 @@ self.addEventListener("fetch", async function (event) {
152152
}
153153

154154
case "NETWORK_ERROR": {
155-
const { name, message } = clientMessage.payload;
155+
const {
156+
name,
157+
message
158+
} = clientMessagerror.payload;
156159
const networkError = new Error(message);
157160
networkError.name = name;
158161

@@ -161,9 +164,9 @@ self.addEventListener("fetch", async function (event) {
161164
}
162165

163166
case "INTERNAL_ERROR": {
164-
const parsedBody = JSON.parse(clientMessage.payload.body);
167+
const parsedBody = JSON.parse( clientMessagerror.payload.body );
165168

166-
console.error(
169+
consolerror.error(
167170
`\
168171
[MSW] Request handler function for "%s %s" has thrown the following exception:
169172
@@ -181,7 +184,7 @@ If you wish to mock an error response, please refer to this guide: https://mswjs
181184
}
182185
}
183186
}).catch((error) => {
184-
console.error(
187+
consolerror.error(
185188
'[MSW] Failed to mock a "%s" request to "%s": %s',
186189
request.method,
187190
request.url,
@@ -218,9 +221,9 @@ function sendToClient(client, message) {
218221
}
219222

220223
function createResponse(clientMessage) {
221-
return new Response(clientMessage.payload.body, {
222-
...clientMessage.payload,
223-
headers: clientMessage.payload.headers,
224+
return new Response( clientMessagerror.payload.body, {
225+
...clientMessagerror.payload,
226+
headers: clientMessagerror.payload.headers,
224227
});
225228
}
226229

src/App.js

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,65 @@
1-
import React, { Component } from "react";
1+
// import React, { Component } from "react";
2+
//
3+
// import AddForm from "./components/AddForm";
4+
// import SmurfList from "./components/SmurfList";
5+
// import Header from "./components/Header";
6+
//
7+
// import "bootstrap/dist/css/bootstrap.min.css";
8+
// import "./App.css";
9+
//
10+
// class App extends Component {
11+
// render() {
12+
// return (
13+
// <div className="App">
14+
// <Header />
15+
//
16+
// <main>
17+
// <SmurfList />
18+
// <AddForm />
19+
// </main>
20+
// </div>
21+
// );
22+
// }
23+
// }
24+
//
25+
// export default App;
26+
//
27+
// //Task List:
28+
// //1. Connect the fetchSmurfs actions to the App component.
29+
// //2. Call the fetchSmurfs action when the component first loads.
230

3-
import AddForm from "./components/AddForm";
4-
import SmurfList from "./components/SmurfList";
5-
import Header from "./components/Header";
631

7-
import "bootstrap/dist/css/bootstrap.min.css";
8-
import "./App.css";
32+
import React, { Component } from 'react';
33+
import { connect } from 'react-redux';
34+
35+
import AddForm from './components/AddForm';
36+
import SmurfList from './components/SmurfList';
37+
import Header from './components/Header';
38+
39+
import { fetchSmurfs } from './actions';
40+
41+
import 'bootstrap/dist/css/bootstrap.min.css';
42+
import './App.css';
943

1044
class App extends Component {
45+
46+
componentDidMount() {
47+
this.props.fetchSmurfs();
48+
}
49+
1150
render() {
51+
1252
return (
1353
<div className="App">
1454
<Header />
1555

1656
<main>
17-
<SmurfList />
18-
<AddForm />
57+
<SmurfList/>
58+
<AddForm/>
1959
</main>
2060
</div>
2161
);
2262
}
2363
}
2464

25-
export default App;
26-
27-
//Task List:
28-
//1. Connect the fetchSmurfs actions to the App component.
29-
//2. Call the fetchSmurfs action when the component first loads.
65+
export default connect(null, { fetchSmurfs })(App);

src/actions/index.js

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,61 @@
11
// import axios from 'axios';
22

33
//Task List:
4-
//1. Add a thunk action called fetchSmurfs that triggers a loading status display in our application, performs an axios call to retreive smurfs from our server, saves the result of that call to our state and shows an error if one is made.
4+
//1. Add a thunk action called fetchSmurfs that triggers a loading status display in our application, performs an axios call to retreive smurfs from our server, saves the result of that call to our state and shows an error if one is maderror.
55
//2. Add a standard action that allows us to add new smurf (including the name, nickname, position, summary)
6-
//3. Add a standard action that allows us to set the value of the error message slice of state.
7-
import axios from 'axios';
8-
9-
//Const
10-
export const FETCH_START = 'FETCH_START';
11-
export const FETCH_SUCCESS = 'FETCH_SUCCESS';
12-
export const FETCH_FAIL = 'FETCH_FAIL';
13-
export const ADD_SMURFS = 'ADD_SMURFS';
14-
export const ERROR = 'ERROR';
15-
16-
6+
//3. Add a standard action that allows us to set the value of the error message slice of staterror.
7+
import axios from "axios";
8+
export const FETCH_START = "FETCH_START";
9+
export const FETCH_SUCCESS = "FETCH_SUCCESS";
10+
export const FETCH_FAIL = "FETCH_FAIL";
11+
export const ADD_SMURF = "ADD_SMURF";
12+
export const ERROR = "ERROR";
1713

1814
export const fetchSmurfs = () => {
1915
return ( dispatch ) => {
2016
dispatch( fetchStart() );
2117

2218
axios
23-
.get( 'http://localhost:3333/smurfs' )
24-
.then( res => {
19+
.get( "http://localhost:3333/smurfs" )
20+
.then( ( res ) => {
2521
dispatch( fetchSuccess( res.data ) );
2622
} )
27-
.catch( err => {
28-
dispatch( fetchFail( "Couldn't get the info" ) )
29-
} )
30-
}
31-
}
23+
.catch( ( err ) => {
24+
dispatch( fetchFail( "Couldn't get the info" ) );
25+
} );
26+
};
27+
};
3228

3329
export const fetchStart = () => {
34-
return ( { type: FETCH_START } )
35-
}
30+
return {
31+
type: FETCH_START
32+
};
33+
};
3634

3735
export const fetchSuccess = ( smurfs ) => {
38-
return ( { type: FETCH_SUCCESS, payload: smurfs } )
39-
}
36+
return {
37+
type: FETCH_SUCCESS,
38+
payload: smurfs
39+
};
40+
};
4041

4142
export const fetchFail = ( error ) => {
42-
return ( { type: FETCH_FAIL, payload: error } )
43-
}
43+
return {
44+
type: FETCH_FAIL,
45+
payload: error
46+
};
47+
};
4448

4549
export const addSmurfs = ( smurfs ) => {
46-
return ( { type: ADD_SMURFS, payload: smurfs } )
47-
}
50+
return {
51+
type: ADD_SMURF,
52+
payload: smurfs
53+
};
54+
};
4855

4956
export const errorMessage = ( error ) => {
50-
return ( { type: ERROR, payload: error } )
51-
}
57+
return {
58+
type: ERROR,
59+
payload: error
60+
};
61+
};

0 commit comments

Comments
 (0)