@admin-layout/client 10.0.9-alpha.58 → 10.0.9-alpha.59
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLayoutSettings.d.ts","sourceRoot":"","sources":["../../src/hooks/useLayoutSettings.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useLayoutSettings.d.ts","sourceRoot":"","sources":["../../src/hooks/useLayoutSettings.ts"],"names":[],"mappings":"AAwBA,eAAO,MAAM,iBAAiB;;0BA2CP,GAAG;CA6CzB,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {useEffect,useCallback}from'react';import {useDispatch,useSelector}from'react-redux';import {CHANGE_SETTINGS_ACTION}from'../constants/constants.js';const updateColorWeak = (colorWeak) => {
|
|
1
|
+
import {useEffect,useCallback}from'react';import {useDispatch,useSelector}from'react-redux';import {merge,transform,isEqual,isObject}from'lodash-es';import {defaultSettings}from'../config/defaultSettings.js';import {CHANGE_SETTINGS_ACTION}from'../constants/constants.js';const updateColorWeak = (colorWeak) => {
|
|
2
2
|
// @sri to avoid breaking during SSR, split into to checks
|
|
3
3
|
if (typeof window !== 'undefined') {
|
|
4
4
|
const root = document.getElementById('root');
|
|
@@ -7,6 +7,13 @@ import {useEffect,useCallback}from'react';import {useDispatch,useSelector}from'r
|
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
9
|
};
|
|
10
|
+
const getDifference = (obj1, obj2) => {
|
|
11
|
+
return transform(obj1, (result, value, key) => {
|
|
12
|
+
if (!isEqual(value, obj2[key])) {
|
|
13
|
+
result[key] = isObject(value) && isObject(obj2[key]) ? getDifference(value, obj2[key]) : value;
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
};
|
|
10
17
|
const useLayoutSettings = () => {
|
|
11
18
|
const dispatch = useDispatch();
|
|
12
19
|
const settings = useSelector((state) => state.settings);
|
|
@@ -33,30 +40,34 @@ const useLayoutSettings = () => {
|
|
|
33
40
|
if (!response.ok) {
|
|
34
41
|
throw new Error('Failed to fetch settings');
|
|
35
42
|
}
|
|
36
|
-
const
|
|
37
|
-
|
|
43
|
+
const diffSettings = await response.json();
|
|
44
|
+
// Merge the differences with default settings
|
|
45
|
+
const mergedSettings = merge({}, defaultSettings, diffSettings);
|
|
46
|
+
return mergedSettings;
|
|
38
47
|
}
|
|
39
48
|
catch (error) {
|
|
40
49
|
console.error(error);
|
|
41
|
-
|
|
50
|
+
// Return default settings if there's an error
|
|
51
|
+
return defaultSettings;
|
|
42
52
|
}
|
|
43
53
|
}, []);
|
|
44
54
|
const setSettings = useCallback(async (config) => {
|
|
45
55
|
const { colorWeak, contentWidth } = config;
|
|
46
56
|
try {
|
|
47
|
-
// @sri to avoid breaking during SSR, split into to checks
|
|
48
57
|
if (settings.contentWidth !== contentWidth) {
|
|
49
58
|
if (typeof window !== 'undefined') {
|
|
50
59
|
window.dispatchEvent(new Event('resize'));
|
|
51
60
|
}
|
|
52
61
|
}
|
|
53
62
|
updateColorWeak(!!colorWeak);
|
|
63
|
+
// Get only the differences between the new config and default settings
|
|
64
|
+
const diffConfig = getDifference(config, defaultSettings);
|
|
54
65
|
const response = await fetch('/resources/settings', {
|
|
55
66
|
method: 'POST',
|
|
56
67
|
headers: {
|
|
57
68
|
'Content-Type': 'application/json',
|
|
58
69
|
},
|
|
59
|
-
body: JSON.stringify({ config }),
|
|
70
|
+
body: JSON.stringify({ config: diffConfig }),
|
|
60
71
|
});
|
|
61
72
|
if (!response.ok) {
|
|
62
73
|
throw new Error('Failed to update settings');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLayoutSettings.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useLayoutSettings.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@admin-layout/client",
|
|
3
|
-
"version": "10.0.9-alpha.
|
|
3
|
+
"version": "10.0.9-alpha.59",
|
|
4
4
|
"description": "Sample client for higher packages to depend on",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "CDMBase LLC",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"publishConfig": {
|
|
38
38
|
"access": "public"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "0ec2dd288c00e0abcd1b0e9a8738c9d9eb1050da",
|
|
41
41
|
"typescript": {
|
|
42
42
|
"definition": "lib/index.d.ts"
|
|
43
43
|
}
|