Show warning when disconnected

This commit is contained in:
Ken-Håvard Lieng 2017-05-29 06:16:24 +02:00
parent 2d32df3afe
commit d9e3d71a1f
7 changed files with 88 additions and 32 deletions

File diff suppressed because one or more lines are too long

View File

@ -39,8 +39,33 @@ i[class^="icon-"]:before, i[class*=" icon-"]:before {
margin: 0; margin: 0;
} }
.tablist { .wrap {
position: fixed; position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
display: flex;
flex-direction: column;
}
.app-info {
width: 100%;
font-family: Montserrat, sans-serif;
background: #F6546A;
color: #FFF;
height: 50px;
line-height: 50px;
text-align: center;
}
.app-container {
position: relative;
flex: 1;
}
.tablist {
position: absolute;
left: 0; left: 0;
top: 0; top: 0;
bottom: 0; bottom: 0;
@ -120,7 +145,7 @@ i[class^="icon-"]:before, i[class*=" icon-"]:before {
} }
.side-buttons { .side-buttons {
position: fixed; position: absolute;
bottom: 0; bottom: 0;
height: 50px; height: 50px;
width: 200px; width: 200px;
@ -147,7 +172,7 @@ i[class^="icon-"]:before, i[class*=" icon-"]:before {
} }
.main-container { .main-container {
position: fixed; position: absolute;
left: 200px; left: 200px;
top: 0; top: 0;
bottom: 0; bottom: 0;
@ -166,7 +191,7 @@ i[class^="icon-"]:before, i[class*=" icon-"]:before {
} }
.connect .navicon, .settings .navicon { .connect .navicon, .settings .navicon {
position: absolute; position: fixed;
top: 0; top: 0;
left: 0; left: 0;
} }
@ -581,6 +606,10 @@ i[class^="icon-"]:before, i[class*=" icon-"]:before {
} }
@media (max-width: 600px) { @media (max-width: 600px) {
.app-info {
font-size: 12px;
}
.tablist { .tablist {
width: 200px; width: 200px;
transform: translateX(-200px); transform: translateX(-200px);

View File

@ -14,16 +14,31 @@ export default class App extends Component {
}; };
render() { render() {
const mainClass = this.props.showTabList ? 'main-container off-canvas' : 'main-container'; const { connected, tab, channels, servers,
privateChats, showTabList, select, push } = this.props;
const mainClass = showTabList ? 'main-container off-canvas' : 'main-container';
return ( return (
<div onClick={this.handleClick}> <div className="wrap">
<TabList {...this.props} /> {!connected &&
<div className="app-info">Connection lost, attempting to reconnect...</div>
}
<div className="app-container" onClick={this.handleClick}>
<TabList
tab={tab}
channels={channels}
servers={servers}
privateChats={privateChats}
showTabList={showTabList}
select={select}
push={push}
/>
<div className={mainClass}> <div className={mainClass}>
<Route name="chat"><Chat /></Route> <Route name="chat"><Chat /></Route>
<Route name="connect"><Connect /></Route> <Route name="connect"><Connect /></Route>
<Route name="settings"><Settings /></Route> <Route name="settings"><Settings /></Route>
</div> </div>
</div> </div>
</div>
); );
} }
} }

View File

@ -10,6 +10,7 @@ import { push } from '../util/router';
const mapState = createStructuredSelector({ const mapState = createStructuredSelector({
channels: getChannels, channels: getChannels,
connected: state => state.environment.get('connected'),
privateChats: getPrivateChats, privateChats: getPrivateChats,
servers: getServers, servers: getServers,
showTabList: getShowTabList, showTabList: getShowTabList,

View File

@ -1,4 +1,5 @@
import { socketAction } from '../state/actions'; import { socketAction } from '../state/actions';
import { setEnvironment } from '../state/environment';
import { broadcast, inform, print, addMessage, addMessages } from '../state/messages'; import { broadcast, inform, print, addMessage, addMessages } from '../state/messages';
import { select } from '../state/tab'; import { select } from '../state/tab';
import { normalizeChannel } from '../util'; import { normalizeChannel } from '../util';
@ -102,6 +103,10 @@ export default function handleSocket({ socket, store: { dispatch, getState } })
print(message) { print(message) {
const tab = getState().tab.selected; const tab = getState().tab.selected;
dispatch(addMessage(message, tab.server, tab.name)); dispatch(addMessage(message, tab.server, tab.name));
},
_connected(connected) {
dispatch(setEnvironment('connected', connected));
} }
}; };

View File

@ -10,7 +10,11 @@ export const getWindowWidth = state => state.environment.get('windowWidth');
export const getConnectDefaults = state => state.environment.get('connect_defaults'); export const getConnectDefaults = state => state.environment.get('connect_defaults');
export default createReducer(Map(), { const initialState = Map({
connected: true
});
export default createReducer(initialState, {
[actions.SET_ENVIRONMENT](state, action) { [actions.SET_ENVIRONMENT](state, action) {
return state.set(action.key, action.value); return state.set(action.key, action.value);
}, },

View File

@ -26,12 +26,14 @@ export default class Socket {
}, this.connectTimeout); }, this.connectTimeout);
this.ws.onopen = () => { this.ws.onopen = () => {
this.emit('_connected', true);
clearTimeout(this.timeoutConnect); clearTimeout(this.timeoutConnect);
this.backoff.reset(); this.backoff.reset();
this.setTimeoutPing(); this.setTimeoutPing();
}; };
this.ws.onclose = () => { this.ws.onclose = () => {
this.emit('_connected', false);
clearTimeout(this.timeoutConnect); clearTimeout(this.timeoutConnect);
clearTimeout(this.timeoutPing); clearTimeout(this.timeoutPing);
if (!this.closing) { if (!this.closing) {