Added redux library to all project

This commit is contained in:
mistikk 2018-09-13 23:36:03 +03:00
parent 66518d10cb
commit 79d0dd2e98
9 changed files with 2348 additions and 69 deletions

View File

@ -82,4 +82,4 @@
"git add" "git add"
] ]
} }
} }

View File

@ -28,6 +28,8 @@ export const Login = (username, password) => {
posting: account["posting"].key_auths.map(x => x[0]), posting: account["posting"].key_auths.map(x => x[0]),
}; };
console.log("=========account==========", account);
// Set private keys of user // Set private keys of user
privateKeys = getPrivateKeys(username, password); privateKeys = getPrivateKeys(username, password);

View 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,
};
}

View File

@ -1,7 +1,14 @@
export const FETCH_USER = "FETCH_USER"; export const FETCH_USER = "FETCH_USER";
export const FETCH_USER_SUCCESS = "FETCH_USER_SUCCESS"; export const FETCH_USER_SUCCESS = "FETCH_USER_SUCCESS";
export const FETCH_USER_FAIL = "FETCH_USER_FAIL"; export const FETCH_USER_FAIL = "FETCH_USER_FAIL";
export const SET_USER_DATA = "SET_USER_DATA";
export const LOGOUT = "LOGOUT"; export const LOGOUT = "LOGOUT";
export const LOGOUT_SUCCESS = "LOGOUT_SUCCESS"; export const LOGOUT_SUCCESS = "LOGOUT_SUCCESS";
export const LOGOUT_FAIL = "LOGOUT_FAIL"; 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";

View 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;
}
}

View File

@ -1,6 +1,7 @@
import { combineReducers } from 'redux'; import { combineReducers } from "redux";
import userReducer from './userReducer'; import userReducer from "./userReducer";
import accountReducer from "./accountReducer";
export default combineReducers({ export default combineReducers({
account: userReducer, accounts: accountReducer,
}); });

View File

@ -1,5 +1,8 @@
import { Provider } from "react-redux";
import { Navigation } from "react-native-navigation"; import { Navigation } from "react-native-navigation";
import store from "../redux/store/store";
// SCREENS // SCREENS
import Splash from "./splash/splashContainer"; import Splash from "./splash/splashContainer";
import SideMenu from "./sideMenuScreen"; import SideMenu from "./sideMenuScreen";
@ -22,29 +25,108 @@ import PostCard from "../components/post-card/postCard";
import Search from "../components/search/search"; import Search from "../components/search/search";
function registerScreens() { function registerScreens() {
Navigation.registerComponent("navigation.eSteem.Splash", () => Splash); Navigation.registerComponentWithRedux(
Navigation.registerComponent("navigation.eSteem.Home", () => Home); "navigation.eSteem.Splash",
Navigation.registerComponent("navigation.eSteem.Hot", () => Hot); () => Splash,
Navigation.registerComponent("navigation.eSteem.Feed", () => Feed); Provider,
Navigation.registerComponent("navigation.eSteem.Post", () => Post); store
Navigation.registerComponent("navigation.eSteem.Login", () => Login); );
Navigation.registerComponent("navigation.eSteem.Wallet", () => Wallet); Navigation.registerComponentWithRedux(
Navigation.registerComponent("navigation.eSteem.Editor", () => Editor); "navigation.eSteem.Home",
Navigation.registerComponent("navigation.eSteem.Discover", () => Discover); () => Home,
Navigation.registerComponent("navigation.eSteem.Settings", () => Settings); Provider,
Navigation.registerComponent( 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", "navigation.eSteem.Notifications",
() => Notifications () => Notifications,
Provider,
store
); );
Navigation.registerComponent( Navigation.registerComponentWithRedux(
"navigation.eSteem.SideMenuScreen", "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 = { module.exports = {

View File

@ -22,6 +22,7 @@ import {
Thumbnail, Thumbnail,
} from "native-base"; } from "native-base";
import { Navigation } from "react-native-navigation"; import { Navigation } from "react-native-navigation";
import { connect } from "react-redux";
import { Login } from "../../providers/steem/auth"; import { Login } from "../../providers/steem/auth";
import RNRestart from "react-native-restart"; import RNRestart from "react-native-restart";
@ -38,6 +39,10 @@ class LoginPage extends Component {
}; };
} }
componentDidMount() {
console.log("=================test", this.props.account);
}
doLogin = () => { doLogin = () => {
const { componentId } = this.props; const { componentId } = this.props;
@ -349,4 +354,9 @@ const styles = StyleSheet.create({
flexDirection: "row", flexDirection: "row",
}, },
}); });
export default LoginPage;
const mapStateToProps = state => ({
account: state.accounts,
});
export default connect(mapStateToProps)(LoginPage);

2164
yarn.lock

File diff suppressed because it is too large Load Diff