Skip to content

Commit

Permalink
Multiple boilerplate cleanings
Browse files Browse the repository at this point in the history
  • Loading branch information
qwebdev committed May 18, 2018
1 parent 28d8366 commit c00a71b
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 118 deletions.
10 changes: 2 additions & 8 deletions src/Config/AppConfig.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
// Simple React Native specific changes

export default {
// font scaling override - RN default is on
allowTextFontScaling: true,
AppName: 'Binder',
APIServer: 'http://localhost:8000/api/v1',
AdMobBannerID: '',
FCMKey: '',
AppName: 'React JS BoilerPlate',
APIServer: 'https://jsonplaceholder.typicode.com',
}
17 changes: 1 addition & 16 deletions src/Containers/GetExample.js → src/Containers/Posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,10 @@ import { Form, TextArea } from 'semantic-ui-react'
class GetExample extends Component {

componentDidMount(){
console.log(this.props.posts.data);

// Fetching the data into props from the API
this.props.getAPIData();



}


componentDidUpdate(){
console.log(this.props.posts.data);

// Once API data is fetched, dispatching a post request
if(typeof this.props.posts.data !== 'undefined'){
// this.props.postAPIData('JWT Token');
}

}

render(){
Expand Down Expand Up @@ -56,8 +42,7 @@ const mapStateToProps = (state) => {

const mapDispatchToProps = (dispatch) => {
return {
getAPIData: (data) => dispatch(PostsActions.postsSet(data)),
postAPIData: (data) => dispatch(PostsActions.postsSet(data)),
getAPIData: (data) => dispatch(PostsActions.postsGet(data)),
}
};

Expand Down
27 changes: 10 additions & 17 deletions src/Navigation/Routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,21 @@ import React, { Component } from 'react'

import NotFoundPage from '../Components/NotFoundPage';
import Home from '../Containers/Home';
import GetExample from '../Containers/GetExample';
import Posts from '../Containers/Posts';
import {Route, Switch} from "react-router-dom";


class AppNavigation extends Component {

render(){
return(

<Switch>
<Route exact path="/" component={Home}/>
<Route exact path="/example" component={GetExample}/>
<Route component={NotFoundPage}/>
</Switch>

)
return(
<Switch>
<Route exact path="/" component={Home}/>
<Route exact path="/example" component={Posts}/>
<Route component={NotFoundPage}/>
</Switch>

)
}
}

}

// AppNavigation.propTypes = {
// children: PropTypes.element
// };

export default AppNavigation;
6 changes: 0 additions & 6 deletions src/Redux/Posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import Immutable from 'seamless-immutable'

const { Types, Creators } = createActions({
postsGet: null,
postsSet: ['data'],
postsSuccess: ['data'],
postsFailure: null,
})
Expand All @@ -27,10 +26,6 @@ export const INITIAL_STATE = Immutable({
export const get = (state, { data }) =>
state.merge({ fetching: true, data })

// request the data from an api
export const set = (state, { data }) =>
state.merge({ fetching: true, data })

// successful api lookup
export const success = (state, { data }) =>
state.merge({ fetching: false, error: null, data:data })
Expand All @@ -43,7 +38,6 @@ export const failure = state =>

export const Posts = createReducer(INITIAL_STATE, {
[Types.POSTS_GET]: get,
[Types.POSTS_SET]: set,
[Types.POSTS_SUCCESS]: success,
[Types.POSTS_FAILURE]: failure,
})
12 changes: 3 additions & 9 deletions src/Sagas/ExampleSaga.js → src/Sagas/PostsSaga.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,12 @@ import { put, call } from 'redux-saga/effects';
import PostsActions from "../Redux/Posts";

export function * onExampleFetch(api, action) {

const response = yield call(api.getExampleData, action.data)

console.log(action.data);
console.log(response.data);

const response = yield call(api.getPosts, action.data)
if (response.ok) {
console.log('Profile succesfully updated');
console.log('API Data fetched');
yield put(PostsActions.postsSuccess(response.data))
} else {
console.log('Profile did not update. Backend might be down.');
console.log('API Data fetched. Backend might be down.');
yield put(PostsActions.postsFailure())
}

}
29 changes: 2 additions & 27 deletions src/Sagas/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import { takeLatest, all } from 'redux-saga/effects'
import "regenerator-runtime/runtime";
import API from '../Services/Api'
// import FixtureAPI from '../Services/FixtureApi'
// import DebugConfig from '../Config/DebugConfig'

/* ------------- Types ------------- */

import {PostsActions} from '../Redux/Posts'


/* ------------- Sagas ------------- */

import { onExampleFetch } from './ExampleSaga'

import { onExampleFetch } from './PostsSaga'

/* ------------- API ------------- */

Expand All @@ -25,27 +21,6 @@ const api = API.create()
export default function * root () {
yield all([
// some sagas only receive an action
takeLatest(PostsActions.POSTS_SET, onExampleFetch, api),
//
// takeLatest(UserActions.USER_REQUEST, onFetchRecords),
// takeLatest(SettingsActions.SETTINGS_SET, onSettingsSet, api),
// takeLatest(ProfileActions.PROFILE_SET, onProfileUpdate, api),
//
// takeLatest(UsersActions.GENERAL_REQUEST, onUsersFetch, api),
//
//
// takeLatest(MatchesActions.MATCH_REQUEST, onActionSent, api),
//
// takeLatest(ConversationActions.CONVERSATIONS_REQUEST, onConversationsFetch, api),
//
// //TODO: Not really needing these ones
// takeLatest(MessagesActions.MESSAGE_ADD, onNewMessage, api),
// takeLatest(MessagesActions.MESSAGES_REQUEST, onMessagesFetched, api),
//
// takeLatest(LocationActions.LOCATION_REQUEST, onLocationUpdate, api),
// takeLatest(NotificationActions.NOTIFICATION_REQUEST, onDeviceTokenUpdate, api),
//
// takeLatest(UserReportActions.REPORT_SEND, onReportSent, api),

takeLatest(PostsActions.POSTS_GET, onExampleFetch, api),
])
}
25 changes: 4 additions & 21 deletions src/Services/Api.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// a library to wrap and simplify api calls
import apisauce from 'apisauce'
// import AppConfig from '../Config/AppConfig'
import AppConfig from '../Config/AppConfig'

// our "constructor"
const create = (baseURL = /*AppConfig.APIServer*/ 'https://jsonplaceholder.typicode.com') => {
const create = (baseURL = AppConfig.APIServer ) => {
// ------
// STEP 1
// ------
Expand Down Expand Up @@ -40,16 +39,8 @@ const create = (baseURL = /*AppConfig.APIServer*/ 'https://jsonplaceholder.typi
// way at this level.
//

const getExampleData = (token) => api.get('posts', {token:token})
// const getMatches = (token) => api.get('users', {token:token})
//
// const getConversations = (token) => api.get('conversations', {token:token})
// const userAction = (token,data) => api.post('action', {data:data}, {headers: {Authorization: 'Bearer ' + token}})
const getPosts = (token) => api.get('posts', {token:token})
// const setSettings = (token,data) => api.post(`settings`, {data:data}, {headers: {Authorization: 'Bearer ' + token}})
// const updateProfile = (token,data) => api.post(`profile`, {data:data}, {headers: {Authorization: 'Bearer ' + token}})
// const setLocation = (token,data) => api.post(`location/set`, {data:data}, {headers: {Authorization: 'Bearer ' + token}})
// const sendReport = (token,data) => api.post(`report`, {data:data}, {headers: {Authorization: 'Bearer ' + token}})
// const updateNotificationToken = (token,data) => api.post(`notification/updateToken`, {data:data}, {headers: {Authorization: 'Bearer ' + token}})

// ------
// STEP 3
Expand All @@ -65,15 +56,7 @@ const create = (baseURL = /*AppConfig.APIServer*/ 'https://jsonplaceholder.typi
//
return {
// a list of the API functions from step 2
getExampleData,
// getMatches,
// userAction,
// setSettings,
// updateProfile,
// setLocation,
// getConversations,
// sendReport,
// updateNotificationToken
getPosts,
}
}

Expand Down
12 changes: 0 additions & 12 deletions src/containers/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,9 @@ import { Icon } from 'semantic-ui-react'
class Home extends Component {

componentDidMount(){

// alert(1);
console.log(this.props);
console.log(this.state);

}


componentDidUpdate(){

// alert(1);
console.log(this.props);
console.log(this.state);
// this.props.getAPIData();

}

render(){
Expand Down
2 changes: 0 additions & 2 deletions src/store/CreateStore.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { createStore, applyMiddleware, compose } from 'redux'
// import Config from '../Config/DebugConfig'
import createSagaMiddleware from 'redux-saga'

import createHistory from 'history/createBrowserHistory';
Expand All @@ -22,7 +21,6 @@ export default (rootReducer, rootSaga) => {
/* ------------- Assemble Middleware ------------- */
enhancers.push(applyMiddleware(...middleware))

// if Reactotron is enabled (default for __DEV__), we'll create the Store through Reactotron
const createAppropriateStore = createStore
const composeMethod = process.env.NODE_ENV === 'production' ? compose : window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
const store = createAppropriateStore(rootReducer, composeMethod(...enhancers))
Expand Down

0 comments on commit c00a71b

Please sign in to comment.