Fix initial load, remove fixed todos

This commit is contained in:
2025-04-24 18:54:02 +09:30
parent 42e9470400
commit 4b88f70c9a

View File

@@ -1,5 +1,6 @@
import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
computed,
effect,
@@ -67,6 +68,7 @@ export class FileViewerComponent {
file = input<File | undefined>();
private duckdbService = inject(DuckdbService);
private cdr = inject(ChangeDetectorRef);
// Can't be computed since effect has to run first so file exists in duckdb
protected columns = signal<Column[]>([]);
@@ -95,16 +97,11 @@ export class FileViewerComponent {
[],
);
const newValue = Array.from({ length: Number(rows.totalRows) });
newValue.splice(0, 100, ...rows.rows);
this.currentValue.set(newValue);
}
// TODO: Refresh table? Or is this automatic when columns change?
// this.table().
//TODO: Get rows in file
});
}
// TODO: Getting an infinite loop
protected async onLazyLoad(event: TableLazyLoadEvent) {
const file = this.file();
if (file) {
@@ -116,10 +113,11 @@ export class FileViewerComponent {
[],
[],
);
if (!this.currentValue()) {
this.currentValue.set(Array.from({ length: Number(rows.totalRows) }));
}
// First clear out existing data, don't want to risk loading entire file into memory
this.currentValue().fill(undefined);
// Can't update the current value, otherwise we get an infinite loop
this.currentValue().splice(event.first!, event.rows!, ...rows.rows);
this.cdr.markForCheck();
}
}
}