insomnia/app/redux/modules/requests.js

51 lines
1020 B
JavaScript
Raw Normal View History

import * as network from '../../lib/network'
2016-04-23 06:16:23 +00:00
import {loadStart, loadStop} from './global'
import {show} from './modals'
import {MODAL_REQUEST_RENAME} from '../../lib/constants'
2016-04-23 06:08:52 +00:00
export const REQUEST_CHANGE_FILTER = 'requests/filter';
const initialState = {
filter: ''
};
2016-04-23 06:08:52 +00:00
// ~~~~~~~~ //
// REDUCERS //
// ~~~~~~~~ //
export default function (state = initialState, action) {
2016-04-23 06:08:52 +00:00
switch (action.type) {
2016-04-23 06:08:52 +00:00
case REQUEST_CHANGE_FILTER:
const filter = action.filter;
return Object.assign({}, state, {filter});
2016-04-23 06:08:52 +00:00
default:
return state;
}
}
// ~~~~~~~ //
// ACTIONS //
// ~~~~~~~ //
export function changeFilter (filter) {
return {type: REQUEST_CHANGE_FILTER, filter};
}
export function send (request) {
return dispatch => {
dispatch(loadStart());
2016-04-29 08:15:37 +00:00
network.send(request._id, () => {
2016-04-23 06:08:52 +00:00
dispatch(loadStop());
});
}
}
export function showUpdateNamePrompt (request) {
const defaultValue = request.name;
return show(MODAL_REQUEST_RENAME, {defaultValue, request});
}