<commit_before>import * as api from '../api';

export function deleteAddon(addonId) {
    return function(dispatch, getState) {
        const projectId = getState().project.get('id');
        dispatch(deletingAddon(addonId));
        if (addonId < 0) {
            dispatch(deletedAddon(addonId));
        } else {
            return api.delet(`/projects/${projectId}/integrations/${addonId}`)
                .then(resp => {
                    dispatch(deletedAddon(addonId));
                }, resp => {
                    throw new Error(`Failed to delete addon #${addonId}`);
                });
        }
    }
}

export function deletingAddon(id) {
    return {
        type: 'DELETING_ADDON',
        id
    }
}

export function deletedAddon(id) {
    return {
        type: 'DELETED_ADDON',
        id
    }
}

export function newAddon(kind) {
    const id = (+new Date()) * -1;
    return {
        type: 'NEW_ADDON',
        kind,
        id
    }
}

export function fetchAddons() {
    function shouldFetch(state) {
        let isFetching = state.addons.get('isFetching');
        let itemCount = state.addons.get('items').size;
        if (!isFetching && itemCount === 0) {
            return true;
        } else {
            return false;
        }
    }
  
    return function(dispatch, getState) {
        const state = getState();
        const projectId = state.project.get('id');
        if (shouldFetch(state)) {
            dispatch(fetchingAddons());
            return api.get(`/projects/${projectId}/addons`)
                .then(resp => {
                    dispatch(receivedAddons(resp.addon));
                }, resp => {
                    throw new Error('Failed to fetch project addons.');
                });
        } else {
          return Promise.resolve();
        }
    }
}

export function fetchingAddons() {
    return {
        type: 'FETCHING_ADDONS'
    }
}

export function receivedAddons(addons) {
    return {
        type: 'RECEIVED_ADDONS',
        items: addons
    }
}

export function saveAddon(id, kind, data) {
    return function(dispatch, getState) {
        const state = getState();
        const projectId = state.project.get('id');
        const body = JSON.stringify({
            kind,
            data
        });
        let push;
        
        if (id < 0) {
            push = api.post(`/projects/${projectId}/integrations`, {
                body
            });
        } else {
            push = api.patch(`/projects/${projectId}/integrations/${id}`, {
                body
            });
        }

        return push.then(resp => {
            dispatch(changedAddon(resp.addon, id));
        }, resp => {
            throw new Error(`Failed to save addon ${kind} #${id}.`)
        });
  }
}

export function changedAddon(addon, prevId) {
    return {
        type: 'CHANGED_ADDON',
        addon,
        prevId
    }
}<commit_msg>always fetch addons for now<commit_after>import * as api from '../api';

export function deleteAddon(addonId) {
    return function(dispatch, getState) {
        const projectId = getState().project.get('id');
        dispatch(deletingAddon(addonId));
        if (addonId < 0) {
            dispatch(deletedAddon(addonId));
        } else {
            return api.delet(`/projects/${projectId}/integrations/${addonId}`)
                .then(resp => {
                    dispatch(deletedAddon(addonId));
                }, resp => {
                    throw new Error(`Failed to delete addon #${addonId}`);
                });
        }
    }
}

export function deletingAddon(id) {
    return {
        type: 'DELETING_ADDON',
        id
    }
}

export function deletedAddon(id) {
    return {
        type: 'DELETED_ADDON',
        id
    }
}

export function newAddon(kind) {
    const id = (+new Date()) * -1;
    return {
        type: 'NEW_ADDON',
        kind,
        id
    }
}

export function fetchAddons() {
    function shouldFetch(state) {
        return true
    }
  
    return function(dispatch, getState) {
        const state = getState();
        const projectId = state.project.get('id');
        if (shouldFetch(state)) {
            dispatch(fetchingAddons());
            return api.get(`/projects/${projectId}/addons`)
                .then(resp => {
                    dispatch(receivedAddons(resp.addon));
                }, resp => {
                    throw new Error('Failed to fetch project addons.');
                });
        } else {
          return Promise.resolve();
        }
    }
}

export function fetchingAddons() {
    return {
        type: 'FETCHING_ADDONS'
    }
}

export function receivedAddons(addons) {
    return {
        type: 'RECEIVED_ADDONS',
        items: addons
    }
}

export function saveAddon(id, kind, data) {
    return function(dispatch, getState) {
        const state = getState();
        const projectId = state.project.get('id');
        const body = JSON.stringify({
            kind,
            data
        });
        let push;
        
        if (id < 0) {
            push = api.post(`/projects/${projectId}/integrations`, {
                body
            });
        } else {
            push = api.patch(`/projects/${projectId}/integrations/${id}`, {
                body
            });
        }

        return push.then(resp => {
            dispatch(changedAddon(resp.addon, id));
        }, resp => {
            throw new Error(`Failed to save addon ${kind} #${id}.`)
        });
  }
}

export function changedAddon(addon, prevId) {
    return {
        type: 'CHANGED_ADDON',
        addon,
        prevId
    }
}
{'fraction_non_alphanumeric': 0.128223368308732, 'fraction_numerical': 0.001244887070958563, 'mean_word_length': 1.6243583761082594, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, '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': '3389963', 'n_tokens_mistral': 1646, 'n_tokens_neox': 1626, 'n_words': 337}