<commit_before>// imports

// actions

// action creators

// API actions

function facebookLogin(access_token){
    return dispatch => {
        fetch('/users/login/facebook/',{
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify({
                access_token
            })
        })
    .then(response => response.json())
    .then(json => console.log(json)) 
    .catch(err => console.log(err));
    }
}

// initial state
const initialState = {
    isLoggedIn: localStorage.getItem('jwt') || false
}

// reducer

function reducer(state = initialState, action) {
    switch(action.type){
        default: 
            return state;
    }
}

// reducer functions

// exports

const actionCreators ={
    facebookLogin
}

export { actionCreators };

//reducer export

export default reducer;<commit_msg>Setting the Token with FB Login<commit_after>// imports

// actions

const SAVE_TOKEN = 'SAVE_TOKEN';

// action creators

function saveToken(token){
    return {
        type: SAVE_TOKEN,
        token
    }
}

// API actions

function facebookLogin(access_token){
    return dispatch => {
        fetch('/users/login/facebook/',{
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify({
                access_token
            })
        })
    .then(response => response.json())
    .then(json => {
        if(json.token){
            localStorage.setItem('jwt', json.token)
            dispatch(saveToken(json.token));
        }
    }) 
    .catch(err => console.log(err));
    }
}

// initial state

const initialState = {
    isLoggedIn: localStorage.getItem('jwt') || false
}

// reducer

function reducer(state = initialState, action) {
    switch(action.type){
        case SAVE_TOKEN:
            return applySetToken(state, action);
        default: 
            return state;
    }
}

// reducer functions

function applySetToken(state, action){
    const { token } = action;
    return {
        ...state, 
        isLoggedIn: true,
        token
    }
}

// exports

const actionCreators ={
    facebookLogin
}

export { actionCreators };

//reducer export

export default reducer;
{'fraction_non_alphanumeric': 0.12418300653594772, 'fraction_numerical': 0.0, 'mean_word_length': 1.9664082687338502, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '2957237', 'n_tokens_mistral': 678, 'n_tokens_neox': 666, 'n_words': 142}