(store: RootStore)
| 21 | }; |
| 22 | |
| 23 | export function updateStoreFromUrl(store: RootStore) { |
| 24 | const [path, query] = window.location.hash.substr(1).split("?", 2); |
| 25 | const path_components = path.substr(1).split("/"); |
| 26 | |
| 27 | if (path_components[0] === "flows") { |
| 28 | if (path_components.length == 3) { |
| 29 | const [flowId, tab] = path_components.slice(1); |
| 30 | store.dispatch(selectTab(tab)); |
| 31 | |
| 32 | const selectFlowOnceAvailable = () => { |
| 33 | const flow = store.getState().flows.byId.get(flowId); |
| 34 | if (flow !== undefined) { |
| 35 | unsubscribe(); |
| 36 | store.dispatch(select([flow])); |
| 37 | } |
| 38 | }; |
| 39 | const unsubscribe = store.subscribe(selectFlowOnceAvailable); |
| 40 | selectFlowOnceAvailable(); |
| 41 | } |
| 42 | } else if (path_components[0] === "capture") { |
| 43 | store.dispatch(setCurrent(Tab.Capture)); |
| 44 | } |
| 45 | |
| 46 | if (query) { |
| 47 | query.split("&").forEach((x) => { |
| 48 | const [key, encodedVal] = x.split("=", 2); |
| 49 | const value = decodeURIComponent(encodedVal); |
| 50 | switch (key) { |
| 51 | case Query.SEARCH: |
| 52 | store.dispatch(setFilter(value)); |
| 53 | break; |
| 54 | case Query.HIGHLIGHT: |
| 55 | store.dispatch(setHighlight(value)); |
| 56 | break; |
| 57 | case Query.SHOW_EVENTLOG: |
| 58 | if (!store.getState().eventLog.visible) |
| 59 | store.dispatch(eventLogActions.toggleVisibility()); |
| 60 | break; |
| 61 | case Query.SHOW_COMMANDBAR: |
| 62 | if (!store.getState().commandBar.visible) |
| 63 | store.dispatch(commandBarActions.toggleVisibility()); |
| 64 | break; |
| 65 | default: |
| 66 | console.error(`unimplemented query arg: ${x}`); |
| 67 | } |
| 68 | }); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | export function updateUrlFromStore(store: RootStore) { |
| 73 | const state = store.getState(); |
no test coverage detected
searching dependent graphs…