Skip to content

Commit

Permalink
fix(List): fix initial loading also visible on reload
Browse files Browse the repository at this point in the history
  • Loading branch information
mfal committed Nov 15, 2024
1 parent 80449fa commit 524fc26
Showing 1 changed file with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { times } from "remeda";
import { IncrementalLoaderState } from "@/components/List/model/loading/IncrementalLoaderState";
import { hash } from "object-code";

type AsyncResourceLoadingState = AsyncResource["state"]["value"];

const emptyData: never[] = [];

export class IncrementalLoader<T> {
Expand Down Expand Up @@ -97,14 +99,26 @@ export class IncrementalLoader<T> {
asyncResource: AsyncResource<DataLoaderResult<T>>,
batchIndex: number,
): void {
const skipReloadState = (
newState: AsyncResourceLoadingState,
): AsyncResourceLoadingState => {
if (this.loaderState.dataBatches[batchIndex]?.length > 0) {
return "loaded";
}
return newState;
};

useEffect(() => {
this.loaderState.setBatchLoadingState(
batchIndex,
asyncResource.state.value,
skipReloadState(asyncResource.state.value),
);

return asyncResource.state.observe((newState) => {
this.loaderState.setBatchLoadingState(batchIndex, newState);
this.loaderState.setBatchLoadingState(
batchIndex,
skipReloadState(newState),
);
});
}, [asyncResource, batchIndex]);
}
Expand Down

0 comments on commit 524fc26

Please sign in to comment.