<commit_before>// Reducer
var accounts = undefined;
var account = undefined;

function app(state, action) {
    var newState = undefined;
    switch (action.type) {
        case 'GET_ACCOUNTS':
            accounts = action.payload;
            var stateAccounts = JSON.parse(JSON.stringify(action.payload))
            stateAccounts.liabilities = stateAccounts.liabilities
                .filter(x => !x.hidden && x.type !== 'grouped');
            stateAccounts.selectedMenuIndex = localStorage && localStorage.getItem('selectedTab') || 0;
            newState = stateAccounts;
            break;
        case 'MENU_SELECT':
            localStorage.setItem('selectedTab', action.payload);
            const selectedMenuIndex = action.payload;
            newState = Object.assign({}, state, {selectedMenuIndex});
            break;
        case 'SELECT_ACCOUNT_CLICK':
            newState = Object.assign({}, state, {});
            newState.liabilities.forEach(liab => {
                if(liab.title === action.payload.title){
                    liab.selected = !liab.selected;
                }
            });
            break;
        case 'GROUP_CLICK':
            newState = JSON.parse(JSON.stringify(state));
            const group = (newState.liabilities.filter(x => x.title === action.payload.title)||[])[0];
            newState.liabilities = newState.liabilities.filter(x => x.type !== 'grouped');
            if(group.open){
                group.open = false;
            } else {
                const groupedItems = group.items
                    .map(item => (accounts.liabilities.filter(x => x.title === item.title)||[])[0]);
                var newLiabs = [];
                newState.liabilities.forEach(item => {
                    newLiabs.push(item);
                    if(item.title === action.payload.title){
                        newLiabs = newLiabs.concat(groupedItems);
                        item.open = true;
                    }
                });
                newState.liabilities = newLiabs;
            }
            debugger;
            console.log('should insert inline grouped items here');
            break;
        case 'GROUP_REMOVE':
            console.log('Remove group here: ', account.title);

            break;
        case 'ACCOUNT_SAVE':
            console.log('Save account here: ', account.title);
            account=undefined;
            break;
        }
        
    return newState || state || {};
}

function popup(state, action) {
    var newState = undefined;

    switch (action.type) {
        case 'POPUP_ACCOUNT':
            account = accounts.liabilities
                .filter(a => a.title.toLowerCase() === action.payload.title.toLowerCase());
            account = account[0];
            newState = Object.assign({}, state, {
                error: account ? false : 'could not find account',
                account: JSON.parse(JSON.stringify(account || false))<commit_msg>sort by status first and date second<commit_after>// Reducer
var accounts = undefined;
var account = undefined;

function app(state, action) {
    var newState = undefined;
    switch (action.type) {
        case 'GET_ACCOUNTS':
            accounts = action.payload;
            var stateAccounts = JSON.parse(JSON.stringify(action.payload))
            stateAccounts.liabilities = stateAccounts.liabilities
                .filter(x => !x.hidden && x.type !== 'grouped');
            stateAccounts.selectedMenuIndex = localStorage && localStorage.getItem('selectedTab') || 0;
            newState = stateAccounts;
            break;
        case 'MENU_SELECT':
            localStorage.setItem('selectedTab', action.payload);
            const selectedMenuIndex = action.payload;
            newState = Object.assign({}, state, {selectedMenuIndex});
            break;
        case 'SELECT_ACCOUNT_CLICK':
            newState = Object.assign({}, state, {});
            newState.liabilities.forEach(liab => {
                if(liab.title === action.payload.title){
                    liab.selected = !liab.selected;
                }
            });
            break;
        case 'GROUP_CLICK':
            newState = JSON.parse(JSON.stringify(state));
            const group = (newState.liabilities.filter(x => x.title === action.payload.title)||[])[0];
            newState.liabilities = newState.liabilities.filter(x => x.type !== 'grouped');
            if(group.open){
                group.open = false;
                break;
            } 
            
            const statToNumber = {
                due: 0,
                pending: 1,
                paid: 2
            };
            const groupedItems = group.items
                .map(item => (accounts.liabilities.filter(x => x.title === item.title)||[])[0])
                .sort(function (a, b) {
                    var statCompare = 0;
                    if (statToNumber[a.status] > statToNumber[b.status]) statCompare = 1;
                    if (statToNumber[a.status] < statToNumber[b.status]) statCompare = -1;
                
                    return statCompare || new Date(a.date) - new Date(b.date);
                });
            var newLiabs = [];
            newState.liabilities.forEach(item => {
                newLiabs.push(item);
                if(item.title === action.payload.title){
                    newLiabs = newLiabs.concat(groupedItems);
                    item.open = true;
                }
            });
            newState.liabilities = newLiabs;
            break;
        case 'GROUP_REMOVE':
            console.log('Remove group here: ', account.title);

            break;
        case 'ACCOUNT_SAVE':
            console.log('Save account here: ', account.title);
            account=undefined;
            break;
        }
        
    return newState || state || {};
}

function popup(state, action) {
    var newState = undefined;

    switch (action.type) {
        case 'POPUP_ACCOUNT':
            account = accounts.liabilities
                .filter(a => a.title.toLowerCase() === action.payload.title.toLowerCase());
            account = account[0];
            newState = Object.assign({}, state, {
                error: account ? false : 'could not find account',
                account: JSON.parse(JSON.stringify(account || false))
{'fraction_non_alphanumeric': 0.12046672973825291, 'fraction_numerical': 0.002207505518763797, 'mean_word_length': 1.6484342379958246, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 20, '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': '6510063', 'n_tokens_mistral': 1673, 'n_tokens_neox': 1618, 'n_words': 330}