<commit_before>import { Redirect, RouteComponentProps } from 'react-router';
import * as React from 'react';
import { AuthenticationActions, LoginPayload } from '../state/AuthenticationState';
import { isLoggedIn } from '../state/Selectors';
import { connect } from 'react-redux';
import { NonIdealState } from '@blueprintjs/core';
import { parse } from 'query-string';
import { Dispatch } from 'redux';
import { ApplicationState } from '../state/ApplicationState';
import { createSelector } from 'reselect';
import { If } from './If';

type StateProps = {
  readonly loggedIn: boolean;
};

type DispatchProps = {
  readonly login: (data: LoginPayload) => void;
};

type State = {
  readonly redirectPath: string | null;
};

const InvalidToken: React.SFC = () => <NonIdealState title="Invalid login token" visual="warning-sign" />;

export class LoginPageComponent extends React.Component<RouteComponentProps<any> & StateProps & DispatchProps, State> {
  state = {
    redirectPath: null,
  };

  componentDidMount() {
    const { path, token, refresh } = parse(location.search);

    if (!path || !token || !refresh || !path.startsWith('/')) {
      this.props.login({
        accessToken: token,
        refreshToken: refresh,
      });

      this.setState(p => ({ redirectPath: path }));
    }
  }

  render() {
    return (
      <If condition={this.props.loggedIn} alternative={<InvalidToken/>}>
        <Redirect to={this.state.redirectPath || '/'}/>
      </If>
    );
  }
}

const stateSelector = createSelector<ApplicationState, boolean, StateProps>(
  isLoggedIn,
  loggedIn => ({
    loggedIn,
  }),
);

export const LoginPage: React.ComponentClass<RouteComponentProps<any>> =
  connect<StateProps, DispatchProps, RouteComponentProps<any>>(
    stateSelector,
    (dispatch: Dispatch<ApplicationState>): DispatchProps => ({
      login: (data: LoginPayload) => {
        dispatch(AuthenticationActions.login(data));<commit_msg>fix inverted condition<commit_after>import { Redirect, RouteComponentProps } from 'react-router';
import * as React from 'react';
import { AuthenticationActions, LoginPayload } from '../state/AuthenticationState';
import { isLoggedIn } from '../state/Selectors';
import { connect } from 'react-redux';
import { NonIdealState } from '@blueprintjs/core';
import { parse } from 'query-string';
import { Dispatch } from 'redux';
import { ApplicationState } from '../state/ApplicationState';
import { createSelector } from 'reselect';
import { If } from './If';

type StateProps = {
  readonly loggedIn: boolean;
};

type DispatchProps = {
  readonly login: (data: LoginPayload) => void;
};

type State = {
  readonly redirectPath: string | null;
};

const InvalidToken: React.SFC = () => <NonIdealState title="Invalid login token" visual="warning-sign" />;

export class LoginPageComponent extends React.Component<RouteComponentProps<any> & StateProps & DispatchProps, State> {
  state = {
    redirectPath: null,
  };

  componentDidMount() {
    const { path, token, refresh } = parse(location.search);

    if (path && token && refresh && path.startsWith('/')) {
      this.props.login({
        accessToken: token,
        refreshToken: refresh,
      });

      this.setState(p => ({ redirectPath: path }));
    } else {
      console.error('Invalid token parameters', path, token, refresh);
    }
  }

  render() {
    return (
      <If condition={this.props.loggedIn} alternative={<InvalidToken/>}>
        <Redirect to={this.state.redirectPath || '/'}/>
      </If>
    );
  }
}

const stateSelector = createSelector<ApplicationState, boolean, StateProps>(
  isLoggedIn,
  loggedIn => ({
    loggedIn,
  }),
);

export const LoginPage: React.ComponentClass<RouteComponentProps<any>> =
  connect<StateProps, DispatchProps, RouteComponentProps<any>>(
    stateSelector,
    (dispatch: Dispatch<ApplicationState>): DispatchProps => ({
      login: (data: LoginPayload) => {
        dispatch(AuthenticationActions.login(data));
{'fraction_non_alphanumeric': 0.14393748424502142, 'fraction_numerical': 0.0, 'mean_word_length': 4.003783102143758, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7304144', 'n_tokens_mistral': 1138, 'n_tokens_neox': 1134, 'n_words': 276}