Skip to content

Commit

Permalink
add no connection notif
Browse files Browse the repository at this point in the history
  • Loading branch information
adnanfajlur committed Apr 10, 2018
1 parent ef6a384 commit 9c617cf
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
</style>
</head>
<body>
<main>
<main id="main">
<div class="wrapAppbar">
<div class="appbar">
<img src="./img/icon/coffe-32.png" alt="coffe">
Expand Down
22 changes: 22 additions & 0 deletions src/js/renderDom.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ function changeUrl(param) {
}

async function fetchAsync(page, search) {
renderOffline()
let response = await fetch(`https://hnpwa.com/api/v0/${page === '' ? 'news' : page}.json?page=${search}`, {
header: {
'Access-Control-Allow-Origin': '*'
Expand All @@ -116,6 +117,27 @@ async function fetchAsync(page, search) {
return data;
}

function renderOffline() {
if (!window.navigator.onLine) {
getEl('main').appendChild(div({
style: {
position: 'fixed',
bottom: '0',
width: '100vw',
textAlign: 'center',
padding: '5px 0',
color: '#fff',
background: '#c0392b'
},
id: 'divOffline'
},
span(`No Connections Are Available`)
))
} else if (getEl('divOffline') !== null) {
getEl('main').removeChild(getEl('divOffline'))
}
}

fetchData()
renderPagination()
getEl(`link${halaman()}`).className = 'active'
Expand Down
6 changes: 3 additions & 3 deletions src/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ self.__precacheManifest = [
},
{
"url": "index.html",
"revision": "a2584d0dacd0d6f76ee03fbe6cbb506f"
"revision": "f2d26fedb421a982d2846ede4a2e31e6"
},
{
"url": "js/app.js",
Expand All @@ -45,15 +45,15 @@ self.__precacheManifest = [
},
{
"url": "js/renderDom.js",
"revision": "8bc43853925caacc59f7f3fab634fee4"
"revision": "2bbc243ed99d4f232a65b2d84220a3f1"
},
{
"url": "other/manifest.json",
"revision": "c95966b16d7f270c22908636d6fc3268"
},
{
"url": "/",
"revision": "cf4972201659ebad22fd7f7871bd5225"
"revision": "93f569f3536b3c756772727fc77de6ce"
}
].concat(self.__precacheManifest || []);
workbox.precaching.suppressWarnings();
Expand Down

0 comments on commit 9c617cf

Please sign in to comment.