@etsoo/toolpad 1.0.27 → 1.0.28

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.
@@ -28,7 +28,7 @@ export type PageData = {
28
28
  noBreadcrumbs?: boolean;
29
29
  noPageHeader?: boolean;
30
30
  };
31
- type PageDataAction = PageData | true;
31
+ type PageDataAction = PageData;
32
32
  export declare const PageDataContext: React.Context<{
33
33
  state: PageData;
34
34
  dispatch: React.Dispatch<PageDataAction>;
@@ -60,19 +60,18 @@ const PageContentHeader = (0, styles_1.styled)("div")(({ theme }) => ({
60
60
  }));
61
61
  exports.PageDataContext = React.createContext({ state: {}, dispatch: (value) => value });
62
62
  function reducer(state, action) {
63
- if (action === true) {
64
- // Reset the state
65
- if (state.breadcrumbs == null &&
66
- state.title == null &&
67
- state.page == null &&
68
- state.noBreadcrumbs == null &&
69
- state.noPageHeader == null) {
70
- return state;
71
- }
72
- else {
73
- return {};
63
+ // Check if the action is the same as the current state
64
+ let key;
65
+ let isSame = true;
66
+ for (key in action) {
67
+ if (action[key] !== state[key]) {
68
+ isSame = false;
69
+ break;
74
70
  }
75
71
  }
72
+ if (isSame) {
73
+ return state;
74
+ }
76
75
  return { ...state, ...action };
77
76
  }
78
77
  function PageDataContextProvider(props) {
@@ -91,17 +90,15 @@ function PageDataContextProvider(props) {
91
90
  }
92
91
  function PageContainerBar(props) {
93
92
  const { defaultTitle, slots, slotProps } = props;
94
- const loaded = React.useRef(false);
95
93
  const { state, dispatch } = React.useContext(exports.PageDataContext);
96
94
  const activePage = (0, useActivePage_1.useActivePage)();
97
95
  React.useLayoutEffect(() => {
98
- if (loaded.current) {
99
- // Reset the page data state
100
- dispatch(true);
101
- }
102
- else {
103
- loaded.current = true;
104
- }
96
+ // Reset the state when the active page changes without rerendering
97
+ state.breadcrumbs = undefined;
98
+ state.noBreadcrumbs = undefined;
99
+ state.noPageHeader = undefined;
100
+ state.page = undefined;
101
+ state.title = undefined;
105
102
  }, [activePage?.sourcePath]);
106
103
  let resolvedBreadcrumbs = state.breadcrumbs ?? activePage?.breadcrumbs ?? [];
107
104
  const title = state.title ?? defaultTitle ?? activePage?.title ?? "";
@@ -28,7 +28,7 @@ export type PageData = {
28
28
  noBreadcrumbs?: boolean;
29
29
  noPageHeader?: boolean;
30
30
  };
31
- type PageDataAction = PageData | true;
31
+ type PageDataAction = PageData;
32
32
  export declare const PageDataContext: React.Context<{
33
33
  state: PageData;
34
34
  dispatch: React.Dispatch<PageDataAction>;
@@ -19,19 +19,18 @@ const PageContentHeader = styled("div")(({ theme }) => ({
19
19
  }));
20
20
  export const PageDataContext = React.createContext({ state: {}, dispatch: (value) => value });
21
21
  function reducer(state, action) {
22
- if (action === true) {
23
- // Reset the state
24
- if (state.breadcrumbs == null &&
25
- state.title == null &&
26
- state.page == null &&
27
- state.noBreadcrumbs == null &&
28
- state.noPageHeader == null) {
29
- return state;
30
- }
31
- else {
32
- return {};
22
+ // Check if the action is the same as the current state
23
+ let key;
24
+ let isSame = true;
25
+ for (key in action) {
26
+ if (action[key] !== state[key]) {
27
+ isSame = false;
28
+ break;
33
29
  }
34
30
  }
31
+ if (isSame) {
32
+ return state;
33
+ }
35
34
  return { ...state, ...action };
36
35
  }
37
36
  export function PageDataContextProvider(props) {
@@ -50,17 +49,15 @@ export function PageDataContextProvider(props) {
50
49
  }
51
50
  function PageContainerBar(props) {
52
51
  const { defaultTitle, slots, slotProps } = props;
53
- const loaded = React.useRef(false);
54
52
  const { state, dispatch } = React.useContext(PageDataContext);
55
53
  const activePage = useActivePage();
56
54
  React.useLayoutEffect(() => {
57
- if (loaded.current) {
58
- // Reset the page data state
59
- dispatch(true);
60
- }
61
- else {
62
- loaded.current = true;
63
- }
55
+ // Reset the state when the active page changes without rerendering
56
+ state.breadcrumbs = undefined;
57
+ state.noBreadcrumbs = undefined;
58
+ state.noPageHeader = undefined;
59
+ state.page = undefined;
60
+ state.title = undefined;
64
61
  }, [activePage?.sourcePath]);
65
62
  let resolvedBreadcrumbs = state.breadcrumbs ?? activePage?.breadcrumbs ?? [];
66
63
  const title = state.title ?? defaultTitle ?? activePage?.title ?? "";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/toolpad",
3
- "version": "1.0.27",
3
+ "version": "1.0.28",
4
4
  "author": "ETSOO",
5
5
  "description": "Dashboard framework extention based on Toolpad Core",
6
6
  "main": "build/cjs/index.js",
@@ -52,7 +52,7 @@ export type PageData = {
52
52
  noPageHeader?: boolean;
53
53
  };
54
54
 
55
- type PageDataAction = PageData | true;
55
+ type PageDataAction = PageData;
56
56
 
57
57
  export const PageDataContext = React.createContext<{
58
58
  state: PageData;
@@ -60,21 +60,20 @@ export const PageDataContext = React.createContext<{
60
60
  }>({ state: {}, dispatch: (value) => value });
61
61
 
62
62
  function reducer(state: PageData, action: PageDataAction) {
63
- if (action === true) {
64
- // Reset the state
65
- if (
66
- state.breadcrumbs == null &&
67
- state.title == null &&
68
- state.page == null &&
69
- state.noBreadcrumbs == null &&
70
- state.noPageHeader == null
71
- ) {
72
- return state;
73
- } else {
74
- return {};
63
+ // Check if the action is the same as the current state
64
+ let key: keyof PageDataAction;
65
+ let isSame = true;
66
+ for (key in action) {
67
+ if (action[key] !== state[key]) {
68
+ isSame = false;
69
+ break;
75
70
  }
76
71
  }
77
72
 
73
+ if (isSame) {
74
+ return state;
75
+ }
76
+
78
77
  return { ...state, ...action };
79
78
  }
80
79
 
@@ -116,18 +115,17 @@ type PageContainerBarProps = {
116
115
  function PageContainerBar(props: PageContainerBarProps) {
117
116
  const { defaultTitle, slots, slotProps } = props;
118
117
 
119
- const loaded = React.useRef(false);
120
118
  const { state, dispatch } = React.useContext(PageDataContext);
121
119
 
122
120
  const activePage = useActivePage();
123
121
 
124
122
  React.useLayoutEffect(() => {
125
- if (loaded.current) {
126
- // Reset the page data state
127
- dispatch(true);
128
- } else {
129
- loaded.current = true;
130
- }
123
+ // Reset the state when the active page changes without rerendering
124
+ state.breadcrumbs = undefined;
125
+ state.noBreadcrumbs = undefined;
126
+ state.noPageHeader = undefined;
127
+ state.page = undefined;
128
+ state.title = undefined;
131
129
  }, [activePage?.sourcePath]);
132
130
 
133
131
  let resolvedBreadcrumbs = state.breadcrumbs ?? activePage?.breadcrumbs ?? [];