From 4b88f70c9aa4fb1d97d34c863e9748c97916dca3 Mon Sep 17 00:00:00 2001 From: vato007 Date: Thu, 24 Apr 2025 18:54:02 +0930 Subject: [PATCH] Fix initial load, remove fixed todos --- src/app/file-viewer/file-viewer.component.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/app/file-viewer/file-viewer.component.ts b/src/app/file-viewer/file-viewer.component.ts index d9323c1..9e97859 100644 --- a/src/app/file-viewer/file-viewer.component.ts +++ b/src/app/file-viewer/file-viewer.component.ts @@ -1,5 +1,6 @@ import { ChangeDetectionStrategy, + ChangeDetectorRef, Component, computed, effect, @@ -67,6 +68,7 @@ export class FileViewerComponent { file = input(); 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([]); @@ -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(); } } }