Skip to content

Commit

Permalink
Add messages when user is online/offline
Browse files Browse the repository at this point in the history
  • Loading branch information
RalucaNicola committed Feb 14, 2018
1 parent c2c4528 commit a4ff93e
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 3 deletions.
4 changes: 2 additions & 2 deletions dist/main.bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/main.css

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions src/style/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,26 @@ h1 {
}

}


.connectionMessage {
position: absolute;
top: 0;
left: 50%;
margin-left: -150px;
width: 300px;
z-index: 100;
padding: 20px;
text-align: center;
font-size: $normal-font;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
font-weight: bold;
}

.online {
background-color: rgba(184, 242, 204, 0.9);
}

.offline {
background-color: rgba(241, 189, 183, 0.9);
}
2 changes: 2 additions & 0 deletions src/ts/State.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,6 @@ export default class State extends declared(Accessor) {
@property()
trails: Array<Trail> = null;

@property()
online: boolean = true;
}
2 changes: 2 additions & 0 deletions src/ts/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ esriConfig.request.useIdentity = false;

import State from "./State";
import deviceUtils from "./ui/deviceUtils";
import ConnectionManager from "./ui/ConnectionManager";
import SceneElement from "./scene/SceneElement";
import LoadingPage from "./ui/LoadingPage";
import Trail from "./data/Trail";
Expand All @@ -22,6 +23,7 @@ if ("serviceWorker" in navigator) {

const state = new State();
deviceUtils.init(state);
const connectionManager = new ConnectionManager(state);
const loadingPage = new LoadingPage(state);
const sceneElement = new SceneElement(state);
sceneElement.getZEnrichedTrails()
Expand Down
52 changes: 52 additions & 0 deletions src/ts/ui/ConnectionManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import * as dom from "dojo/dom";
import * as on from "dojo/on";
import * as domConstruct from "dojo/dom-construct";

function createMessage(message: string, online: boolean): void {

// display message
const messageContainer = domConstruct.create("div", {
innerHTML: message,
class: online ? "online connectionMessage" : "offline connectionMessage"
}, document.body);

// message disappears after 3 seconds
window.setTimeout(function() {
domConstruct.destroy(messageContainer);
}, 3000);
}

export default class ConnectionManager {

constructor(state) {

window.addEventListener("load", function() {

function updateOnlineStatus(event) {
state.online = navigator.onLine ? true : false;
}

window.addEventListener("online", updateOnlineStatus);
window.addEventListener("offline", updateOnlineStatus);
});

state.watch("online", (value) => {
console.log(value);
if (!value) {
this.createOfflineMessage();
}
else {
this.createOnlineMessage();
}
});
}

createOfflineMessage() {
createMessage("You seem to be offline. This application has limited functionality.", false);
}

createOnlineMessage() {
createMessage("You are back online.", true);
}

}

0 comments on commit a4ff93e

Please sign in to comment.