Skip to content

Commit c883a78

Browse files
denishacquinDencristiam86
authored
fix: node logs scrolling behavior (#986)
Co-authored-by: Den <den@Deniss-MacBook-Pro.local> Co-authored-by: Cristiam Da Silva <cristiam86@gmail.com>
1 parent 503a856 commit c883a78

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

frontend/src/components/Simulator/NodeLogs.vue

+22-7
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@ import EmptyListPlaceholder from './EmptyListPlaceholder.vue';
77
import { Ban, SearchIcon, X } from 'lucide-vue-next';
88
import LogFilterBtn from '@/components/Simulator/LogFilterBtn.vue';
99
import TextInput from '../global/inputs/TextInput.vue';
10+
import { useScroll } from '@vueuse/core';
11+
import { useTemplateRef } from 'vue';
1012
1113
const nodeStore = useNodeStore();
1214
const uiStore = useUIStore();
13-
const scrollContainer = ref<HTMLDivElement>();
15+
const scrollContainer = useTemplateRef<HTMLElement>('scrollContainer');
16+
const { y, isScrolling, arrivedState, directions } = useScroll(scrollContainer);
1417
1518
type ColorMapType = {
1619
[key: string]: string;
@@ -23,13 +26,25 @@ const colorMap: ComputedRef<ColorMapType> = computed(() => ({
2326
success: 'text-green-400',
2427
}));
2528
26-
watch(nodeStore.logs, () => {
27-
nextTick(() => {
28-
scrollContainer.value?.scrollTo({
29-
top: scrollContainer.value.scrollHeight,
30-
behavior: 'smooth',
29+
const wasAtBottom = ref(false);
30+
31+
watch(
32+
() => nodeStore.logs.length,
33+
() => {
34+
nextTick(() => {
35+
if (!wasAtBottom.value && scrollContainer.value) {
36+
scrollContainer.value.scrollTop = scrollContainer.value.scrollHeight;
37+
}
3138
});
32-
});
39+
},
40+
);
41+
42+
watch(y, () => {
43+
if (directions.top) {
44+
wasAtBottom.value = true;
45+
} else if (arrivedState.bottom) {
46+
wasAtBottom.value = false;
47+
}
3348
});
3449
3550
const scopes = ref(['RPC', 'GenVM', 'Consensus']);

0 commit comments

Comments
 (0)