import * as types from '../../types' import { store } from '../../store' import actions from '../../actions' export const showAddTileForm = () => dispatch => { dispatch({ type: types.page.show_add_tile_form }) } export const hideAddTileForm = () => dispatch => { dispatch({ type: types.page.hide_add_tile_form }) } export const toggleAddTileForm = () => dispatch => { dispatch({ type: types.page.toggle_add_tile_form }) } export const updatePageTile = tile => dispatch => { dispatch({ type: types.page.update_page_tile, tile }) } export const showGraphAndPageIfUnloaded = ({ graph_name, page_name }) => dispatch => ( new Promise((resolve, reject) => { showGraphIfUnloaded({ graph_name })(dispatch) .then(graph => ( actions.page.show('name/' + graph_name + '/' + page_name) .then(resolve) .catch(reject) )) .catch(reject) }) ) export const showGraphIfUnloaded = ({ graph_name }) => dispatch => ( new Promise((resolve, reject) => { const { res: graph } = store.getState().graph.show if (graph && graph.path === graph_name) { return resolve(graph) } actions.graph.show('name/' + graph_name) .then(resolve) .catch(reject) }) )