[ ADD ] react configuration

This commit is contained in:
Kuroi488
2020-11-16 17:14:34 +01:00
parent 89c9cfe099
commit 5078a1a96e
71 changed files with 16891 additions and 0 deletions

View File

@ -0,0 +1,11 @@
import * as types from "./FeatureTypes";
//Replace action name and update action types
export const actionRequest = () => ({
type: types.GET_DATA_REQUEST
});
export const actionReceive = payload => ({
type: types.GET_DATA_REQUEST,
payload
});

View File

@ -0,0 +1,11 @@
import {axiosInstance} from '../../network/apis';
const handlerEnabled = false;
// Replace endpoint and change api name
const apiExampleRequest = async () => {
return await axiosInstance.get(`ENDPOINT`, { handlerEnabled });
};
export default {
apiExampleRequest
};

View File

@ -0,0 +1,16 @@
import * as types from "./FeatureTypes";
const INITIAL_STATE = {};
// Replace with you own reducer
export default (state = INITIAL_STATE, action) => {
switch (action.type) {
case types.GET_DATA_RECEIVE:
return {
...state,
...action.payload
};
default:
return state;
}
};

View File

@ -0,0 +1,21 @@
import { call, put } from "redux-saga/effects";
import API from "./FeatureApis";
import * as ACTIONS from "./FeatureAction";
import { dispatchSnackbarError } from "../../utils/Shared";
import { takeLatest } from "redux-saga/effects";
import * as TYPES from "./FeatureTypes";
// Replace with your sagas
export function* sagasRequestExample() {
try {
const response = yield call(API.apiExampleRequest);
yield put(ACTIONS.actionReceive(response.data));
} catch (err) {
dispatchSnackbarError(err.response.data);
}
}
export function* FeatureSaga1() {
yield takeLatest(TYPES.GET_DATA_REQUEST, sagasRequestExample);
}

View File

@ -0,0 +1,3 @@
// Replace with your request types
export const GET_DATA_REQUEST = 'GET_DATA_REQUEST';
export const GET_DATA_RECEIVE = 'GET_DATA_RECEIVE';

View File

@ -0,0 +1,10 @@
import * as types from './LangTypes';
export const setCurrentLang = payload => {
localStorage.setItem('lang', payload);
return { type: types.SET_LANG, payload };
}
export const getCurrentLang = () => {
return { type: types.GET_LANG };
};

View File

@ -0,0 +1,14 @@
import * as types from "./LangTypes";
const INITIAL_STATE = localStorage.getItem("lang") || "en";
export default function locale(state = INITIAL_STATE, action) {
switch (action.type) {
case types.SET_LANG:
return action.payload;
case types.GET_LANG:
return action.payload;
default:
return state;
}
}

View File

@ -0,0 +1,2 @@
export const SET_LANG = 'SET_LANG';
export const GET_LANG = 'GET_LANG';

View File

@ -0,0 +1,13 @@
import * as types from "./LoaderTypes";
export const loader = isLoading => {
return isLoading
? {
type: types.SHOW_LOADER,
data: isLoading
}
: {
type: types.HIDE_LOADER,
data: isLoading
};
};

View File

@ -0,0 +1,14 @@
import * as types from "./LoaderTypes";
const INITIAL_STATE = false;
export default (state = INITIAL_STATE, action) => {
switch (action.type) {
case types.SHOW_LOADER:
return action.data;
case types.HIDE_LOADER:
return action.data;
default:
return state;
}
};

View File

@ -0,0 +1,2 @@
export const SHOW_LOADER = 'SHOW_LOADER';
export const HIDE_LOADER = 'HIDE_LOADER';

View File

@ -0,0 +1,15 @@
import * as types from './SnackbarTypes';
export const showSnackbarAction = (message , snacknarType) => {
return {
type: types.SHOW_SNACKBAR,
message ,
snacknarType
};
};
export const hideSnackbarAction = () => {
return {
type: types.HIDE_SNACKBAR
};
};

View File

@ -0,0 +1,21 @@
import * as types from "./SnackbarTypes";
export default (state = {}, action) => {
switch (action.type) {
case types.SHOW_SNACKBAR:
return {
...state,
isOpen: true,
message: action.message,
type: action.snacknarType
};
case types.HIDE_SNACKBAR:
return {
...state,
isOpen: false
};
default:
return state;
}
};

View File

@ -0,0 +1,2 @@
export const SHOW_SNACKBAR = 'SHOW_SNACKBAR';
export const HIDE_SNACKBAR = 'HIDE_SNACKBAR';

17
react/src/store/index.js Normal file
View File

@ -0,0 +1,17 @@
import { createStore, applyMiddleware, compose } from "redux";
import reducers from "./reducers";
import createSagaMiddleware from "redux-saga";
import { watchSagas } from "./sagas";
const saga = createSagaMiddleware();
//redux dev tool
const composeEnhancers =
typeof window === "object" && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({})
: compose;
const enhancer = composeEnhancers(applyMiddleware(saga));
const store = createStore(reducers, enhancer);
saga.run(watchSagas);
export default store;

View File

@ -0,0 +1,12 @@
import { combineReducers } from "redux";
import lang from "../Lang/LangReducer";
import loader from "../Loader/LoaderReducer";
import snackbar from "../Snackbar/SnackbarReducer";
import Feature1 from "../Feature1/FeatureReducer";
export default combineReducers({
lang,
loader,
snackbar,
Feature1
});

View File

@ -0,0 +1,9 @@
import { FeatureSaga1 } from '../Feature1/FeatureSagas';
import { fork, all } from "redux-saga/effects";
export function* watchSagas() {
//Combine sagas with
yield all([FeatureSaga1()]);
// OR
// yield all([fork(FeatureSaga1)]);
}