Redirect to stored tab if the route is not found
This commit is contained in:
parent
2afbf2359c
commit
5487ecdb57
File diff suppressed because one or more lines are too long
@ -1,10 +1,12 @@
|
|||||||
import documentTitle from './documentTitle';
|
import documentTitle from './documentTitle';
|
||||||
import handleSocket from './handleSocket';
|
import handleSocket from './handleSocket';
|
||||||
import initialState from './initialState';
|
import initialState from './initialState';
|
||||||
|
import storage from './storage';
|
||||||
|
|
||||||
export default function runModules(ctx) {
|
export default function runModules(ctx) {
|
||||||
initialState(ctx);
|
initialState(ctx);
|
||||||
|
|
||||||
documentTitle(ctx);
|
documentTitle(ctx);
|
||||||
handleSocket(ctx);
|
handleSocket(ctx);
|
||||||
|
storage(ctx);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import { setEnvironment } from '../actions/environment';
|
import { setEnvironment } from '../actions/environment';
|
||||||
import { addMessages } from '../actions/message';
|
import { addMessages } from '../actions/message';
|
||||||
|
import { select, updateSelection } from '../actions/tab';
|
||||||
|
import { find } from '../util';
|
||||||
import { initWidthUpdates } from '../util/messageHeight';
|
import { initWidthUpdates } from '../util/messageHeight';
|
||||||
import { replace } from '../util/router';
|
import { replace } from '../util/router';
|
||||||
|
|
||||||
@ -13,6 +15,21 @@ export default function initialState({ store }) {
|
|||||||
type: 'SOCKET_SERVERS',
|
type: 'SOCKET_SERVERS',
|
||||||
data: env.servers
|
data: env.servers
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!store.getState().router.route) {
|
||||||
|
let tab = localStorage.tab;
|
||||||
|
if (tab) {
|
||||||
|
tab = JSON.parse(tab);
|
||||||
|
|
||||||
|
if (find(env.servers, server => server.host === tab.server)) {
|
||||||
|
store.dispatch(select(tab.server, tab.name, true));
|
||||||
|
} else {
|
||||||
|
store.dispatch(updateSelection());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
store.dispatch(updateSelection());
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
store.dispatch(replace('/connect'));
|
store.dispatch(replace('/connect'));
|
||||||
}
|
}
|
||||||
|
15
client/src/js/modules/storage.js
Normal file
15
client/src/js/modules/storage.js
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import debounce from 'lodash/debounce';
|
||||||
|
import observe from '../util/observe';
|
||||||
|
import { getSelectedTab } from '../reducers/tab';
|
||||||
|
|
||||||
|
const saveTab = debounce(tab => {
|
||||||
|
localStorage.tab = JSON.stringify(tab);
|
||||||
|
}, 3000);
|
||||||
|
|
||||||
|
export default function storage({ store }) {
|
||||||
|
observe(store, getSelectedTab, tab => {
|
||||||
|
if (tab.server) {
|
||||||
|
saveTab(tab);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
@ -45,3 +45,12 @@ export function measureScrollBarWidth() {
|
|||||||
|
|
||||||
return widthNoScroll - widthWithScroll;
|
return widthNoScroll - widthWithScroll;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function find(arr, pred) {
|
||||||
|
for (let i = 0; i < arr.length; i++) {
|
||||||
|
if (pred(arr[i])) {
|
||||||
|
return arr[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user