experiment with storing heights in vuex
This commit is contained in:
parent
232e36cf43
commit
68153f0ce9
3 changed files with 20 additions and 7 deletions
|
@ -35,9 +35,7 @@ const conversation = {
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
highlight: null,
|
highlight: null,
|
||||||
expanded: false,
|
expanded: false
|
||||||
// Approximate minimum height of a status, gets overwritten with real one
|
|
||||||
virtualHeight: '120px'
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
props: [
|
props: [
|
||||||
|
@ -114,7 +112,8 @@ const conversation = {
|
||||||
return this.expanded || this.isPage
|
return this.expanded || this.isPage
|
||||||
},
|
},
|
||||||
hiddenStyle () {
|
hiddenStyle () {
|
||||||
return this.virtualHidden ? { height: this.virtualHeight } : {}
|
const height = this.status.virtualHeight || '120px'
|
||||||
|
return this.virtualHidden ? { height } : {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
|
@ -136,7 +135,10 @@ const conversation = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
virtualHidden (value) {
|
virtualHidden (value) {
|
||||||
this.virtualHeight = `${this.$el.clientHeight}px`
|
this.$store.dispatch(
|
||||||
|
'setVirtualHeight',
|
||||||
|
{ statusId: this.statusId, height: `${this.$el.clientHeight}px` }
|
||||||
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
|
|
@ -113,6 +113,7 @@ const Timeline = {
|
||||||
this.unfocused = document.hidden
|
this.unfocused = document.hidden
|
||||||
}
|
}
|
||||||
window.addEventListener('keydown', this.handleShortKey)
|
window.addEventListener('keydown', this.handleShortKey)
|
||||||
|
setTimeout(this.determineVisibleStatuses, 250)
|
||||||
},
|
},
|
||||||
destroyed () {
|
destroyed () {
|
||||||
window.removeEventListener('scroll', this.handleScroll)
|
window.removeEventListener('scroll', this.handleScroll)
|
||||||
|
@ -159,6 +160,8 @@ const Timeline = {
|
||||||
if (!this.$refs.timeline) return
|
if (!this.$refs.timeline) return
|
||||||
if (!this.virtualScrollingEnabled) return
|
if (!this.virtualScrollingEnabled) return
|
||||||
|
|
||||||
|
console.log('determineVisibleStatuses', window.pageYOffset)
|
||||||
|
|
||||||
const statuses = this.$refs.timeline.children
|
const statuses = this.$refs.timeline.children
|
||||||
const cappedScrollIndex = Math.max(0, Math.min(this.virtualScrollIndex, statuses.length - 1))
|
const cappedScrollIndex = Math.max(0, Math.min(this.virtualScrollIndex, statuses.length - 1))
|
||||||
|
|
||||||
|
@ -184,7 +187,7 @@ const Timeline = {
|
||||||
|
|
||||||
// if the status is too far from viewport, check the next/previous ones if
|
// if the status is too far from viewport, check the next/previous ones if
|
||||||
// they happen to be better
|
// they happen to be better
|
||||||
while (err < -100 && approxIndex < statuses.length - 1) {
|
while (err < -20 && approxIndex < statuses.length - 1) {
|
||||||
err += statuses[approxIndex].offsetHeight
|
err += statuses[approxIndex].offsetHeight
|
||||||
approxIndex++
|
approxIndex++
|
||||||
}
|
}
|
||||||
|
@ -196,6 +199,8 @@ const Timeline = {
|
||||||
// this status is now the center point for virtual scrolling and visible
|
// this status is now the center point for virtual scrolling and visible
|
||||||
// statuses will be nearby statuses before and after it
|
// statuses will be nearby statuses before and after it
|
||||||
this.virtualScrollIndex = approxIndex
|
this.virtualScrollIndex = approxIndex
|
||||||
|
console.log('result', statuses[approxIndex], statuses[approxIndex].getBoundingClientRect().y, err)
|
||||||
|
console.log(window.pageYOffset, statuses[approxIndex].offsetTop)
|
||||||
},
|
},
|
||||||
scrollLoad (e) {
|
scrollLoad (e) {
|
||||||
const bodyBRect = document.body.getBoundingClientRect()
|
const bodyBRect = document.body.getBoundingClientRect()
|
||||||
|
@ -210,7 +215,7 @@ const Timeline = {
|
||||||
handleScroll: throttle(function (e) {
|
handleScroll: throttle(function (e) {
|
||||||
this.determineVisibleStatuses()
|
this.determineVisibleStatuses()
|
||||||
this.scrollLoad(e)
|
this.scrollLoad(e)
|
||||||
}, 150),
|
}, 200),
|
||||||
handleVisibilityChange () {
|
handleVisibilityChange () {
|
||||||
this.unfocused = document.hidden
|
this.unfocused = document.hidden
|
||||||
}
|
}
|
||||||
|
|
|
@ -597,6 +597,9 @@ export const mutations = {
|
||||||
updateStatusWithPoll (state, { id, poll }) {
|
updateStatusWithPoll (state, { id, poll }) {
|
||||||
const status = state.allStatusesObject[id]
|
const status = state.allStatusesObject[id]
|
||||||
status.poll = poll
|
status.poll = poll
|
||||||
|
},
|
||||||
|
setVirtualHeight (state, { statusId, height }) {
|
||||||
|
state.allStatusesObject[statusId].virtualHeight = height
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -777,6 +780,9 @@ const statuses = {
|
||||||
store.commit('addNewStatuses', { statuses: data.statuses })
|
store.commit('addNewStatuses', { statuses: data.statuses })
|
||||||
return data
|
return data
|
||||||
})
|
})
|
||||||
|
},
|
||||||
|
setVirtualHeight ({ commit }, { statusId, height }) {
|
||||||
|
commit('setVirtualHeight', { statusId, height })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mutations
|
mutations
|
||||||
|
|
Loading…
Add table
Reference in a new issue