@vonaffenfels/contentful-teasermanager 1.0.6 → 1.0.8
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.
- package/package.json +2 -2
- package/src/components/Teasermanager.js +27 -9
- package/src/lib/runLoaders.js +38 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vonaffenfels/contentful-teasermanager",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"prepublish": "yarn run build",
|
|
6
6
|
"dev": "yarn run start",
|
|
@@ -99,7 +99,7 @@
|
|
|
99
99
|
"@vonaffenfels/slate-editor": "^1.0.5",
|
|
100
100
|
"webpack": "5.73.0"
|
|
101
101
|
},
|
|
102
|
-
"gitHead": "
|
|
102
|
+
"gitHead": "93ecd9a3fd0bc3e7d14a80b1138d1934d505d032",
|
|
103
103
|
"publishConfig": {
|
|
104
104
|
"access": "public"
|
|
105
105
|
}
|
|
@@ -5,11 +5,18 @@ import Renderer from "@vonaffenfels/slate-editor/dist/Renderer";
|
|
|
5
5
|
import componentLoader from "@vonaffenfels/slate-editor/componentLoader";
|
|
6
6
|
import {Timeline} from "./Teasermanager/Timeline";
|
|
7
7
|
import styles from "./Teasermanager.module.css";
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
import {runLoaders} from "../lib/runLoaders"
|
|
9
|
+
|
|
10
|
+
export const Teasermanager = ({
|
|
11
|
+
entryId,
|
|
12
|
+
onSlotClick = () => console.error("missing onSlotClick"),
|
|
13
|
+
contentFieldName = "content",
|
|
14
|
+
locale = "de",
|
|
15
|
+
}) => {
|
|
10
16
|
const contentfulClient = getContentfulClient();
|
|
11
17
|
const [entry, setEntry] = useState(null);
|
|
12
18
|
const wrapperRef = useRef(null);
|
|
19
|
+
const [loadedContent, setLoadedContent] = useState(null);
|
|
13
20
|
const [currentDate, setCurrentDate] = useState(null);
|
|
14
21
|
|
|
15
22
|
const initSlot = (node) => {
|
|
@@ -65,17 +72,28 @@ export const Teasermanager = ({entryId, onSlotClick = () => console.error("missi
|
|
|
65
72
|
}
|
|
66
73
|
}, [wrapperRef, currentDate]);
|
|
67
74
|
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
const contentValue = entry?.fields?.[contentFieldName]?.[locale];
|
|
77
|
+
const portalValue = entry?.fields?.portal?.[locale];
|
|
78
|
+
|
|
79
|
+
if (!contentValue) {
|
|
80
|
+
return setLoadedContent(null);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
runLoaders(contentValue, portalValue).then(setLoadedContent);
|
|
84
|
+
}, [contentFieldName, locale, entry]);
|
|
85
|
+
|
|
68
86
|
return <div className="w-full flex flex-col">
|
|
69
87
|
<div className="w-full">
|
|
70
|
-
<Timeline currentDate={currentDate} setCurrentDate={setCurrentDate}
|
|
88
|
+
<Timeline currentDate={currentDate} setCurrentDate={setCurrentDate}/>
|
|
71
89
|
</div>
|
|
72
90
|
<div className={styles.wrapper} ref={wrapperRef}>
|
|
73
|
-
{!!
|
|
91
|
+
{!!loadedContent &&
|
|
74
92
|
<Renderer
|
|
75
|
-
value={
|
|
76
|
-
storybookComponentLoader={componentLoader}
|
|
93
|
+
value={loadedContent}
|
|
94
|
+
storybookComponentLoader={componentLoader}
|
|
95
|
+
/>
|
|
96
|
+
}
|
|
77
97
|
</div>
|
|
78
|
-
|
|
79
98
|
</div>
|
|
80
|
-
|
|
81
|
-
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export const runLoaders = async (value, portal) => {
|
|
2
|
+
if (!Array.isArray(value)) {
|
|
3
|
+
return value;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
const newValue = await Promise.all(value.map(async (item) => {
|
|
7
|
+
try {
|
|
8
|
+
return await runLoader(item, portal)
|
|
9
|
+
} catch (e) {
|
|
10
|
+
console.error(e);
|
|
11
|
+
return item;
|
|
12
|
+
}
|
|
13
|
+
}));
|
|
14
|
+
|
|
15
|
+
return newValue;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const runLoader = async (item, portal) => {
|
|
19
|
+
|
|
20
|
+
if (!item?.block) {
|
|
21
|
+
return item;
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
const response = await fetch(`/api/loader/?portal=${portal}&block=${item.block}&variables=${JSON.stringify(item.attributes)}`).then(res => res.json());
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
...item,
|
|
28
|
+
attributes: {
|
|
29
|
+
...(item.attributes || {}),
|
|
30
|
+
...response,
|
|
31
|
+
},
|
|
32
|
+
}
|
|
33
|
+
} catch (e) {
|
|
34
|
+
console.error(e);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return item;
|
|
38
|
+
}
|