Skip to content

Commit 794910b

Browse files
author
Guillaume Chau
committed
feat(ui): git FileDiff auto-refresh on page focus
1 parent 2b0ac9f commit 794910b

File tree

2 files changed

+55
-4
lines changed

2 files changed

+55
-4
lines changed

packages/@vue/cli-ui/src/components/FileDiffView.vue

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,12 @@
6464
</template>
6565
</div>
6666

67-
<VueLoadingIndicator
68-
v-if="loading"
69-
class="overlay"
70-
/>
67+
<transition name="vue-ui-fade">
68+
<VueLoadingIndicator
69+
v-if="loading"
70+
class="overlay"
71+
/>
72+
</transition>
7173

7274
<VueModal
7375
v-if="showCommitModal"
@@ -108,10 +110,16 @@
108110
</template>
109111

110112
<script>
113+
import PageVisibility from '../mixins/PageVisibility'
114+
111115
import FILE_DIFFS from '../graphql/fileDiffs.gql'
112116
import GIT_COMMIT from '../graphql/gitCommit.gql'
113117
114118
export default {
119+
mixins: [
120+
PageVisibility
121+
],
122+
115123
data () {
116124
return {
117125
fileDiffs: [],
@@ -151,6 +159,14 @@ export default {
151159
}
152160
},
153161
162+
watch: {
163+
documentFocus (value) {
164+
if (value) {
165+
this.refresh()
166+
}
167+
}
168+
},
169+
154170
methods: {
155171
setCollapsedToAll (value) {
156172
const map = {}
@@ -180,6 +196,8 @@ export default {
180196
message: this.commitMessage
181197
}
182198
})
199+
this.showCommitModal = false
200+
this.refresh()
183201
this.$emit('continue')
184202
} catch (e) {
185203
console.error(e)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import Vue from 'vue'
2+
3+
const vm = new Vue({
4+
data: {
5+
documentVisible: !document.hidden,
6+
documentFocus: document.hasFocus()
7+
}
8+
})
9+
10+
document.addEventListener('visibilitychange', () => {
11+
vm.documentVisible = !document.hidden
12+
}, false)
13+
14+
window.addEventListener('focus', () => {
15+
vm.documentFocus = true
16+
})
17+
18+
window.addEventListener('blur', () => {
19+
vm.documentFocus = false
20+
})
21+
22+
// @vue/component
23+
export default {
24+
computed: {
25+
documentVisible () {
26+
return vm.documentVisible
27+
},
28+
29+
documentFocus () {
30+
return vm.documentFocus
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)