<commit_before>import objectAssign from 'object-assign';
import {actions as mappingActions} from './mapping';
import {routerActions} from 'react-router-redux'
import {predicateBy} from '../../utils/stringHelper';
import kdbush from 'kdbush';



//TYPES
export const types = {
    SET_POIS: 'STADTPLAN/SET_POIS',
    SET_FILTERED_POIS: 'STADTPLAN/SET_FILTERED_POIS',
    SET_TYPES: 'STADTPLAN/SET_TYPES',
    SET_LEBENSLAGEN: 'STADTPLAN/SET_LEBENSLAGEN',
}


export const constants = {
    DEBUG_ALWAYS_LOADING: true
}


///INITIAL STATE
const initialState = {
    pois: [],
    poisMD5: "",
    filteredPois: [],
    filteredPoisIndex: null,
    lebenslagen: [],
    poitypes: [],

}
///REDUCER
export default function ehrenamtReducer(state = initialState, action) {
    let newState;
    switch (action.type) {
        case types.SET_POIS:
        {
            newState = objectAssign({}, state);
            newState.pois=action.pois;
            newState.poisMD5=action.poisMD5;
            return newState;
        }
        case types.SET_FILTERED_POIS:
        {
            newState = objectAssign({}, state);
            newState.filteredPois=action.filteredPois;
            newState.filteredPoisIndex=kdbush(action.filteredPois, (p)=>p.geojson.coordinates[0], (p) => p.geojson.coordinates[1]);
            return newState;
        }
        case types.SET_TYPES:
        {
            newState = objectAssign({}, state);
            newState.poitypes=action.poitypes;
            return newState;
        }
        case types.SET_LEBENSLAGEN:
        {
            newState = objectAssign({}, state);
            newState.lebenslagen=action.lebenslagen;
            return newState;
        }
        default:
            return state;
    }
}

///SIMPLEACTIONCREATORS
function setPOIs(pois,poisMD5) {
    return {type: types.SET_POIS, pois, poisMD5};
}
function setFilteredPOIs(filteredPois) {
    return {type: types.SET_FILTERED_POIS, filteredPois};
}
function setTypes(poitypes) {
    return {type: types.SET_TYPES, poitypes};
}
function setLebenslagen(lebenslagen) {
    return {type: types.SET_LEBENSLAGEN, lebenslagen};
}


//COMPLEXACTIONS

function loadPOIs() {
    return (dispatch, getState) => {
        let md5 = null;
        let currentPOI=null;
        const state = getState();
        let noCacheHeaders = new Headers();
        noCacheHeaders.append('pragma', 'no-cache');
        noCacheHeaders.append('cache-control', 'no-cache');

        return fetch('/pois/poi.data.json.md5', {method: 'get', headers: noCacheHeaders}).then((response) => {
            if (response.ok) {
                return response.text();
            } else {
                throw new Error('Server md5 response wasn\'t OK');
            }
        }).then((md5value) => {
            md5 = md5value.trim();
            if (md5 === state.stadtplan.poisMD5 && constants.DEBUG_ALWAYS_LOADING===false) {
                // dispatch(applyFilter());
                // dispatch(createFeatureCollectionFromOffers());
    
                throw 'CACHEHIT';
            } else {
                return "fetchit";
            }
        }).then((fetchit) => {
            return fetch('/pois/poi.data.json', {method: 'get', headers: noCacheHeaders});
        }).then((response) => {
            if (response.ok) {
                return response.json();
            } else {<commit_msg>:sparkles: working on #18: enabling the caching of the poi datatset<commit_after>import objectAssign from 'object-assign';
import {actions as mappingActions} from './mapping';
import {routerActions} from 'react-router-redux'
import {predicateBy} from '../../utils/stringHelper';
import kdbush from 'kdbush';



//TYPES
export const types = {
    SET_POIS: 'STADTPLAN/SET_POIS',
    SET_FILTERED_POIS: 'STADTPLAN/SET_FILTERED_POIS',
    SET_TYPES: 'STADTPLAN/SET_TYPES',
    SET_LEBENSLAGEN: 'STADTPLAN/SET_LEBENSLAGEN',
}


export const constants = {
    DEBUG_ALWAYS_LOADING: false
}


///INITIAL STATE
const initialState = {
    pois: [],
    poisMD5: "",
    filteredPois: [],
    filteredPoisIndex: null,
    lebenslagen: [],
    poitypes: [],

}
///REDUCER
export default function ehrenamtReducer(state = initialState, action) {
    let newState;
    switch (action.type) {
        case types.SET_POIS:
        {
            newState = objectAssign({}, state);
            newState.pois=action.pois;
            newState.poisMD5=action.poisMD5;
            return newState;
        }
        case types.SET_FILTERED_POIS:
        {
            newState = objectAssign({}, state);
            newState.filteredPois=action.filteredPois;
            newState.filteredPoisIndex=kdbush(action.filteredPois, (p)=>p.geojson.coordinates[0], (p) => p.geojson.coordinates[1]);
            return newState;
        }
        case types.SET_TYPES:
        {
            newState = objectAssign({}, state);
            newState.poitypes=action.poitypes;
            return newState;
        }
        case types.SET_LEBENSLAGEN:
        {
            newState = objectAssign({}, state);
            newState.lebenslagen=action.lebenslagen;
            return newState;
        }
        default:
            return state;
    }
}

///SIMPLEACTIONCREATORS
function setPOIs(pois,poisMD5) {
    return {type: types.SET_POIS, pois, poisMD5};
}
function setFilteredPOIs(filteredPois) {
    return {type: types.SET_FILTERED_POIS, filteredPois};
}
function setTypes(poitypes) {
    return {type: types.SET_TYPES, poitypes};
}
function setLebenslagen(lebenslagen) {
    return {type: types.SET_LEBENSLAGEN, lebenslagen};
}


//COMPLEXACTIONS

function loadPOIs() {
    return (dispatch, getState) => {
        let md5 = null;
        let currentPOI=null;
        const state = getState();
        let noCacheHeaders = new Headers();
        noCacheHeaders.append('pragma', 'no-cache');
        noCacheHeaders.append('cache-control', 'no-cache');

        return fetch('/pois/poi.data.json.md5', {method: 'get', headers: noCacheHeaders}).then((response) => {
            if (response.ok) {
                return response.text();
            } else {
                throw new Error('Server md5 response wasn\'t OK');
            }
        }).then((md5value) => {
            md5 = md5value.trim();
            if (md5 === state.stadtplan.poisMD5 && (constants.DEBUG_ALWAYS_LOADING===false)) {
                dispatch(applyFilter());
                dispatch(createFeatureCollectionFromPOIs());
                throw 'CACHEHIT';
            } else {
                return "fetchit";
            }
        }).then((fetchit) => {
            return fetch('/pois/poi.data.json', {method: 'get', headers: noCacheHeaders});
        }).then((response) => {
            if (response.ok) {
                return response.json();
            } else {
{'fraction_non_alphanumeric': 0.12599118942731277, 'fraction_numerical': 0.004698972099853157, 'mean_word_length': 2.280828516377649, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '7034417', 'n_tokens_mistral': 2167, 'n_tokens_neox': 2143, 'n_words': 398}