Skip to content

Commit 5c9437d

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

File tree

2 files changed

+43
-11
lines changed

2 files changed

+43
-11
lines changed
Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,50 @@
1-
import { DatasourceController } from "@mendix/widget-plugin-grid/query/DatasourceController";
21
import { computed, makeObservable } from "mobx";
32

3+
type DerivedLoaderControllerSpec = {
4+
showSilentRefresh: boolean;
5+
refreshIndicator: boolean;
6+
query: {
7+
isFetchingNextBatch: boolean;
8+
isFirstLoad: boolean;
9+
isRefreshing: boolean;
10+
isSilentRefresh: boolean;
11+
};
12+
};
13+
414
export class DerivedLoaderController {
5-
constructor(
6-
private datasourceController: DatasourceController,
7-
private refreshIndicator: boolean
8-
) {
15+
constructor(private spec: DerivedLoaderControllerSpec) {
916
makeObservable(this, {
10-
isRefreshing: computed,
11-
showRefreshIndicator: computed
17+
isFirstLoad: computed,
18+
isFetchingNextBatch: computed,
19+
isRefreshing: computed
1220
});
1321
}
1422

23+
get isFirstLoad(): boolean {
24+
const { query } = this.spec;
25+
26+
return query.isFirstLoad;
27+
}
28+
29+
get isFetchingNextBatch(): boolean {
30+
return this.spec.query.isFetchingNextBatch;
31+
}
32+
1533
get isRefreshing(): boolean {
16-
const { isSilentRefresh, isRefreshing } = this.datasourceController;
34+
const { isSilentRefresh, isRefreshing } = this.spec.query;
35+
36+
if (this.spec.showSilentRefresh) {
37+
return isSilentRefresh || isRefreshing;
38+
}
39+
1740
return !isSilentRefresh && isRefreshing;
1841
}
1942

2043
get showRefreshIndicator(): boolean {
21-
return this.refreshIndicator && this.isRefreshing;
44+
if (!this.spec.refreshIndicator) {
45+
return false;
46+
}
47+
48+
return this.isRefreshing;
2249
}
2350
}

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

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

4243
export type GalleryPropsGate = DerivedPropsGate<DynamicProps>;
@@ -99,10 +100,14 @@ export class GalleryStore extends BaseControllerHost {
99100
host: this._sortHost
100101
};
101102

102-
this.loaderCtrl = new DerivedLoaderController(this._query, spec.refreshIndicator);
103+
this.loaderCtrl = new DerivedLoaderController({
104+
showSilentRefresh: spec.refreshInterval > 1,
105+
refreshIndicator: spec.refreshIndicator,
106+
query: this._query
107+
});
103108

104109
new RefreshController(this, {
105-
delay: 0,
110+
delay: spec.refreshInterval * 1000,
106111
query: this._query.derivedQuery
107112
});
108113

0 commit comments

Comments
 (0)