Skip to content

Commit ce2de11

Browse files
feat(gallery-web): update derived loader controller to use refresh interval
1 parent ee646d6 commit ce2de11

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

packages/pluggableWidgets/gallery-web/src/controllers/DerivedLoaderController.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,39 @@ import { computed, makeObservable } from "mobx";
44
export class DerivedLoaderController {
55
constructor(
66
private datasourceService: DatasourceService,
7-
private refreshIndicator: boolean
7+
private refreshIndicator: boolean,
8+
private showSilentRefresh: boolean
89
) {
910
makeObservable(this, {
10-
isRefreshing: computed,
11-
showRefreshIndicator: computed
11+
isFirstLoad: computed,
12+
isFetchingNextBatch: computed,
13+
isRefreshing: computed
1214
});
1315
}
1416

17+
get isFirstLoad(): boolean {
18+
return this.datasourceService.isFirstLoad;
19+
}
20+
21+
get isFetchingNextBatch(): boolean {
22+
return this.datasourceService.isFetchingNextBatch;
23+
}
24+
1525
get isRefreshing(): boolean {
1626
const { isSilentRefresh, isRefreshing } = this.datasourceService;
27+
28+
if (this.showSilentRefresh) {
29+
return isSilentRefresh || isRefreshing;
30+
}
31+
1732
return !isSilentRefresh && isRefreshing;
1833
}
1934

2035
get showRefreshIndicator(): boolean {
21-
return this.refreshIndicator && this.isRefreshing;
36+
if (!this.refreshIndicator) {
37+
return false;
38+
}
39+
40+
return this.isRefreshing;
2241
}
2342
}

packages/pluggableWidgets/gallery-web/src/stores/GalleryStore.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ interface StaticProps {
3636
storeFilters: boolean;
3737
storeSort: boolean;
3838
refreshIndicator: boolean;
39+
refreshInterval: number;
3940
}
4041

4142
export type GalleryPropsGate = DerivedPropsGate<DynamicProps>;
@@ -63,7 +64,7 @@ export class GalleryStore extends SetupHost {
6364

6465
this.name = spec.name;
6566

66-
this._query = new DatasourceService(this, spec.gate, 0 * 1000);
67+
this._query = new DatasourceService(this, spec.gate, spec.refreshInterval * 1000);
6768

6869
this.paging = new PaginationController({
6970
query: this._query,
@@ -95,7 +96,11 @@ export class GalleryStore extends SetupHost {
9596
host: this._sortHost
9697
};
9798

98-
this.loaderCtrl = new DerivedLoaderController(this._query, spec.refreshIndicator);
99+
this.loaderCtrl = new DerivedLoaderController({
100+
showSilentRefresh: spec.refreshInterval > 1,
101+
refreshIndicator: spec.refreshIndicator,
102+
query: this._query
103+
});
99104

100105
const useStorage = spec.storeFilters || spec.storeSort;
101106
if (useStorage) {

0 commit comments

Comments
 (0)