Skip to content

Instantly share code, notes, and snippets.

krissanawat101 krissnawat

Block or report user

Report or block krissnawat

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Article-reducer.js
const initialState = {
articles: [],
article: {}
}
export default (state=initialState, action) => {
switch (action.type) {
case 'LOAD_ARTICLES' :
return {
...state,
articles: action.articles
@krissnawat
krissnawat / authUser.js
Created Feb 3, 2019
src/redux/reducers/authUser.js
View authUser.js
const initialState = {
user: {},
isAuth: false,
profile: {}
}
export default (state = initialState, action) => {
switch (action.type) {
case 'SET_USER':
return {
...state,
@krissnawat
krissnawat / common.js
Created Feb 3, 2019
// src/redux/reducers/common.js
View common.js
const defaultState = {
appName: '',
modalMode: false
};
export default (state = defaultState, action) => {
switch (action.type) {
case 'TOGGLE_MODAL':
console.log(`toggling modal: ${action.modalMode}`)
View redux-actions.js
import axios from 'axios'
//const url = "http://localhost:5000/api/"
const url = process.env.NODE_ENV === 'production' ? "/api/" : "http://localhost:5000/api/"
export function loadArticles () {
return (dispatch) => {
axios.get(`${url}articles`)
.then((res) => {
let articles = res.data
dispatch({type:'LOAD_ARTICLES', articles})
View reducer.js
import { combineReducers } from 'redux';
import articles from './reducers/articles';
import authUser from './reducers/authUser';
import common from './reducers/common';
import { routerReducer } from 'react-router-redux';
export default combineReducers({
articles,
authUser,
common,
router: routerReducer
View store.js
import { applyMiddleware, createStore } from 'redux';
//import { createLogger } from 'redux-logger'
import { composeWithDevTools } from 'redux-devtools-extension/developmentOnly';
import reducer from './reducer';
import thunk from 'redux-thunk'
import createHistory from 'history/createBrowserHistory';
export const history = createHistory();
// Build the middleware for intercepting and dispatching navigation actions
//const myRouterMiddleware = routerMiddleware(history);
View src-index.js
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import App from './App.js';
import registerServiceWorker from './registerServiceWorker';
import { store, history } from './redux/store';
ReactDOM.render((
View src-index.js
import React from 'react';
import ReactDOM from 'react-dom';
import './assets/medium.css';
import { Provider } from 'react-redux';
import { Switch, Route } from 'react-router-dom';
import { ConnectedRouter } from 'react-router-redux';
import App from './App.js';
import registerServiceWorker from './registerServiceWorker';
import { store, history } from './redux/store';
View src-App.js
import React, { Component } from 'react';
import { Switch, Route } from 'react-router-dom'
import Header from './components/Header';
import Feed from './components/Feed'
import Profile from './components/Profile'
import ArticleView from './components/ArticleView'
import Editor from './components/Editor'
import SignInWith from './components/SignInWith'
class App extends Component {
render() {
View requireAuth.js
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
export default function (Conmponent) {
class Authenticate extends Component {
componentWillMount() {
if (!this.props.isAuth) {
this.context.router.history.push('/')
}
You can’t perform that action at this time.