Improve settings storage
- add error reporting - refactor
This commit is contained in:
@@ -12,6 +12,7 @@ import { Dispatch } from 'redux'
|
||||
import { MqttOptions } from '../../../backend/src/DataSource'
|
||||
import { showTree } from './Tree'
|
||||
import { TopicViewModel } from '../TopicViewModel'
|
||||
import { showError } from './Global'
|
||||
|
||||
export const connect = (options: MqttOptions, connectionId: string) => (dispatch: Dispatch<any>, getState: () => AppState) => {
|
||||
dispatch(connecting(connectionId))
|
||||
@@ -44,11 +45,6 @@ export const connecting: (connectionId: string) => Action = (connectionId: strin
|
||||
type: ActionTypes.CONNECTION_SET_CONNECTING,
|
||||
})
|
||||
|
||||
export const showError = (error?: string) => ({
|
||||
error,
|
||||
type: ActionTypes.CONNECTION_SET_SHOW_ERROR,
|
||||
})
|
||||
|
||||
export const disconnect = () => (dispatch: Dispatch<any>, getState: () => AppState) => {
|
||||
const { connectionId, tree } = getState().connection
|
||||
rendererEvents.emit(removeConnection, connectionId)
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { AppState } from '../reducers'
|
||||
import { clearLegacyConnectionOptions, loadLegacyConnectionOptions } from '../model/LegacyConnectionSettings'
|
||||
import { ConnectionOptions, createEmptyConnection, makeDefaultConnections } from '../model/ConnectionOptions'
|
||||
import { default as persistantStorage, StorageIdentifier } from '../PersistantStorage'
|
||||
import { Dispatch } from 'redux'
|
||||
import { loadLegacyConnectionOptions, clearLegacyConnectionOptions } from '../model/LegacyConnectionSettings'
|
||||
import { showError } from './Global'
|
||||
import {
|
||||
ActionTypes,
|
||||
Action,
|
||||
@@ -13,8 +14,13 @@ const storedConnectionsIdentifier: StorageIdentifier<{[s: string]: ConnectionOpt
|
||||
}
|
||||
|
||||
export const loadConnectionSettings = () => async (dispatch: Dispatch<any>, getState: () => AppState) => {
|
||||
await ensureConnectionsHaveBeenInitialized()
|
||||
const connections = await persistantStorage.load(storedConnectionsIdentifier)
|
||||
let connections
|
||||
try {
|
||||
await ensureConnectionsHaveBeenInitialized()
|
||||
connections = await persistantStorage.load(storedConnectionsIdentifier)
|
||||
} catch (error) {
|
||||
dispatch(showError(error))
|
||||
}
|
||||
|
||||
if (!connections) {
|
||||
return
|
||||
@@ -27,8 +33,12 @@ export const loadConnectionSettings = () => async (dispatch: Dispatch<any>, getS
|
||||
}
|
||||
}
|
||||
|
||||
export const saveConnectionSettings = () => (_dispatch: Dispatch<any>, getState: () => AppState) => {
|
||||
persistantStorage.store(storedConnectionsIdentifier, getState().connectionManager.connections)
|
||||
export const saveConnectionSettings = () => async (dispatch: Dispatch<any>, getState: () => AppState) => {
|
||||
try {
|
||||
await persistantStorage.store(storedConnectionsIdentifier, getState().connectionManager.connections)
|
||||
} catch (error) {
|
||||
dispatch(showError(error))
|
||||
}
|
||||
}
|
||||
|
||||
export const updateConnection = (connectionId: string, changeSet: any): Action => ({
|
||||
|
||||
6
app/src/actions/Global.ts
Normal file
6
app/src/actions/Global.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { ActionTypes } from '../reducers'
|
||||
|
||||
export const showError = (error?: string) => ({
|
||||
error,
|
||||
type: ActionTypes.showError,
|
||||
})
|
||||
@@ -5,5 +5,6 @@ import * as updateNotifierActions from './UpdateNotifier'
|
||||
import * as connectionActions from './Connection'
|
||||
import * as sidebarActons from './Sidebar'
|
||||
import * as connectionManagerActions from './ConnectionManager'
|
||||
import * as globalActions from './Global'
|
||||
|
||||
export { settingsActions, treeActions, publishActions, updateNotifierActions, connectionActions, sidebarActons, connectionManagerActions }
|
||||
export { settingsActions, treeActions, publishActions, updateNotifierActions, connectionActions, sidebarActons, connectionManagerActions, globalActions }
|
||||
|
||||
Reference in New Issue
Block a user