<commit_before>import {
  REGISTER_START, REGISTER_COMPLETE,
  LOGIN_START, LOGIN_COMPLETE, SET_TOKEN,
  LOGOUT_START, LOGOUT_COMPLETE
} from '../constants/actionTypes/auth';
import { LOAD_ALL_PLAYLISTS_START } from '../constants/actionTypes/playlists';
import { get, post } from '../utils/Request';
import * as Session from '../utils/Session';
import * as Socket from '../utils/Socket';
import { advance, loadHistory } from './BoothActionCreators';
import {
  setPlaylists, selectPlaylist, activatePlaylistComplete
} from './PlaylistActionCreators';
import { closeLoginDialog } from './DialogActionCreators';
import { setUsers } from './UserActionCreators';
import { currentUserSelector, tokenSelector } from '../selectors/userSelectors';

const debug = require('debug')('uwave:actions:login');

export function loginComplete({ jwt, user }) {
  Socket.auth(jwt);
  return dispatch => {
    dispatch({
      type: LOGIN_COMPLETE,
      payload: { jwt, user }
    });
    dispatch(closeLoginDialog());
  };
}

export function loadedState(state) {
  return (dispatch, getState) => {
    dispatch(setUsers(state.users || []));
    dispatch(setPlaylists(state.playlists || []));
    if (state.booth) {
      // TODO don't set this when logging in _after_ entering the page?
      dispatch(advance(state.booth));
    }
    if (state.user) {
      const token = tokenSelector(getState());
      dispatch(loginComplete({<commit_msg>waitlist: initialise WL state on load<commit_after>import {
  REGISTER_START, REGISTER_COMPLETE,
  LOGIN_START, LOGIN_COMPLETE, SET_TOKEN,
  LOGOUT_START, LOGOUT_COMPLETE
} from '../constants/actionTypes/auth';
import { LOAD_ALL_PLAYLISTS_START } from '../constants/actionTypes/playlists';
import { get, post } from '../utils/Request';
import * as Session from '../utils/Session';
import * as Socket from '../utils/Socket';
import { advance, loadHistory } from './BoothActionCreators';
import {
  setPlaylists, selectPlaylist, activatePlaylistComplete
} from './PlaylistActionCreators';
import { closeLoginDialog } from './DialogActionCreators';
import { setUsers } from './UserActionCreators';
import { setWaitList } from './WaitlistActionCreators';
import { currentUserSelector, tokenSelector } from '../selectors/userSelectors';

const debug = require('debug')('uwave:actions:login');

export function loginComplete({ jwt, user }) {
  Socket.auth(jwt);
  return dispatch => {
    dispatch({
      type: LOGIN_COMPLETE,
      payload: { jwt, user }
    });
    dispatch(closeLoginDialog());
  };
}

export function loadedState(state) {
  return (dispatch, getState) => {
    dispatch(setUsers(state.users || []));
    dispatch(setPlaylists(state.playlists || []));
    dispatch(setWaitList({
      waitlist: state.waitlist,
      locked: state.waitlistLocked
    }));
    if (state.booth) {
      // TODO don't set this when logging in _after_ entering the page?
      dispatch(advance(state.booth));
    }
    if (state.user) {
      const token = tokenSelector(getState());
      dispatch(loginComplete({
{'fraction_non_alphanumeric': 0.13649851632047477, 'fraction_numerical': 0.0, 'mean_word_length': 4.267361111111111, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '910223', 'n_tokens_mistral': 891, 'n_tokens_neox': 901, 'n_words': 211}