Improve 404 handling

This commit is contained in:
Ken-Håvard Lieng 2018-11-29 13:06:37 +01:00
parent 869713d236
commit 5861a54dfc
4 changed files with 146 additions and 125 deletions

File diff suppressed because one or more lines are too long

View File

@ -17,11 +17,7 @@ export default class Editable extends PureComponent {
// eslint-disable-next-line react/no-did-update-set-state // eslint-disable-next-line react/no-did-update-set-state
this.updateInputWidth(this.props.value); this.updateInputWidth(this.props.value);
this.inputEl.current.focus(); this.inputEl.current.focus();
} } else if (this.state.editing && prevProps.value !== this.props.value) {
}
getSnapshotBeforeUpdate(prevProps) {
if (this.state.editing && prevProps.value !== this.props.value) {
this.updateInputWidth(this.props.value); this.updateInputWidth(this.props.value);
} }
} }

View File

@ -25,25 +25,47 @@ function loadState({ store }, env) {
data: env.servers data: env.servers
}); });
if (!store.getState().router.route) { const { router } = store.getState();
const tab = Cookie.get('tab');
if (tab) { if (!router.route || router.route === 'chat') {
const [server, name = null] = tab.split(/;(.+)/); const tabs = [];
if (router.route === 'chat') {
tabs.push(router.params);
}
const cookie = Cookie.get('tab');
if (cookie) {
const [server, name = null] = cookie.split(/;(.+)/);
tabs.push({
server,
name
});
}
let found = false;
let i = 0;
while (!found) {
const tab = tabs[i];
i++;
if ( if (
name && tab.name &&
find( find(
env.channels, env.channels,
chan => chan.server === server && chan.name === name chan => chan.server === tab.server && chan.name === tab.name
) )
) { ) {
store.dispatch(select(server, name, true)); found = true;
} else if (find(env.servers, srv => srv.host === server)) { store.dispatch(select(tab.server, tab.name, true));
store.dispatch(select(server, null, true)); } else if (find(env.servers, srv => srv.host === tab.server)) {
} else { found = true;
store.dispatch(updateSelection()); store.dispatch(select(tab.server, null, true));
} }
} else { }
if (!found) {
store.dispatch(updateSelection()); store.dispatch(updateSelection());
} }
} }

View File

@ -64,7 +64,10 @@ export function updateSelection() {
if (serverAddrs.length === 0) { if (serverAddrs.length === 0) {
dispatch(replace('/connect')); dispatch(replace('/connect'));
} else if (history.length > 0) { } else if (
history.length > 0 &&
history[history.length - 1] !== state.tab.selected
) {
const tab = history[history.length - 1]; const tab = history[history.length - 1];
dispatch(select(tab.server, tab.name, true)); dispatch(select(tab.server, tab.name, true));
} else if (servers[server]) { } else if (servers[server]) {