Skip to content

Commit

Permalink
Redirect to home page if can't open db
Browse files Browse the repository at this point in the history
  • Loading branch information
sheldhur committed Jan 28, 2018
1 parent 01c8af9 commit eed30ab
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions app/actions/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@ import { remote } from 'electron';
import * as fs from 'fs';
import { push } from 'react-router-redux';
import {
DEFAULT_SETTINGS,
FILE_EXT_ALL,
FILE_EXT_DB,
FORMAT_DATE_SQL,
FORMAT_FILENAME,
LS_KEY_APP_SETTINGS,
LS_KEY_LAST_DB
DEFAULT_SETTINGS, FILE_EXT_ALL, FILE_EXT_DB, FORMAT_DATE_SQL, FORMAT_FILENAME, LS_KEY_APP_SETTINGS, LS_KEY_LAST_DB,
} from '../constants/app';
import * as types from '../constants/main';
import dbConnect from '../database/dbConnect';
Expand All @@ -22,37 +16,37 @@ let db;
export function setLoading(payload) {
return {
type: types.LOADING,
payload
payload,
};
}

export function setError(payload) {
return {
type: types.ERROR,
payload
payload,
};
}

export function setUpdate(payload) {
return {
type: types.UPDATE,
payload
payload,
};
}

export function setSettings(payload) {
return {
type: types.SETTINGS,
payload,
syncState: true
syncState: true,
};
}

export function setDataBasePath(payload) {
return {
type: types.DB_PATH,
payload,
syncState: true
syncState: true,
};
}

Expand All @@ -75,11 +69,12 @@ export function getLastDataBase(openMain = true) {
} catch (e) {
console.error(e);
dispatch(setError(errorToObject(new Error('Can\'t open last database: ' + path))));
dispatch(push('/'));
}
} else {
dispatch(setDataBasePath(null));
}
}
};
}

export function saveSettings(values, useDefault = false) {
Expand All @@ -106,7 +101,7 @@ export function saveSettings(values, useDefault = false) {
localStorage[LS_KEY_APP_SETTINGS] = settingsApp;

return dispatch(setSettings(settings));
}
};
}

export function loadSettings(id = 1) {
Expand All @@ -123,7 +118,7 @@ export function loadSettings(id = 1) {
} catch (e) {
throw e;
}
}
};
}

async function createConnect(path) {
Expand All @@ -149,7 +144,7 @@ export function openDataBase(path, openMain = true) {
dispatch(setError(errorToObject(e)));
dispatch(push('/'));
}
}
};
}

export function createDataBase(path, settings) {
Expand All @@ -165,7 +160,7 @@ export function createDataBase(path, settings) {
console.error(e);
dispatch(setError(e));
}
}
};
}

export function closeDataBase() {
Expand All @@ -175,15 +170,15 @@ export function closeDataBase() {
db = null;
dispatch(push('/home'));
}
}
};
}

function openMainPage() {
return (dispatch, getState) => {
if (getState().router.location.pathname !== '/main') {
return dispatch(push('/main'));
}
}
};
}

export function dialogOpenCreateDataBase(settings) {
Expand All @@ -197,7 +192,7 @@ export function dialogOpenCreateDataBase(settings) {
buttonLabel: !settings ? 'Open database' : 'Create database',
filters: [
{ name: 'Database', extensions: FILE_EXT_DB },
{ name: 'All Files', extensions: FILE_EXT_ALL }
{ name: 'All Files', extensions: FILE_EXT_ALL },
],
}, (filePaths) => {
if (filePaths && filePaths.length) {
Expand All @@ -208,5 +203,5 @@ export function dialogOpenCreateDataBase(settings) {
}
}
});
}
};
}

0 comments on commit eed30ab

Please sign in to comment.