Skip to content

Commit 041e70e

Browse files
committed
Update: improve update-ready display
1 parent f53c66f commit 041e70e

File tree

5 files changed

+69
-25
lines changed

5 files changed

+69
-25
lines changed

.eslintrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"browser": false
1616
},
1717
"globals": {
18+
"applicationCache": false,
1819
"atob": false,
1920
"btoa": false,
2021
"console": false,

src/app-state.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export default class PlaygroundState {
2424
this.messages = []
2525
this.fixedCode = code
2626
this.fixedMessages = []
27+
this.showUpdateReadyToast = false
2728

2829
const deserialized =
2930
typeof serializedString === "string" &&

src/app.vue

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
</div>
5050
</div>
5151
<div class="app__footer">
52-
<div class="app__footer-message"/>
5352
<div
5453
class="app__version-item"
5554
v-for="(v, name) in versions"
@@ -59,6 +58,10 @@
5958
v{{ v.version }}
6059
</div>
6160
</div>
61+
<div class="app__update-ready-toast" v-if="showUpdateReadyToast">
62+
<div>Please reload because a new version of this site is available.</div>
63+
<button @click="reload">Reload</button>
64+
</div>
6265
</div>
6366
</template>
6467

@@ -79,7 +82,7 @@ export default {
7982
},
8083
8184
data() {
82-
return new AppState(window.location.hash.slice(1))
85+
return new AppState(location.hash.slice(1))
8386
},
8487
8588
computed: {
@@ -140,11 +143,15 @@ export default {
140143
},
141144
142145
onUrlHashChange() {
143-
this.$data.deserialize(window.location.hash.slice(1))
146+
this.$data.deserialize(location.hash.slice(1))
144147
},
145148
146149
applyUrlHash() {
147-
window.location.replace(`#${this.$data.serialize()}`)
150+
location.replace(`#${this.$data.serialize()}`)
151+
},
152+
153+
reload() {
154+
location.reload(false)
148155
},
149156
},
150157
}
@@ -234,15 +241,44 @@ a:hover {
234241
flex-shrink: 0;
235242
border-top: 1px solid #CCC;
236243
}
237-
.app__footer-message {
238-
flex-grow: 1;
239-
color: #B71C1C;
240-
}
241244
.app__version-item {
242245
flex-shrink: 0;
243246
margin-right: 8px;
244247
}
245248
.app__version-item:not(:last-child)::after {
246249
content: ","
247250
}
251+
252+
.app__update-ready-toast {
253+
display: block;
254+
position: absolute;
255+
right: 24px;
256+
bottom: 32px;
257+
width: 320px;
258+
padding: 8px;
259+
border: 1px solid #4CAF50;
260+
border-radius: 3px;
261+
background: white;
262+
box-shadow: 0 4px 16px rgba(0,0,0, 0.5);
263+
text-align: center;
264+
animation: AppToastIn 0.333s;
265+
}
266+
.app__update-ready-toast > div {
267+
text-align: left;
268+
}
269+
.app__update-ready-toast > button {
270+
margin-top: 8px;
271+
padding: 4px 32px;
272+
}
273+
274+
@keyframes AppToastIn {
275+
0% {
276+
opacity: 0;
277+
transform: translate(0, 50%) scale(0.5);
278+
}
279+
100% {
280+
opacity: 1;
281+
transform: none;
282+
}
283+
}
248284
</style>

src/index.html

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -146,20 +146,6 @@
146146
}
147147
})(SplashScreen, MainContent)
148148

149-
// Check update.
150-
window.addEventListener("load", function() {
151-
applicationCache.addEventListener("updateready", function() {
152-
if (applicationCache.status == applicationCache.UPDATEREADY) {
153-
applicationCache.swapCache()
154-
155-
var footer = document.querySelector(".app__footer-message")
156-
if (footer) {
157-
footer.textContent = "Please reload because a new version of this site is available."
158-
}
159-
}
160-
})
161-
})
162-
163149
// Show loading error.
164150
window.onerror = function onLoadError() {
165151
MainContent.innerHTML = "Failed to load. Please ensure you are using a browser which supports ES2015."

src/index.js

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
11
import Vue from "vue"
22
import App from "./app.vue"
33

4-
new Vue({
5-
render: (h) => h(App),
6-
}).$mount("#main")
4+
const app = new Vue({
5+
computed: {
6+
updateReady: {
7+
get() {
8+
return this.$refs.app.showUpdateReadyToast
9+
},
10+
set(value) {
11+
this.$refs.app.showUpdateReadyToast = value
12+
},
13+
},
14+
},
15+
render: (h) => h(App, { ref: "app" }),
16+
})
17+
app.$mount("#main")
18+
19+
// Check update.
20+
window.addEventListener("load", () => {
21+
applicationCache.addEventListener("updateready", () => {
22+
if (applicationCache.status === applicationCache.UPDATEREADY) {
23+
app.updateReady = true
24+
}
25+
})
26+
})

0 commit comments

Comments
 (0)