1
0
mirror of https://github.com/amir20/dozzle.git synced 2025-12-21 21:33:18 +01:00
Files
dozzle/assets/components/ScrollableView.vue
Amir Raminfar c938b2ea1b Fetch more (#209)
* Adds code to fetch more

* Adds working in progress

* Adds debugging test

* Cleans up and creates a new component

* Adds debug logs

* Adds debounce for messages

* Fixes scrolling

* Fixes go code to handle length

* Fixes tests

* Adds loader

* Fixes tests
2019-12-17 14:58:29 -08:00

90 lines
1.9 KiB
Vue

<template lang="html">
<section>
<header v-if="$slots.header">
<slot name="header"></slot>
</header>
<main ref="content" @scroll.passive="onScroll" data-scrolling>
<slot></slot>
</main>
<div class="scroll-bar-notification">
<transition name="fade">
<button
class="button"
:class="hasMore ? 'is-warning' : 'is-primary'"
@click="scrollToBottom('smooth')"
v-show="paused"
>
<span class="icon large"> <i class="fas fa-chevron-down"></i> </span>
</button>
</transition>
</div>
</section>
</template>
<script>
export default {
name: "ScrollableView",
data() {
return {
paused: false,
hasMore: false
};
},
mounted() {
const { content } = this.$refs;
new MutationObserver(e => {
if (!this.paused) {
this.scrollToBottom("instant");
} else {
this.hasMore = true;
}
}).observe(content, { childList: true, subtree: true });
},
methods: {
scrollToBottom(behavior = "instant") {
const { content } = this.$refs;
if (typeof content.scroll === "function") {
content.scroll({ top: content.scrollHeight, behavior });
} else {
content.scrollTop = content.scrollHeight;
}
this.hasMore = false;
},
onScroll(e) {
const { content } = this.$refs;
this.paused = content.scrollTop + content.clientHeight + 1 < content.scrollHeight;
}
}
};
</script>
<style scoped lang="scss">
section {
display: flex;
flex-direction: column;
height: 100vh;
main {
flex: 1;
overflow: auto;
}
.scroll-bar-notification {
text-align: right;
margin-right: 65px;
button {
position: fixed;
bottom: 30px;
}
}
.fade-enter-active,
.fade-leave-active {
transition: opacity 0.15s ease-in;
}
.fade-enter,
.fade-leave-to {
opacity: 0;
}
}
</style>