@@ -20,7 +20,7 @@ const openJsonModal = (validJson: string) => {
20
20
jsonModal . style . display = "flex" ;
21
21
} ;
22
22
23
- const updateLogTable = ( scrollUp = false ) => {
23
+ const updateLogTable = ( ) => {
24
24
const selectedFilter = filterSelect . value ;
25
25
const filteredLogs = selectedFilter === "all" ? logs : logs . filter ( ( log ) => getLevelString ( log . level ) === selectedFilter ) ;
26
26
@@ -51,12 +51,6 @@ const updateLogTable = (scrollUp = false) => {
51
51
}
52
52
} ) ;
53
53
}
54
- // scroll to last added data
55
- if ( scrollUp ) {
56
- logCell [ 0 ] . scrollIntoView ( ) ;
57
- } else {
58
- logCell [ logCell . length - 1 ] . scrollIntoView ( ) ;
59
- }
60
54
} ) ;
61
55
} ;
62
56
@@ -68,30 +62,32 @@ const fetchData = async () => {
68
62
isLoading = true ;
69
63
70
64
if ( logs . length > 0 ) {
71
- const firstAvailableTimestamp = logs . at ( 0 ) ?. timestamp ;
65
+ const firstAvailableTimestamp = logs . at ( logs . length - 1 ) ?. timestamp ;
72
66
const { data, error } = await supabaseClient
73
67
. from ( "logs" )
74
68
. select ( )
75
69
. lt ( "timestamp" , firstAvailableTimestamp )
76
70
. order ( "timestamp" , { ascending : false } )
77
71
. limit ( 25 ) ;
78
72
if ( data && data . length > 0 ) {
79
- logs . unshift ( ...data . reverse ( ) ) ;
80
- updateLogTable ( true ) ;
73
+ logs . push ( ...data ) ;
74
+ updateLogTable ( ) ;
81
75
} else console . log ( error ) ;
82
76
} else {
83
77
const { data, error } = await supabaseClient . from ( "logs" ) . select ( ) . order ( "timestamp" , { ascending : false } ) . limit ( 30 ) ;
84
78
if ( data && data . length > 0 ) {
85
- logs . push ( ...data . reverse ( ) ) ;
86
- updateLogTable ( true ) ;
79
+ logs . push ( ...data ) ;
80
+ updateLogTable ( ) ;
87
81
} else console . log ( error ) ;
88
82
}
89
83
90
84
isLoading = false ;
91
85
} ;
92
86
93
87
const handleScroll = async ( ) => {
94
- if ( document . documentElement . scrollTop !== 0 || isLoading ) {
88
+ const bottom = document . documentElement . scrollHeight - document . documentElement . scrollTop === document . documentElement . clientHeight ;
89
+
90
+ if ( ! bottom || isLoading ) {
95
91
return ;
96
92
}
97
93
await fetchData ( ) ;
@@ -114,7 +110,7 @@ supabaseClient
114
110
115
111
const handlePayload = ( logEntry : any ) => {
116
112
if ( logEntry ?. eventType !== "INSERT" ) return ;
117
- logs . push ( logEntry . new ) ;
113
+ logs . unshift ( logEntry . new ) ;
118
114
updateLogTable ( ) ;
119
115
} ;
120
116
0 commit comments