feat: scroll logs to the bottom on update
This commit is contained in:
@@ -17,7 +17,7 @@
|
|||||||
{{ title }}
|
{{ title }}
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div name="log" class="realtime-log">
|
<div ref="logsRef" name="log" class="realtime-log">
|
||||||
<span v-if="log" class="space-y-2">
|
<span v-if="log" class="space-y-2">
|
||||||
<span
|
<span
|
||||||
v-for="(entry, index) in log"
|
v-for="(entry, index) in log"
|
||||||
@@ -32,15 +32,33 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import { nextTick, ref, watch } from "@nuxtjs/composition-api"
|
||||||
import { getSourcePrefix as source } from "~/helpers/utils/string"
|
import { getSourcePrefix as source } from "~/helpers/utils/string"
|
||||||
|
|
||||||
defineProps({
|
const props = defineProps({
|
||||||
log: { type: Array, default: () => [] },
|
log: { type: Array, default: () => [] },
|
||||||
title: {
|
title: {
|
||||||
type: String,
|
type: String,
|
||||||
default: "",
|
default: "",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const logsRef = ref<any | null>(null)
|
||||||
|
const BOTTOM_SCROLL_DIST_INNACURACY = 5
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.log,
|
||||||
|
() => {
|
||||||
|
if (!logsRef.value) return
|
||||||
|
const distToBottom =
|
||||||
|
logsRef.value.scrollHeight -
|
||||||
|
logsRef.value.scrollTop -
|
||||||
|
logsRef.value.clientHeight
|
||||||
|
if (distToBottom < BOTTOM_SCROLL_DIST_INNACURACY) {
|
||||||
|
nextTick(() => (logsRef.value.scrollTop = logsRef.value.scrollHeight))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
|
|||||||
Reference in New Issue
Block a user