mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-26 14:54:19 +03:00
Added redux library to all project
This commit is contained in:
parent
66518d10cb
commit
79d0dd2e98
@ -82,4 +82,4 @@
|
||||
"git add"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
@ -28,6 +28,8 @@ export const Login = (username, password) => {
|
||||
posting: account["posting"].key_auths.map(x => x[0]),
|
||||
};
|
||||
|
||||
console.log("=========account==========", account);
|
||||
|
||||
// Set private keys of user
|
||||
privateKeys = getPrivateKeys(username, password);
|
||||
|
||||
|
43
src/redux/actions/accountAction.js
Normal file
43
src/redux/actions/accountAction.js
Normal file
@ -0,0 +1,43 @@
|
||||
import { getAccount } from "../../providers/steem/dsteem";
|
||||
import {
|
||||
ADD_NEW_ACCOUNT,
|
||||
UPDATE_ACCOUNT_DATA,
|
||||
REMOVE_ACCOUNT_DATA,
|
||||
FETCH_ACCOUNT_FAIL,
|
||||
FETCHING_ACCOUNT,
|
||||
} from "../constants/constants";
|
||||
|
||||
export function fetchAccountFromSteem(user) {
|
||||
return dispatch => {
|
||||
dispatch({ type: FETCHING_ACCOUNT });
|
||||
|
||||
return getAccount(user)
|
||||
.then(res => {
|
||||
return dispatch({ type: ADD_NEW_ACCOUNT, payload: res[0] });
|
||||
})
|
||||
.catch(err => {
|
||||
return dispatch({ type: FETCH_ACCOUNT_FAIL, payload: err });
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export function addNewAccount(data) {
|
||||
return {
|
||||
type: ADD_NEW_ACCOUNT,
|
||||
payload: data,
|
||||
};
|
||||
}
|
||||
|
||||
export function updateAccountData(data) {
|
||||
return {
|
||||
type: UPDATE_ACCOUNT_DATA,
|
||||
payload: data,
|
||||
};
|
||||
}
|
||||
|
||||
export function removeAccountData(data) {
|
||||
return {
|
||||
type: REMOVE_ACCOUNT_DATA,
|
||||
payload: data,
|
||||
};
|
||||
}
|
@ -1,7 +1,14 @@
|
||||
export const FETCH_USER = "FETCH_USER";
|
||||
export const FETCH_USER_SUCCESS = "FETCH_USER_SUCCESS";
|
||||
export const FETCH_USER_FAIL = "FETCH_USER_FAIL";
|
||||
export const SET_USER_DATA = "SET_USER_DATA";
|
||||
|
||||
export const LOGOUT = "LOGOUT";
|
||||
export const LOGOUT_SUCCESS = "LOGOUT_SUCCESS";
|
||||
export const LOGOUT_FAIL = "LOGOUT_FAIL";
|
||||
|
||||
export const ADD_NEW_ACCOUNT = "ADD_NEW_ACCOUNT";
|
||||
export const UPDATE_ACCOUNT_DATA = "UPDATE_ACCOUNT_DATA";
|
||||
export const REMOVE_ACCOUNT_DATA = "REMOVE_ACCOUNT_DATA";
|
||||
export const FETCHING_ACCOUNT = "FETCHING_ACCOUNT";
|
||||
export const FETCH_ACCOUNT_FAIL = "FETCH_ACCOUNT_FAIL";
|
||||
|
60
src/redux/reducers/accountReducer.js
Normal file
60
src/redux/reducers/accountReducer.js
Normal file
@ -0,0 +1,60 @@
|
||||
import {
|
||||
ADD_NEW_ACCOUNT,
|
||||
UPDATE_ACCOUNT_DATA,
|
||||
REMOVE_ACCOUNT_DATA,
|
||||
FETCH_ACCOUNT_FAIL,
|
||||
FETCHING_ACCOUNT,
|
||||
} from "../constants/constants";
|
||||
|
||||
const initialState = {
|
||||
isFetching: null,
|
||||
data: [],
|
||||
hasError: false,
|
||||
errorMessage: null,
|
||||
};
|
||||
|
||||
export default function(state = initialState, action) {
|
||||
switch (action.type) {
|
||||
case FETCHING_ACCOUNT:
|
||||
return {
|
||||
...state,
|
||||
isFetching: true,
|
||||
hasError: false,
|
||||
errorMessage: null,
|
||||
};
|
||||
case FETCH_ACCOUNT_FAIL:
|
||||
return {
|
||||
...state,
|
||||
isFetching: false,
|
||||
hasError: true,
|
||||
errorMessage: action.err,
|
||||
};
|
||||
case ADD_NEW_ACCOUNT:
|
||||
return {
|
||||
...state,
|
||||
isFetching: false,
|
||||
data: state.data.push(action.payload),
|
||||
hasError: false,
|
||||
errorMessage: null,
|
||||
};
|
||||
|
||||
case UPDATE_ACCOUNT_DATA:
|
||||
return Object.assign({}, state, {
|
||||
isFetching: false,
|
||||
data: action.payload,
|
||||
hasError: false,
|
||||
errorMessage: null,
|
||||
});
|
||||
|
||||
case REMOVE_ACCOUNT_DATA:
|
||||
return Object.assign({}, state, {
|
||||
isFetching: false,
|
||||
data: action.payload,
|
||||
hasError: false,
|
||||
errorMessage: null,
|
||||
});
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
import { combineReducers } from 'redux';
|
||||
import userReducer from './userReducer';
|
||||
import { combineReducers } from "redux";
|
||||
import userReducer from "./userReducer";
|
||||
import accountReducer from "./accountReducer";
|
||||
|
||||
export default combineReducers({
|
||||
account: userReducer,
|
||||
accounts: accountReducer,
|
||||
});
|
||||
|
@ -1,5 +1,8 @@
|
||||
import { Provider } from "react-redux";
|
||||
import { Navigation } from "react-native-navigation";
|
||||
|
||||
import store from "../redux/store/store";
|
||||
|
||||
// SCREENS
|
||||
import Splash from "./splash/splashContainer";
|
||||
import SideMenu from "./sideMenuScreen";
|
||||
@ -22,29 +25,108 @@ import PostCard from "../components/post-card/postCard";
|
||||
import Search from "../components/search/search";
|
||||
|
||||
function registerScreens() {
|
||||
Navigation.registerComponent("navigation.eSteem.Splash", () => Splash);
|
||||
Navigation.registerComponent("navigation.eSteem.Home", () => Home);
|
||||
Navigation.registerComponent("navigation.eSteem.Hot", () => Hot);
|
||||
Navigation.registerComponent("navigation.eSteem.Feed", () => Feed);
|
||||
Navigation.registerComponent("navigation.eSteem.Post", () => Post);
|
||||
Navigation.registerComponent("navigation.eSteem.Login", () => Login);
|
||||
Navigation.registerComponent("navigation.eSteem.Wallet", () => Wallet);
|
||||
Navigation.registerComponent("navigation.eSteem.Editor", () => Editor);
|
||||
Navigation.registerComponent("navigation.eSteem.Discover", () => Discover);
|
||||
Navigation.registerComponent("navigation.eSteem.Settings", () => Settings);
|
||||
Navigation.registerComponent(
|
||||
Navigation.registerComponentWithRedux(
|
||||
"navigation.eSteem.Splash",
|
||||
() => Splash,
|
||||
Provider,
|
||||
store
|
||||
);
|
||||
Navigation.registerComponentWithRedux(
|
||||
"navigation.eSteem.Home",
|
||||
() => Home,
|
||||
Provider,
|
||||
store
|
||||
);
|
||||
Navigation.registerComponentWithRedux(
|
||||
"navigation.eSteem.Hot",
|
||||
() => Hot,
|
||||
Provider,
|
||||
store
|
||||
);
|
||||
Navigation.registerComponentWithRedux(
|
||||
"navigation.eSteem.Feed",
|
||||
() => Feed,
|
||||
Provider,
|
||||
store
|
||||
);
|
||||
Navigation.registerComponentWithRedux(
|
||||
"navigation.eSteem.Post",
|
||||
() => Post,
|
||||
Provider,
|
||||
store
|
||||
);
|
||||
Navigation.registerComponentWithRedux(
|
||||
"navigation.eSteem.Login",
|
||||
() => Login,
|
||||
Provider,
|
||||
store
|
||||
);
|
||||
Navigation.registerComponentWithRedux(
|
||||
"navigation.eSteem.Wallet",
|
||||
() => Wallet,
|
||||
Provider,
|
||||
store
|
||||
);
|
||||
Navigation.registerComponentWithRedux(
|
||||
"navigation.eSteem.Editor",
|
||||
() => Editor,
|
||||
Provider,
|
||||
store
|
||||
);
|
||||
Navigation.registerComponentWithRedux(
|
||||
"navigation.eSteem.Discover",
|
||||
() => Discover,
|
||||
Provider,
|
||||
store
|
||||
);
|
||||
Navigation.registerComponentWithRedux(
|
||||
"navigation.eSteem.Settings",
|
||||
() => Settings,
|
||||
Provider,
|
||||
store
|
||||
);
|
||||
Navigation.registerComponentWithRedux(
|
||||
"navigation.eSteem.Notifications",
|
||||
() => Notifications
|
||||
() => Notifications,
|
||||
Provider,
|
||||
store
|
||||
);
|
||||
Navigation.registerComponent(
|
||||
Navigation.registerComponentWithRedux(
|
||||
"navigation.eSteem.SideMenuScreen",
|
||||
() => SideMenu
|
||||
() => SideMenu,
|
||||
Provider,
|
||||
store
|
||||
);
|
||||
Navigation.registerComponentWithRedux(
|
||||
"navigation.eSteem.Profile",
|
||||
() => Profile,
|
||||
Provider,
|
||||
store
|
||||
);
|
||||
Navigation.registerComponentWithRedux(
|
||||
"navigation.eSteem.Author",
|
||||
() => Author,
|
||||
Provider,
|
||||
store
|
||||
);
|
||||
Navigation.registerComponentWithRedux(
|
||||
"navigation.eSteem.PostCard",
|
||||
() => PostCard,
|
||||
Provider,
|
||||
store
|
||||
);
|
||||
Navigation.registerComponentWithRedux(
|
||||
"navigation.eSteem.Search",
|
||||
() => Search,
|
||||
Provider,
|
||||
store
|
||||
);
|
||||
Navigation.registerComponentWithRedux(
|
||||
"navigation.eSteem.PinCode",
|
||||
() => PinCode,
|
||||
Provider,
|
||||
store
|
||||
);
|
||||
Navigation.registerComponent("navigation.eSteem.Profile", () => Profile);
|
||||
Navigation.registerComponent("navigation.eSteem.Author", () => Author);
|
||||
Navigation.registerComponent("navigation.eSteem.PostCard", () => PostCard);
|
||||
Navigation.registerComponent("navigation.eSteem.Search", () => Search);
|
||||
Navigation.registerComponent("navigation.eSteem.PinCode", () => PinCode);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
@ -22,6 +22,7 @@ import {
|
||||
Thumbnail,
|
||||
} from "native-base";
|
||||
import { Navigation } from "react-native-navigation";
|
||||
import { connect } from "react-redux";
|
||||
|
||||
import { Login } from "../../providers/steem/auth";
|
||||
import RNRestart from "react-native-restart";
|
||||
@ -38,6 +39,10 @@ class LoginPage extends Component {
|
||||
};
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
console.log("=================test", this.props.account);
|
||||
}
|
||||
|
||||
doLogin = () => {
|
||||
const { componentId } = this.props;
|
||||
|
||||
@ -349,4 +354,9 @@ const styles = StyleSheet.create({
|
||||
flexDirection: "row",
|
||||
},
|
||||
});
|
||||
export default LoginPage;
|
||||
|
||||
const mapStateToProps = state => ({
|
||||
account: state.accounts,
|
||||
});
|
||||
|
||||
export default connect(mapStateToProps)(LoginPage);
|
||||
|
Loading…
Reference in New Issue
Block a user