<commit_before>import * as types from './actionTypes';
import FlibooksAPI from '../api/flibooksApi';
import {beginAjaxCall, ajaxCallError} from './ajaxStatusActions';

export function searchAuthorsSuccess(term, authors) {
    return { type: types.SEARCH_AUTHORS_SUCCESS, authors: {term, authors} };
}

export function getAuthorSuccess(author) {
    return { type: types.GET_AUTHOR_SUCCESS, author };
}

export function getAuthorBooksSuccess(books) {
    return { type: types.GET_AUTHOR_BOOKS_SUCCESS, books };
}

export function getLangsSuccess(langs) {
    return { type: types.GET_LANGS_SUCCESS, langs };
}

export function saveSelectedLangsSuccess(selectedLangs) {
    return { type: types.SAVE_SELECTED_LANGS_DONE, selectedLangs };
}

export function saveNoDeletedSuccess(noDeleted) {
    return { type: types.SAVE_NO_DELETED_DONE, noDeleted };
}

export function getOptionsSuccess() {
    return { type: types.GET_OPTIONS_DONE };
}

export function searchBooksSuccess(title, author, books) {
    return { type: types.SEARCH_BOOKS_SUCCESS, books: {title, author, books} };
}

export function getBooksSuccess(book) {
    return { type: types.GET_BOOK_SUCCESS, book};
}

export function searchBooksByIdSuccess(idBooks) {
    return { type: types.SEARCH_BOOKS_BY_ID_SUCCESS, books: {idBooks}};
}

export function searchAuthors(term) {
    return (dispatch) => {
        dispatch(beginAjaxCall());
        return FlibooksAPI.searchForAuthors(term).then(authors => {
            dispatch(searchAuthorsSuccess(term, authors));
        }).catch(error => {
            dispatch(ajaxCallError(error));
            throw (error);
        });
    };
}

export function getAuthor(id) {
    return (dispatch) => {
        dispatch(beginAjaxCall());
        return FlibooksAPI.getAuthor(id).then(author => {
            dispatch(getAuthorSuccess(author));
        }).catch(error => {
            dispatch(ajaxCallError(error));
            throw (error);
        });
    };
}

export function getAuthorBooks(id) {
    return (dispatch, getState) => {
        dispatch(beginAjaxCall());

        const langs = getState().options.selectedLangs;
        const deleted = !getState().options.noDeleted;
        return FlibooksAPI.getAuthorBooks(id, deleted, langs).then(books => {
            dispatch(getAuthorBooksSuccess(books));
        }).catch(error => {
            dispatch(ajaxCallError(error));
            throw (error);
        });
    };
}

export function searchBooks(title, author) {
    return (dispatch, getState) => {
        dispatch(beginAjaxCall());

        const langs = getState().options.selectedLangs;
        const deleted = !getState().options.noDeleted;
        return FlibooksAPI.searchForBooks(title, author, 20, deleted, langs).then(books => {
            dispatch(searchBooksSuccess(title, author, books));
        }).catch(error => {
            dispatch(ajaxCallError(error));<commit_msg>Cleanup previous author's books list first.<commit_after>import * as types from './actionTypes';
import FlibooksAPI from '../api/flibooksApi';
import {beginAjaxCall, ajaxCallError} from './ajaxStatusActions';

export function searchAuthorsSuccess(term, authors) {
    return { type: types.SEARCH_AUTHORS_SUCCESS, authors: {term, authors} };
}

export function getAuthorSuccess(author) {
    return { type: types.GET_AUTHOR_SUCCESS, author };
}

export function getAuthorBooksSuccess(books) {
    return { type: types.GET_AUTHOR_BOOKS_SUCCESS, books };
}

export function getLangsSuccess(langs) {
    return { type: types.GET_LANGS_SUCCESS, langs };
}

export function saveSelectedLangsSuccess(selectedLangs) {
    return { type: types.SAVE_SELECTED_LANGS_DONE, selectedLangs };
}

export function saveNoDeletedSuccess(noDeleted) {
    return { type: types.SAVE_NO_DELETED_DONE, noDeleted };
}

export function getOptionsSuccess() {
    return { type: types.GET_OPTIONS_DONE };
}

export function searchBooksSuccess(title, author, books) {
    return { type: types.SEARCH_BOOKS_SUCCESS, books: {title, author, books} };
}

export function getBooksSuccess(book) {
    return { type: types.GET_BOOK_SUCCESS, book};
}

export function searchBooksByIdSuccess(idBooks) {
    return { type: types.SEARCH_BOOKS_BY_ID_SUCCESS, books: {idBooks}};
}

export function searchAuthors(term) {
    return (dispatch) => {
        dispatch(beginAjaxCall());
        return FlibooksAPI.searchForAuthors(term).then(authors => {
            dispatch(searchAuthorsSuccess(term, authors));
        }).catch(error => {
            dispatch(ajaxCallError(error));
            throw (error);
        });
    };
}

export function getAuthor(id) {
    return (dispatch) => {
        dispatch(beginAjaxCall());
        return FlibooksAPI.getAuthor(id).then(author => {
            dispatch(getAuthorSuccess(author));
        }).catch(error => {
            dispatch(ajaxCallError(error));
            throw (error);
        });
    };
}

export function getAuthorBooks(id) {
    return (dispatch, getState) => {
        dispatch(getAuthorBooksSuccess([]));
        dispatch(beginAjaxCall());

        const langs = getState().options.selectedLangs;
        const deleted = !getState().options.noDeleted;
        return FlibooksAPI.getAuthorBooks(id, deleted, langs).then(books => {
            dispatch(getAuthorBooksSuccess(books));
        }).catch(error => {
            dispatch(ajaxCallError(error));
            throw (error);
        });
    };
}

export function searchBooks(title, author) {
    return (dispatch, getState) => {
        dispatch(beginAjaxCall());

        const langs = getState().options.selectedLangs;
        const deleted = !getState().options.noDeleted;
        return FlibooksAPI.searchForBooks(title, author, 20, deleted, langs).then(books => {
            dispatch(searchBooksSuccess(title, author, books));
        }).catch(error => {
            dispatch(ajaxCallError(error));
{'fraction_non_alphanumeric': 0.1220505856391105, 'fraction_numerical': 0.0006790018672551349, 'mean_word_length': 3.47040971168437, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, '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': '6790818', 'n_tokens_mistral': 1746, 'n_tokens_neox': 1713, 'n_words': 337}