Skip to content

Commit

Permalink
feat(ui): git FileDiff auto-refresh on page focus
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Chau committed Mar 27, 2018
1 parent 2b0ac9f commit 794910b
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 4 deletions.
26 changes: 22 additions & 4 deletions packages/@vue/cli-ui/src/components/FileDiffView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,12 @@
</template>
</div>

<VueLoadingIndicator
v-if="loading"
class="overlay"
/>
<transition name="vue-ui-fade">
<VueLoadingIndicator
v-if="loading"
class="overlay"
/>
</transition>

<VueModal
v-if="showCommitModal"
Expand Down Expand Up @@ -108,10 +110,16 @@
</template>

<script>
import PageVisibility from '../mixins/PageVisibility'
import FILE_DIFFS from '../graphql/fileDiffs.gql'
import GIT_COMMIT from '../graphql/gitCommit.gql'
export default {
mixins: [
PageVisibility
],
data () {
return {
fileDiffs: [],
Expand Down Expand Up @@ -151,6 +159,14 @@ export default {
}
},
watch: {
documentFocus (value) {
if (value) {
this.refresh()
}
}
},
methods: {
setCollapsedToAll (value) {
const map = {}
Expand Down Expand Up @@ -180,6 +196,8 @@ export default {
message: this.commitMessage
}
})
this.showCommitModal = false
this.refresh()
this.$emit('continue')
} catch (e) {
console.error(e)
Expand Down
33 changes: 33 additions & 0 deletions packages/@vue/cli-ui/src/mixins/PageVisibility.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import Vue from 'vue'

const vm = new Vue({
data: {
documentVisible: !document.hidden,
documentFocus: document.hasFocus()
}
})

document.addEventListener('visibilitychange', () => {
vm.documentVisible = !document.hidden
}, false)

window.addEventListener('focus', () => {
vm.documentFocus = true
})

window.addEventListener('blur', () => {
vm.documentFocus = false
})

// @vue/component
export default {
computed: {
documentVisible () {
return vm.documentVisible
},

documentFocus () {
return vm.documentFocus
}
}
}

0 comments on commit 794910b

Please sign in to comment.