summaryrefslogtreecommitdiff
path: root/frontend/views/page/page.actions.js
blob: 82615155bd3eac613760822dd743603dfa7c19e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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_graph_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)
  })
)