allows scrolling backwards through history

This commit is contained in:
2025-01-05 10:52:09 -05:00
parent 32fcbbd916
commit 2cb1eec404
11 changed files with 214 additions and 87 deletions

View File

@@ -3,6 +3,7 @@ import {
type MaybeRefOrGetter,
onMounted,
onUnmounted,
onWatcherCleanup,
ref,
type Ref,
shallowRef,
@@ -95,6 +96,7 @@ export class WebsocketHandle {
listen_to_telemetry(
telemetry: MaybeRefOrGetter<TelemetryDefinition | null>,
minimum_separation_ms: MaybeRefOrGetter<number> | undefined,
live: MaybeRefOrGetter<boolean>,
) {
const value_result = ref<TelemetryDataItem | null>(null);
@@ -114,10 +116,12 @@ export class WebsocketHandle {
return 0;
});
const is_live = computed(() => toValue(live));
watch(
[uuid, this.connected, minimum_separation],
([uuid_value, connected, min_sep]) => {
if (connected && uuid_value) {
[uuid, this.connected, minimum_separation, is_live],
([uuid_value, connected, min_sep, live_value]) => {
if (connected && uuid_value && live_value) {
this.websocket?.send(
JSON.stringify({
RegisterTlmListener: {
@@ -129,8 +133,26 @@ export class WebsocketHandle {
if (!this.on_telem_value.has(uuid_value)) {
this.on_telem_value.set(uuid_value, []);
}
this.on_telem_value.get(uuid_value)?.push((value) => {
const callback_fn = (value: TelemetryDataItem) => {
value_result.value = value;
};
this.on_telem_value.get(uuid_value)?.push(callback_fn);
onWatcherCleanup(() => {
this.websocket?.send(
JSON.stringify({
UnregisterTlmListener: {
uuid: uuid_value,
},
}),
);
const index = this.on_telem_value
.get(uuid_value)
?.indexOf(callback_fn);
if (index !== undefined && index >= 0) {
this.on_telem_value
.get(uuid_value)
?.splice(index, 1);
}
});
}
},