Only redirect to a stored tab if it still exists

This commit is contained in:
Ken-Håvard Lieng 2017-06-29 07:36:58 +02:00
parent 962f7d1eb0
commit 3af6ad9cd9
3 changed files with 26 additions and 20 deletions

File diff suppressed because one or more lines are too long

View File

@ -23,8 +23,10 @@ export default function initialState({ store }) {
if (tab) { if (tab) {
const [server, name = null] = tab.split(/;(.+)/); const [server, name = null] = tab.split(/;(.+)/);
if (find(env.servers, srv => srv.host === server)) { if (name && find(env.channels, chan => chan.name === name)) {
store.dispatch(select(server, name, true)); store.dispatch(select(server, name, true));
} else if (find(env.servers, srv => srv.host === server)) {
store.dispatch(select(server, null, true));
} else { } else {
store.dispatch(updateSelection()); store.dispatch(updateSelection());
} }

View File

@ -52,6 +52,10 @@ export function measureScrollBarWidth() {
} }
export function find(arr, pred) { export function find(arr, pred) {
if (!arr) {
return null;
}
for (let i = 0; i < arr.length; i++) { for (let i = 0; i < arr.length; i++) {
if (pred(arr[i])) { if (pred(arr[i])) {
return arr[i]; return arr[i];