@vonaffenfels/contentful-teasermanager 1.0.26 → 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.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vonaffenfels/contentful-teasermanager",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.28",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"prepublish": "yarn run build",
|
|
6
6
|
"dev": "yarn run start",
|
|
@@ -96,10 +96,10 @@
|
|
|
96
96
|
"webpack-dev-server": "^4.0.0-beta.2"
|
|
97
97
|
},
|
|
98
98
|
"dependencies": {
|
|
99
|
-
"@vonaffenfels/slate-editor": "^1.0.
|
|
100
|
-
"webpack": "5.
|
|
99
|
+
"@vonaffenfels/slate-editor": "^1.0.28",
|
|
100
|
+
"webpack": "5.88.2"
|
|
101
101
|
},
|
|
102
|
-
"gitHead": "
|
|
102
|
+
"gitHead": "fe5a1e14e437b67a1aa58fa6781b9ae134914750",
|
|
103
103
|
"publishConfig": {
|
|
104
104
|
"access": "public"
|
|
105
105
|
}
|
|
@@ -36,27 +36,32 @@ export const Timeline = ({
|
|
|
36
36
|
setCurrentDate(newDate);
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
-
const handleTimeChange = e => {
|
|
39
|
+
const handleTimeChange = (e, type) => {
|
|
40
40
|
if (!e.target.value) {
|
|
41
41
|
return;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
let newDate = new Date(currentDate);
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
switch (type) {
|
|
47
|
+
case "hour":
|
|
48
|
+
newDate.setHours(e.target.value);
|
|
49
|
+
break;
|
|
50
|
+
case "minute":
|
|
51
|
+
newDate.setMinutes(e.target.value);
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
49
54
|
|
|
50
55
|
setCurrentDate(newDate);
|
|
51
56
|
};
|
|
52
57
|
|
|
53
58
|
return <div className="flex w-full">
|
|
54
59
|
<div className={styles.wrapper}>
|
|
55
|
-
<div className=
|
|
60
|
+
<div className="w-full h-auto text-center py-2">
|
|
56
61
|
{!!currentDate && (
|
|
57
62
|
<>
|
|
58
63
|
<input type="date" value={format(currentDate, "yyyy-MM-dd")} onChange={handleDateChange} className="mr-2 w-auto" />
|
|
59
|
-
<
|
|
64
|
+
<TimeSelect className="inline w-auto" currentDate={currentDate} onChange={handleTimeChange} />
|
|
60
65
|
</>
|
|
61
66
|
)}
|
|
62
67
|
</div>
|
|
@@ -80,4 +85,42 @@ export const Timeline = ({
|
|
|
80
85
|
</div>
|
|
81
86
|
</div>
|
|
82
87
|
</div>;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const TimeSelect = ({
|
|
91
|
+
onChange,
|
|
92
|
+
currentDate,
|
|
93
|
+
...props
|
|
94
|
+
}) => {
|
|
95
|
+
const renderHourSelectOptions = () => {
|
|
96
|
+
let options = [];
|
|
97
|
+
|
|
98
|
+
for (let i = 1; i <= 24; i++) {
|
|
99
|
+
options.push(<option key={`hour-option-${i}`} value={i} style={{padding: "8px"}}>{i < 10 ? `0${i}` : i}</option>);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return options;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const renderMinuteSelectOptions = () => {
|
|
106
|
+
let options = [];
|
|
107
|
+
|
|
108
|
+
for (let i = 0; i <= 60; i += 15) {
|
|
109
|
+
options.push(<option key={`minute-option-${i}`} value={i} style={{padding: "8px"}}>{i < 10 ? `0${i}` : i}</option>);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return options;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
return (
|
|
116
|
+
<div {...props}>
|
|
117
|
+
<select value={format(currentDate, "H")} onChange={e => onChange(e, "hour")} className="w-auto">
|
|
118
|
+
{renderHourSelectOptions()}
|
|
119
|
+
</select>
|
|
120
|
+
<select value={format(currentDate, "m")} onChange={e => onChange(e, "minute")} className="mr-1 w-auto">
|
|
121
|
+
{renderMinuteSelectOptions()}
|
|
122
|
+
</select>
|
|
123
|
+
Uhr
|
|
124
|
+
</div>
|
|
125
|
+
);
|
|
83
126
|
};
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
.timeline {
|
|
10
10
|
height: auto;
|
|
11
|
-
padding:
|
|
11
|
+
padding: 30px 0 12px 0;
|
|
12
12
|
width: 100%;
|
|
13
13
|
display: flex;
|
|
14
14
|
font-weight: bold;
|
|
@@ -48,10 +48,4 @@
|
|
|
48
48
|
left: -100px;
|
|
49
49
|
width: 200px;
|
|
50
50
|
text-align: center;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
.date {
|
|
54
|
-
width: 100%;
|
|
55
|
-
text-align: center;
|
|
56
|
-
padding: 20px 0 30px 0;
|
|
57
51
|
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, {
|
|
2
|
+
useEffect, useRef, useState,
|
|
3
|
+
} from "react";
|
|
2
4
|
|
|
3
5
|
import {getContentfulClient} from "../lib/contentfulClient";
|
|
4
6
|
import Renderer from "@vonaffenfels/slate-editor/dist/Renderer";
|
|
5
7
|
import componentLoader from "@vonaffenfels/slate-editor/componentLoader";
|
|
6
8
|
import {Timeline} from "./Teasermanager/Timeline";
|
|
7
9
|
import styles from "./Teasermanager.module.css";
|
|
8
|
-
import {runLoaders} from "../lib/runLoaders"
|
|
10
|
+
import {runLoaders} from "../lib/runLoaders";
|
|
9
11
|
|
|
10
12
|
export const Teasermanager = ({
|
|
11
13
|
entryId,
|
|
@@ -43,12 +45,12 @@ export const Teasermanager = ({
|
|
|
43
45
|
});
|
|
44
46
|
|
|
45
47
|
node.appendChild(managementNode);
|
|
46
|
-
}
|
|
48
|
+
};
|
|
47
49
|
|
|
48
50
|
const updateSlots = (mutationList) => {
|
|
49
51
|
const slots = wrapperRef.current.querySelectorAll(`*[data-teasermanager-slot]`);
|
|
50
52
|
slots.forEach(initSlot);
|
|
51
|
-
}
|
|
53
|
+
};
|
|
52
54
|
|
|
53
55
|
useEffect(() => {
|
|
54
56
|
if (!entryId && entry) {
|
|
@@ -67,11 +69,15 @@ export const Teasermanager = ({
|
|
|
67
69
|
}
|
|
68
70
|
|
|
69
71
|
const observer = new MutationObserver(updateSlots);
|
|
70
|
-
observer.observe(wrapperRef.current, {
|
|
72
|
+
observer.observe(wrapperRef.current, {
|
|
73
|
+
attributes: false,
|
|
74
|
+
childList: true,
|
|
75
|
+
subtree: true,
|
|
76
|
+
});
|
|
71
77
|
|
|
72
78
|
return () => {
|
|
73
79
|
observer.disconnect();
|
|
74
|
-
}
|
|
80
|
+
};
|
|
75
81
|
}, [wrapperRef, currentDate]);
|
|
76
82
|
|
|
77
83
|
useEffect(() => {
|
|
@@ -84,13 +90,13 @@ export const Teasermanager = ({
|
|
|
84
90
|
}
|
|
85
91
|
|
|
86
92
|
setLoading(true);
|
|
87
|
-
runLoaders(contentValue, portalValue).then(content => {
|
|
93
|
+
runLoaders(contentValue, portalValue, entry?.sys?.id).then(content => {
|
|
88
94
|
setLoadedContent(content);
|
|
89
95
|
setLoading(false);
|
|
90
96
|
});
|
|
91
97
|
}, [contentFieldName, locale, entry, reloadTrigger]);
|
|
92
98
|
|
|
93
|
-
return <div className="w-full flex
|
|
99
|
+
return <div className="flex w-full flex-col">
|
|
94
100
|
<div className="w-full">
|
|
95
101
|
<Timeline currentDate={currentDate} setCurrentDate={setCurrentDate}/>
|
|
96
102
|
</div>
|
|
@@ -103,5 +109,5 @@ export const Teasermanager = ({
|
|
|
103
109
|
/>
|
|
104
110
|
}
|
|
105
111
|
</div>
|
|
106
|
-
</div
|
|
107
|
-
}
|
|
112
|
+
</div>;
|
|
113
|
+
};
|
package/src/lib/runLoaders.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export const runLoaders = async (value, portal) => {
|
|
1
|
+
export const runLoaders = async (value, portal, contextId) => {
|
|
2
2
|
if (!Array.isArray(value)) {
|
|
3
3
|
return value;
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
const newValue = await Promise.all(value.map(async (item) => {
|
|
7
7
|
try {
|
|
8
|
-
return await runLoader(item, portal)
|
|
8
|
+
return await runLoader(item, portal, contextId)
|
|
9
9
|
} catch (e) {
|
|
10
10
|
console.error(e);
|
|
11
11
|
return item;
|
|
@@ -15,13 +15,16 @@ export const runLoaders = async (value, portal) => {
|
|
|
15
15
|
return newValue;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
const runLoader = async (item, portal) => {
|
|
18
|
+
const runLoader = async (item, portal, contextId) => {
|
|
19
19
|
|
|
20
20
|
if (!item?.block) {
|
|
21
21
|
return item;
|
|
22
22
|
}
|
|
23
23
|
try {
|
|
24
|
-
const response = await fetch(`/api/loader/?portal=${portal}&block=${item.block}
|
|
24
|
+
const response = await fetch(`/api/loader/?portal=${portal}&block=${item.block}`, {
|
|
25
|
+
method: "POST",
|
|
26
|
+
body: JSON.stringify({variables: item.attributes, context: {activeContent: {sys: {id: contextId}}}}),
|
|
27
|
+
}).then(res => res.json());
|
|
25
28
|
|
|
26
29
|
return {
|
|
27
30
|
...item,
|