Skip to content
This repository has been archived by the owner on Apr 15, 2019. It is now read-only.

Commit

Permalink
Testing route fix
Browse files Browse the repository at this point in the history
  • Loading branch information
reyraa committed Sep 29, 2017
1 parent 678f7e7 commit 24c89a7
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 32 deletions.
52 changes: 22 additions & 30 deletions src/components/dialog/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,15 @@ import AppBar from 'react-toolbox/lib/app_bar';
import { IconButton } from 'react-toolbox/lib/button';
import styles from './dialog.css';
import dialogs from './dialogs';
import routesReg from '../../utils/routes';

class DialogElement extends Component {
constructor() {
super();
this.state = {};
this.routesReg = [
{
regex: /\/main\/transactions(?:\/[^/]*)?$/,
path: '/main/transactions/',
params: 'dialog',
name: 'transactions',
}, {
regex: /\/main\/voting(?:\/[^/]*)?$/,
path: '/main/voting/',
params: 'dialog',
name: 'voting',
}, {
regex: /\/main\/forging(?:\/[^/]*)?$/,
path: '/main/forging/',
params: 'dialog',
name: 'forging',
}, {
regex: /\/(\w+)?$/,
path: '/',
params: 'dialog',
name: 'login',
},
];
this.current = {
pathname: '/',
reg: this.routesReg[3],
reg: routesReg[3],
list: [],
dialog: '',
};
Expand All @@ -50,15 +28,26 @@ class DialogElement extends Component {
}

checkForDialog() {
// if the dialog is wrong, show a toast
if (this.current.pathname !== this.props.history.location.pathname) {
this.current.reg = this.routesReg.find(item =>
const reg = routesReg.find(item =>
item.regex.test(this.props.history.location.pathname));
this.current.pathname = this.props.history.location.pathname;
const dialogName = this.props.history.location.pathname.replace(this.current.reg.path, '');
if (dialogs[dialogName] !== undefined) {
this.open(this.current.reg, dialogs[dialogName]);
console.log('opening', reg, this.current.pathname, this.props.history.location.pathname);
// wrong route, get back
if (reg === undefined) {
this.goBack();
} else {
this.close();
this.current.reg = reg;
this.current.pathname = this.props.history.location.pathname;
const dialogName = this.props.history.location.pathname.replace(this.current.reg.path, '');

// route has a dialog, open it
if (dialogs[dialogName] !== undefined) {
this.open(this.current.reg, dialogs[dialogName]);
// route doesn't have a dialog, close if already open
} else {
this.close();
}
}
}
}
Expand Down Expand Up @@ -94,6 +83,9 @@ class DialogElement extends Component {

goBack() {
this.props.history.push(this.current.reg.path);
setTimeout(() => {
console.log('closed', this.current.reg.path);
}, 5);
}

render() {
Expand Down
12 changes: 10 additions & 2 deletions src/utils/externalLinks.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import history from '../history';
import routesReg from './routes';
import { errorToastDisplayed } from '../actions/toaster';
import store from '../store';

export default {
init: () => {
const { ipc } = window;
const protocolReg = /[lL][iI][sS][kK]:\/\//;

if (ipc) {
ipc.on('openUrl', (action, url) => {
history.push(url.replace(protocolReg, '/'));
const normalizedUrl = url.toLowerCase().replace('lisk://', '/');
const route = routesReg.find(item => item.regex.test(normalizedUrl));
if (route !== undefined) {
history.push(normalizedUrl);
} else {
store.dispatch(errorToastDisplayed({ label: 'The URL was invalid' }));
}
});
}
},
Expand Down
28 changes: 28 additions & 0 deletions src/utils/routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
export default [
{
regex: /\/main\/transactions(?:\/[^/]*)?$/,
path: '/main/transactions/',
params: 'dialog',
name: 'transactions',
}, {
regex: /\/main\/voting(?:\/[^/]*)?$/,
path: '/main/voting/',
params: 'dialog',
name: 'voting',
}, {
regex: /\/main\/forging(?:\/[^/]*)?$/,
path: '/main/forging/',
params: 'dialog',
name: 'forging',
}, {
regex: /register(\/)?$/,
path: '/',
params: 'dialog',
name: 'login',
}, {
regex: /^\/$/,
path: '/',
params: 'dialog',
name: 'login',
},
];

0 comments on commit 24c89a7

Please sign in to comment.