Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Action, Reducer } from 'redux'
- import fire from '../services/firebasecred'
- import { AppThunkAction } from '../store'
- export interface LoginState {
- isLoggedIn: boolean;
- processingLogin: boolean;
- }
- export const initialState: LoginState = {
- isLoggedIn: false,
- processingLogin: false
- }
- export enum LoginActionTypes {
- Login = 'LOGIN',
- LoggedIn = 'LOGGED_IN',
- }
- export interface LoginAction extends Action { payload: {}; type: LoginActionTypes.Login; }
- export interface LoggedinAction extends Action { payload: { loginname: String }; type: LoginActionTypes.LoggedIn; }
- export type KnownAction = LoginAction | LoggedinAction;
- export interface LoginReducer<T> extends Reducer<T> {
- (State: LoginState, Action: LoginAction): LoginState
- }
- export const actionCreators = {
- login: (username: string, password: string): AppThunkAction<KnownAction> => (dispatch, getState) => {
- // login code but not executed for some reason
- }
- }
- const loginReducer: LoginReducer<LoginState> = (state: LoginState = initialState, action: KnownAction):
- LoginState => {
- switch (action.type) {
- case LoginActionTypes.Login:
- {
- var x = 0;
- }
- break;
- case LoginActionTypes.LoggedIn:
- {
- var x = 0;
- }
- break;
- }
- return state;
- }
- export default loginReducer
- import { connect, Dispatch } from 'react-redux'
- import { RootState } from '../store'
- import * as Login from '../reducers/login'
- import NavMenu, { OwnProps } from '../components/NavMenu'
- interface StateProps {
- loggedIn: boolean
- // isLoggingIn: boolean
- }
- interface AntiStateProps {
- }
- interface DispatchProps {
- login: (username: string, password: string) => void
- }
- const mapStateToProps = (state: RootState): StateProps => {
- return ({ loggedIn: state.login.isLoggedIn });
- }
- const mapDispatchToProps = (dispatch: Dispatch<DispatchProps>): DispatchProps => {
- return ({
- login: Login.actionCreators.login
- })
- }
- export default connect<StateProps, DispatchProps, OwnProps | AntiStateProps>(mapStateToProps, mapDispatchToProps)(NavMenu)
- import * as React from 'react';
- import AppBar from 'material-ui/AppBar'
- import FlatButton from 'material-ui/FlatButton';
- import rootStore from '../store';
- import { connect } from 'react-redux';
- import { RootState } from '../store';
- import * as LoginStore from '../reducers/login';
- export interface OwnProps {
- loggedIn: boolean,
- login: (username: string, password: string) => void;
- }
- interface OwnState {
- // isLoggedIn: boolean
- }
- export default class NavMenu extends React.Component<OwnProps, OwnState>
- {
- // private onLogin: (username: string, password: string) => void
- public constructor(props: OwnProps) {
- super(props);
- // this.onLogin = (username: string, password: string) => props.login(username, password);
- }
- public render() {
- return <div>
- <AppBar title="LOL" zDepth={0}>
- </AppBar>
- <FlatButton label="LOGIN" onClick={this.login.bind(this)} />
- </div>;
- }
- login(){
- this.props.login("username", "password");
- }
- }
- import { combineReducers, createStore, applyMiddleware, Reducer } from 'redux'
- import calenderReducer, { CalenderState } from './reducers/calender'
- import countReducer, { CountState } from './reducers/count'
- import createBrowserHistory from 'history/createBrowserHistory'
- import loginReducer, { LoginState } from './reducers/login'
- import { routerReducer, RouterState, routerMiddleware } from 'react-router-redux'
- import thunk from 'redux-thunk';
- export const history = createBrowserHistory()
- const middleware = routerMiddleware(history)
- export interface RootState {
- calender : CalenderState,
- count : CountState,
- routing : RouterState,
- login : LoginState,
- }
- const rootReducer = combineReducers({
- calender : calenderReducer,
- count : countReducer,
- routing : routerReducer as Reducer<RouterState>,
- login : loginReducer,
- })
- const rootStore = createStore(
- rootReducer,
- applyMiddleware(thunk, middleware),
- )
- // This type can be used as a hint on action creators so that its 'dispatch' and 'getState' params are
- // correctly typed to match your store.
- export interface AppThunkAction<TAction> {
- (dispatch: (action: TAction) => void, getState: () => RootState): void;
- }
- export default rootStore
Add Comment
Please, Sign In to add comment