@etsoo/materialui 1.2.56 → 1.2.58

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -73,6 +73,10 @@ export interface ViewPageProps<T extends DataTypes.StringRecord> extends Omit<Co
73
73
  * Grid container reference
74
74
  */
75
75
  gridRef?: React.Ref<HTMLDivElement>;
76
+ /**
77
+ * Refresh seed
78
+ */
79
+ refreshSeed?: number;
76
80
  }
77
81
  /**
78
82
  * View page
@@ -78,7 +78,7 @@ function getItemField(field, data) {
78
78
  */
79
79
  export function ViewPage(props) {
80
80
  // Destruct
81
- const { actions, children, fields, loadData, paddings = MUGlobal.pagePaddings, spacing = MUGlobal.half(MUGlobal.pagePaddings), supportRefresh = true, fabColumnDirection = true, fabTop = true, supportBack = true, pullToRefresh = true, gridRef, ...rest } = props;
81
+ const { actions, children, fields, loadData, paddings = MUGlobal.pagePaddings, spacing = MUGlobal.half(MUGlobal.pagePaddings), supportRefresh = true, fabColumnDirection = true, fabTop = true, supportBack = true, pullToRefresh = true, gridRef, refreshSeed = 0, ...rest } = props;
82
82
  // Data
83
83
  const [data, setData] = React.useState();
84
84
  // Labels
@@ -86,12 +86,18 @@ export function ViewPage(props) {
86
86
  // Container
87
87
  const pullContainer = "#page-container";
88
88
  // Load data
89
- const refresh = async () => {
89
+ const refresh = React.useCallback(async () => {
90
90
  const result = await loadData();
91
91
  if (result == null)
92
92
  return;
93
93
  setData(result);
94
- };
94
+ }, [loadData]);
95
+ React.useEffect(() => {
96
+ // Only refresh after the first data load
97
+ if (refreshSeed === 0 || data == null)
98
+ return;
99
+ refresh();
100
+ }, [refreshSeed]);
95
101
  return (React.createElement(CommonPage, { paddings: paddings, onRefresh: supportRefresh ? refresh : undefined, onUpdate: supportRefresh ? undefined : refresh, ...rest, scrollContainer: globalThis, fabColumnDirection: fabColumnDirection, fabTop: fabTop, supportBack: supportBack }, data == null ? (React.createElement(LinearProgress, null)) : (React.createElement(React.Fragment, null,
96
102
  React.createElement(Grid, { container: true, justifyContent: "left", spacing: spacing, className: "ET-ViewPage", ref: gridRef, sx: {
97
103
  ".MuiTypography-subtitle2": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/materialui",
3
- "version": "1.2.56",
3
+ "version": "1.2.58",
4
4
  "description": "TypeScript Material-UI Implementation",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -52,7 +52,7 @@
52
52
  "@emotion/styled": "^11.11.0",
53
53
  "@etsoo/appscript": "^1.4.19",
54
54
  "@etsoo/notificationbase": "^1.1.25",
55
- "@etsoo/react": "^1.6.90",
55
+ "@etsoo/react": "^1.6.92",
56
56
  "@etsoo/shared": "^1.2.5",
57
57
  "@mui/icons-material": "^5.11.16",
58
58
  "@mui/material": "^5.13.5",
@@ -115,6 +115,11 @@ export interface ViewPageProps<T extends DataTypes.StringRecord>
115
115
  * Grid container reference
116
116
  */
117
117
  gridRef?: React.Ref<HTMLDivElement>;
118
+
119
+ /**
120
+ * Refresh seed
121
+ */
122
+ refreshSeed?: number;
118
123
  }
119
124
 
120
125
  function formatItemData(fieldData: unknown): string | undefined {
@@ -214,6 +219,7 @@ export function ViewPage<T extends DataTypes.StringRecord>(
214
219
  supportBack = true,
215
220
  pullToRefresh = true,
216
221
  gridRef,
222
+ refreshSeed = 0,
217
223
  ...rest
218
224
  } = props;
219
225
 
@@ -227,11 +233,17 @@ export function ViewPage<T extends DataTypes.StringRecord>(
227
233
  const pullContainer = "#page-container";
228
234
 
229
235
  // Load data
230
- const refresh = async () => {
236
+ const refresh = React.useCallback(async () => {
231
237
  const result = await loadData();
232
238
  if (result == null) return;
233
239
  setData(result);
234
- };
240
+ }, [loadData]);
241
+
242
+ React.useEffect(() => {
243
+ // Only refresh after the first data load
244
+ if (refreshSeed === 0 || data == null) return;
245
+ refresh();
246
+ }, [refreshSeed]);
235
247
 
236
248
  return (
237
249
  <CommonPage