<commit_before>
'use strict';

import Immutable from 'immutable';

import {
  STOP_TIMER,
  TIMER_STARTED,
  TIMER_UPDATED,
  TIMER_FINISHED,
  TIMER_MAX_VALUE_CHANGED
} from '../actions/timer';

import { CHALLENGE_START } from '../actions/challenge';

import { GAME_DIFFICULTY_CHANGE } from '../actions/gamesetting';

import { SESSION_FINISH } from '../actions/session';

const timerDefaultValue = 60 * 1000;

const initialState = Immutable.Map({
  isTimerFinished: false,
  timerMaxValue: timerDefaultValue,
  timerMaxValueLoaded: timerDefaultValue,
  timeLeft: '01:00', // timerDefaultValue
  timerStart: 0,
  timeUsed: '00:00'
});

export function printTime (timeInMilliseconds) {
  const timeInSeconds = Math.ceil(timeInMilliseconds / 1000);
  const seconds = timeInSeconds % 60;
  const minutes = Math.floor(timeInSeconds / 60);

  const mm = (minutes >= 10) ? `${minutes}` : `0${minutes}`;
  const ss = (seconds >= 10) ? `${seconds}` : `0${seconds}`;

  return `${mm}:${ss}`;
}

const difficultySettings = {
  Easy: { displayTime: '15:00', time: 15 * 60 * 1000 },
  Medium: { displayTime: '10:00', time: 10 * 60 * 1000 },
  Hard: { displayTime: '05:00', time: 5 * 60 * 1000 }
  // Random - for random, can randomly generate lives and time and hide until game start
};

export default function timer (state = initialState, action) {
  switch (action.type) {
    case CHALLENGE_START:
      return state.set('timerMaxValueLoaded', state.get('timerMaxValue'));
    case GAME_DIFFICULTY_CHANGE:
      return state
        .set('timeLeft', difficultySettings[action.difficulty].displayTime) // display
        .set('timerMaxValue', difficultySettings[action.difficulty].time); // actual number
    case SESSION_FINISH:
    case STOP_TIMER:
      return state
        .set('isTimerFinished', true)
        .set('timeLeft', '00:00');
    case TIMER_STARTED:
      return state
        .set('isTimerFinished', false)
        // .set('timeLeft', printTime(state.get('timerMaxValue'))) // timerDefaultValue
        .set('timerStart', action.startTime);
    case TIMER_UPDATED:
      return state
        .set('timeUsed', printTime(action.timeNow - state.get('timerStart')))
        .set('timeLeft', printTime(state.get('timerMaxValue') - (action.timeNow - state.get('timerStart'))));
    case TIMER_FINISHED:
      return state.set('isRunningTests', false);
    case TIMER_MAX_VALUE_CHANGED:
      return state.set('timerMaxValue', action.timerMaxValue);
    default:
      return state;
  }
}
<commit_msg>Added state updates to TIMER_FINISHED.<commit_after>
'use strict';

import Immutable from 'immutable';

import {
  STOP_TIMER,
  TIMER_STARTED,
  TIMER_UPDATED,
  TIMER_FINISHED,
  TIMER_MAX_VALUE_CHANGED
} from '../actions/timer';

import { CHALLENGE_START } from '../actions/challenge';

import { GAME_DIFFICULTY_CHANGE } from '../actions/gamesetting';

import { SESSION_FINISH } from '../actions/session';

const timerDefaultValue = 60 * 1000;

const initialState = Immutable.Map({
  isTimerFinished: false,
  timerMaxValue: timerDefaultValue,
  timerMaxValueLoaded: timerDefaultValue,
  timeLeft: '01:00', // timerDefaultValue
  timerStart: 0,
  timeUsed: '00:00'
});

export function printTime (timeInMilliseconds) {
  const timeInSeconds = Math.ceil(timeInMilliseconds / 1000);
  const seconds = timeInSeconds % 60;
  const minutes = Math.floor(timeInSeconds / 60);

  const mm = (minutes >= 10) ? `${minutes}` : `0${minutes}`;
  const ss = (seconds >= 10) ? `${seconds}` : `0${seconds}`;

  return `${mm}:${ss}`;
}

const difficultySettings = {
  Easy: { displayTime: '15:00', time: 15 * 60 * 1000 },
  Medium: { displayTime: '10:00', time: 10 * 60 * 1000 },
  Hard: { displayTime: '05:00', time: 5 * 60 * 1000 }
  // Random - for random, can randomly generate lives and time and hide until game start
};

export default function timer (state = initialState, action) {
  switch (action.type) {
    case CHALLENGE_START:
      return state.set('timerMaxValueLoaded', state.get('timerMaxValue'));
    case GAME_DIFFICULTY_CHANGE:
      return state
        .set('timeLeft', difficultySettings[action.difficulty].displayTime) // display
        .set('timerMaxValue', difficultySettings[action.difficulty].time); // actual number
    case SESSION_FINISH:
    case STOP_TIMER:
      return state
        .set('isTimerFinished', true)
        .set('timeLeft', '00:00');
    case TIMER_STARTED:
      return state
        .set('isTimerFinished', false)
        // .set('timeLeft', printTime(state.get('timerMaxValue'))) // timerDefaultValue
        .set('timerStart', action.startTime);
    case TIMER_UPDATED:
      return state
        .set('timeUsed', printTime(action.timeNow - state.get('timerStart')))
        .set('timeLeft', printTime(state.get('timerMaxValue') - (action.timeNow - state.get('timerStart'))));
    case TIMER_FINISHED:
      return state
        .set('isTimerFinished', true)
        .set('timeLeft', '00:00');
    case TIMER_MAX_VALUE_CHANGED:
      return state.set('timerMaxValue', action.timerMaxValue);
    default:
      return state;
  }
}

{'fraction_non_alphanumeric': 0.13795821836815136, 'fraction_numerical': 0.027591643673630272, 'mean_word_length': 3.7697368421052633, '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': '3214720', 'n_tokens_mistral': 1755, 'n_tokens_neox': 1618, 'n_words': 375}