<commit_before>import T from "../constants/ActionTypes";
import parseUrl from "../util/parseUrl";
import constructUrl from "../util/constructUrl";
import RoutingUsecases from "../constants/RoutingUsecases";
import Categories from "../constants/Categories";

const initialState = {
  hash: "", 
  routingUsecases: []
};

module.exports = (state=initialState, action={}) => {

  if (action.type == T.UPDATE_STATE_FROM_URL) {
    var params = parseUrl(action.payload).params;
  } else if (state.hash != "") {
    params = parseUrl(state.hash).params;
  }

  if(params){
    // TODO parse Boolean for left?
    var { zoom, entry, search, tags, left, categories, addentry } = params;
    var centerStr = params.center;
    var confirmEmail = params.confirm_email

    var center = centerStr ? {
      lat: parseFloat(centerStr.split(',')[0]),
      lng: parseFloat(centerStr.split(',')[1])
    } : null;
  }

  let routingUsecases = [];

  switch(action.type){
    case T.UPDATE_STATE_FROM_URL:
      if(left){
        routingUsecases.push(RoutingUsecases.CHANGE_SIDEBAR_VISIBILITY);
      }
      if(!params || Object.keys(params).length == 0){
        routingUsecases.push(RoutingUsecases.NO_ROUTING);
      } else if(confirmEmail){
        routingUsecases.push(RoutingUsecases.CONFIRM_EMAIL);
      } else if(entry){ 
        routingUsecases.push(RoutingUsecases.SHOW_ENTRY);
      } else {
        if (centerStr && centerStr.includes(',') && (centerStr.length >= 3)) {
          routingUsecases.push(RoutingUsecases.CHANGE_CENTER);   
        }
        if (search || tags || search == "" || tags == "") {
          routingUsecases.push(RoutingUsecases.CHANGE_SEARCH);
        }
      }
      if (categories) {
        routingUsecases.push(RoutingUsecases.CHANGE_SEARCH_CATEGORIES);
      }
      if (zoom) {
        routingUsecases.push(RoutingUsecases.CHANGE_ZOOM);
      }
      if (addentry) {
        if (addentry === 'event') {
          routingUsecases.push(RoutingUsecases.SHOW_NEW_ENTRY)
        }
      }

      return {
        hash: action.payload,
        routingUsecases: routingUsecases
      };


    case T.SET_SEARCH_TEXT:
      search = action.payload;
      break;

    case T.SET_MAP_CENTER:
      center = center = {
        lat: parseFloat(action.payload.lat),
        lng: parseFloat(action.payload.lng)
      };
      break;

    case T.SET_ZOOM:
      zoom = action.payload;
      break;

    case T.SET_CURRENT_ENTRY:
      entry = action.payload;
      break;

    case T.SET_CENTER_IN_URL:
      center = {<commit_msg>feat: add all kind of categories from all entry direct link<commit_after>import T from "../constants/ActionTypes";
import parseUrl from "../util/parseUrl";
import constructUrl from "../util/constructUrl";
import RoutingUsecases from "../constants/RoutingUsecases";
import Categories from "../constants/Categories";

const initialState = {
  hash: "", 
  routingUsecases: []
};

module.exports = (state=initialState, action={}) => {

  if (action.type == T.UPDATE_STATE_FROM_URL) {
    var params = parseUrl(action.payload).params;
  } else if (state.hash != "") {
    params = parseUrl(state.hash).params;
  }

  if(params){
    // TODO parse Boolean for left?
    var { zoom, entry, search, tags, left, categories, addentry } = params;
    var centerStr = params.center;
    var confirmEmail = params.confirm_email

    var center = centerStr ? {
      lat: parseFloat(centerStr.split(',')[0]),
      lng: parseFloat(centerStr.split(',')[1])
    } : null;
  }

  let routingUsecases = [];

  switch(action.type){
    case T.UPDATE_STATE_FROM_URL:
      if(left){
        routingUsecases.push(RoutingUsecases.CHANGE_SIDEBAR_VISIBILITY);
      }
      if(!params || Object.keys(params).length == 0){
        routingUsecases.push(RoutingUsecases.NO_ROUTING);
      } else if(confirmEmail){
        routingUsecases.push(RoutingUsecases.CONFIRM_EMAIL);
      } else if(entry){ 
        routingUsecases.push(RoutingUsecases.SHOW_ENTRY);
      } else {
        if (centerStr && centerStr.includes(',') && (centerStr.length >= 3)) {
          routingUsecases.push(RoutingUsecases.CHANGE_CENTER);   
        }
        if (search || tags || search == "" || tags == "") {
          routingUsecases.push(RoutingUsecases.CHANGE_SEARCH);
        }
      }
      if (categories) {
        routingUsecases.push(RoutingUsecases.CHANGE_SEARCH_CATEGORIES);
      }
      if (zoom) {
        routingUsecases.push(RoutingUsecases.CHANGE_ZOOM);
      }
      if (addentry) {
        if (Object.keys(Categories.NAMES).filter(c => Categories.NAMES[c] === addentry).length) {
          routingUsecases.push(RoutingUsecases.SHOW_NEW_ENTRY)
        }
      }

      return {
        hash: action.payload,
        routingUsecases: routingUsecases
      };


    case T.SET_SEARCH_TEXT:
      search = action.payload;
      break;

    case T.SET_MAP_CENTER:
      center = center = {
        lat: parseFloat(action.payload.lat),
        lng: parseFloat(action.payload.lng)
      };
      break;

    case T.SET_ZOOM:
      zoom = action.payload;
      break;

    case T.SET_CURRENT_ENTRY:
      entry = action.payload;
      break;

    case T.SET_CENTER_IN_URL:
      center = {
{'fraction_non_alphanumeric': 0.12851096575606002, 'fraction_numerical': 0.0015390534821085034, 'mean_word_length': 2.6820113314447593, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '4583795', 'n_tokens_mistral': 1706, 'n_tokens_neox': 1694, 'n_words': 293}