Commit d51aefdd authored by Konrad Mohrfeldt's avatar Konrad Mohrfeldt

implement custom pull-to-refresh. fixes #9

parent eed0ed6b
......@@ -18,11 +18,47 @@
</template>
<script>
import { debounce } from 'throttle-debounce'
import { createQueryString } from '../../util'
import { decodeHash, manipulateHash } from '../../util/encoder'
const getQueryString = url => url ? new URL(url).search.substring(1) : null
const pullRefreshController = (() => {
let startY
const refresh = debounce(350, false, () => {
for (const paginator of paginators) {
paginator.collection.clearCache()
paginator.reset()
}
})
document.body.addEventListener('touchstart', e => {
startY = e.touches[0].pageY
}, { passive: true })
document.body.addEventListener('touchmove', e => {
const y = e.touches[0].pageY
if (document.scrollingElement.scrollTop === 0 && y > startY) {
refresh()
}
}, { passive: true })
const paginators = []
return {
add (paginator) {
paginators.push(paginator)
},
remove (paginator) {
const index = paginators.indexOf(paginator)
if (index !== -1) {
paginators.splice(index, 1)
}
}
}
})()
export default {
props: {
collection: {
......@@ -167,6 +203,10 @@
created () {
const hashData = decodeHash(this.$route.hash.substring(1))
this.reset(this.id && hashData[this.id] ? parseInt(hashData[this.id]) : null)
pullRefreshController.add(this)
},
beforeDestroy () {
pullRefreshController.remove(this)
},
watch: {
allFilters: {
......
......@@ -35,6 +35,7 @@ body {
overflow-y: scroll;
color: white;
padding-top: calc(var(--screen-top-padding) * 1.25);
overscroll-behavior-y: contain;
}
[href],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment