Skip to content
This repository was archived by the owner on Feb 5, 2022. It is now read-only.

Commit a5d60b1

Browse files
committed
feat: add sw reload
1 parent 3b68b47 commit a5d60b1

File tree

7 files changed

+301
-222
lines changed

7 files changed

+301
-222
lines changed

functions/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,8 @@
1818
"tslint": "^5.12.0",
1919
"typescript": "^3.2.2"
2020
},
21-
"private": true
21+
"private": true,
22+
"engines": {
23+
"node": "8"
24+
}
2225
}

package-lock.json

Lines changed: 200 additions & 219 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/assets/i18n/en.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
export const translations = {
22
translation: {
33
home: {
4+
newversion: 'New version available...',
5+
reload: 'Reload',
46
hero: {
57
title: 'Mobile Solutions',
68
subTitle: 'For A Digital World',

src/components/app-nav-header/app-nav-header.scss

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,66 @@ ul.navbar-nav {
131131
margin: 0;
132132
}
133133
}
134+
135+
#toast {
136+
visibility: hidden;
137+
min-width: 250px;
138+
margin-left: -125px;
139+
background-color: #333;
140+
color: #fff;
141+
text-align: center;
142+
border-radius: 2px;
143+
padding: 16px;
144+
position: fixed;
145+
z-index: 1;
146+
left: 50%;
147+
bottom: 30px;
148+
border-radius: 16px;
149+
}
150+
151+
#toast.show {
152+
visibility: visible;
153+
-webkit-animation: fadein 0.5s;
154+
animation: fadein 0.5s;
155+
}
156+
157+
@-webkit-keyframes fadein {
158+
from {
159+
bottom: 0;
160+
opacity: 0;
161+
}
162+
to {
163+
bottom: 30px;
164+
opacity: 1;
165+
}
166+
}
167+
168+
@keyframes fadein {
169+
from {
170+
bottom: 0;
171+
opacity: 0;
172+
}
173+
to {
174+
bottom: 30px;
175+
opacity: 1;
176+
}
177+
}
178+
179+
#toast-button {
180+
text-transform: uppercase;
181+
background: transparent;
182+
text-align: center;
183+
max-width: 200px;
184+
text-decoration: none;
185+
border: 0.75px solid #ffffff;
186+
border-radius: 16px;
187+
box-shadow: 0 2px 4px 0 rgba(128, 128, 128, 0.5);
188+
margin-left: 10px;
189+
color: #ffffff;
190+
191+
&:hover {
192+
text-decoration: none;
193+
background: white;
194+
color: black;
195+
}
196+
}

src/components/app-nav-header/app-nav-header.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ export class AppNavHeader {
135135
</div>
136136
</nav>
137137
<app-search-results onClose={ev => this.toogleSearch('hidden', ev.detail.pageChanged)} />
138+
<div id="toast">
139+
<app-translate keyword="home.newversion" />
140+
<button id="toast-button">
141+
<app-translate keyword="home.reload" />
142+
</button>
143+
</div>
138144
</div>
139145
);
140146
}

src/pages/open-forge-app/open-forge-app.tsx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import '@stencil/router';
2-
import { Component, h } from '@stencil/core';
2+
import { Component, h, Listen } from '@stencil/core';
33
import { polyfill } from 'smoothscroll-polyfill';
44

55
polyfill();
@@ -11,6 +11,29 @@ polyfill();
1111
export class OpenForgeApp {
1212
mainEl: HTMLElement;
1313
newServiceWorker: boolean = false;
14+
registration: ServiceWorkerRegistration;
15+
16+
@Listen('swUpdate', { target: 'window' })
17+
async onSWUpdate() {
18+
this.registration = await navigator.serviceWorker.getRegistration();
19+
if (this.registration && this.registration.waiting) {
20+
this.showToast();
21+
}
22+
}
23+
24+
showToast() {
25+
const toastDiv = document.getElementById('toast');
26+
toastDiv.className = 'show';
27+
const toastButton = document.getElementById('toast-button');
28+
toastButton.addEventListener('click', () => this.closeAndReload());
29+
}
30+
31+
closeAndReload() {
32+
if (this.registration && this.registration.waiting) {
33+
this.registration.waiting.postMessage('skipWaiting');
34+
}
35+
window.location.reload();
36+
}
1437

1538
componentDidLoad() {
1639
try {

stencil.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ export const config: Config = {
2626
serviceWorker: {
2727
globPatterns: [
2828
'**/*.{js,css,json,html,ico,png,svg}'
29-
]
29+
],
30+
swSrc: 'src/sw.js'
3031
},
3132
copy: [
3233
{ src: 'robots.txt' }

0 commit comments

Comments
 (0)