@vonaffenfels/contentful-teasermanager 1.0.8 → 1.0.10

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.8",
3
+ "version": "1.0.10",
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.5",
99
+ "@vonaffenfels/slate-editor": "^1.0.10",
100
100
  "webpack": "5.73.0"
101
101
  },
102
- "gitHead": "93ecd9a3fd0bc3e7d14a80b1138d1934d505d032",
102
+ "gitHead": "bd271f5265184e34c8ebef5f49936ab95fe29dcf",
103
103
  "publishConfig": {
104
104
  "access": "public"
105
105
  }
@@ -8,6 +8,7 @@ const Entry = ({sdk}) => {
8
8
  const [locale, setLocale] = useState(sdk.locales.default);
9
9
  const [portal, setPortal] = useState();
10
10
  const portalField = sdk?.entry?.fields?.portal;
11
+ const [reloadTrigger, setReloadTrigger] = useState(0);
11
12
 
12
13
  portalField?.onValueChanged(() => {
13
14
  if (portalField.getValue() !== portal) {
@@ -26,20 +27,39 @@ const Entry = ({sdk}) => {
26
27
  }, []);
27
28
 
28
29
  const onSlotClick = (slotId, currentDate) => {
29
- console.log("KIENZ_DEBUG: :31 / onSlotClick", {
30
- slotId,
31
- currentDate,
32
- });
33
- sdk.dialogs.selectSingleEntry({contentTypes: ["article"]}).then((entry) => {
30
+ sdk.dialogs.selectSingleEntry({contentTypes: ["article"]}).then(async (entry) => {
34
31
  if (!entry) {
35
32
  return;
36
33
  }
37
34
 
38
- console.log(`Selected entry ${entry.sys.id} for slot ${slotId} and date ${currentDate}`);
35
+ console.log(`Selected entry ${entry.sys.id} for page ${sdk.entry.getSys().id} with portal ${portal} for slot ${slotId} and date ${currentDate}`);
36
+
37
+ const {apiRoot} = sdk.parameters.instance;
38
+ try {
39
+ const response = await fetch(`${apiRoot}/api/saveStateForSlot`, {
40
+ method: "POST",
41
+ body: JSON.stringify({
42
+ "project": portal,
43
+ "slot": slotId,
44
+ "page": sdk.entry.getSys().id,
45
+ "entry": entry.sys.id,
46
+ "date": currentDate,
47
+ }),
48
+ });
49
+ setReloadTrigger((current) => current + 1);
50
+ } catch (e) {
51
+ console.error(e);
52
+ alert("Fehler beim speichern!");
53
+ }
39
54
  });
40
55
  };
41
56
 
42
- return <Teasermanager entryId={sdk.entry.getSys().id} locale={locale} contentFieldName={contentField} onSlotClick={onSlotClick}/>;
57
+ return <Teasermanager
58
+ entryId={sdk.entry.getSys().id}
59
+ locale={locale}
60
+ contentFieldName={contentField}
61
+ onSlotClick={onSlotClick}
62
+ reloadTrigger={reloadTrigger}/>;
43
63
  };
44
64
 
45
65
  export default Entry;
@@ -12,10 +12,12 @@ export const Teasermanager = ({
12
12
  onSlotClick = () => console.error("missing onSlotClick"),
13
13
  contentFieldName = "content",
14
14
  locale = "de",
15
+ reloadTrigger = 0,
15
16
  }) => {
16
17
  const contentfulClient = getContentfulClient();
17
18
  const [entry, setEntry] = useState(null);
18
19
  const wrapperRef = useRef(null);
20
+ const [loading, setLoading] = useState(true);
19
21
  const [loadedContent, setLoadedContent] = useState(null);
20
22
  const [currentDate, setCurrentDate] = useState(null);
21
23
 
@@ -77,18 +79,24 @@ export const Teasermanager = ({
77
79
  const portalValue = entry?.fields?.portal?.[locale];
78
80
 
79
81
  if (!contentValue) {
82
+ setLoading(false);
80
83
  return setLoadedContent(null);
81
84
  }
82
85
 
83
- runLoaders(contentValue, portalValue).then(setLoadedContent);
84
- }, [contentFieldName, locale, entry]);
86
+ setLoading(true);
87
+ runLoaders(contentValue, portalValue).then(content => {
88
+ setLoadedContent(content);
89
+ setLoading(false);
90
+ });
91
+ }, [contentFieldName, locale, entry, reloadTrigger]);
85
92
 
86
93
  return <div className="w-full flex flex-col">
87
94
  <div className="w-full">
88
95
  <Timeline currentDate={currentDate} setCurrentDate={setCurrentDate}/>
89
96
  </div>
90
97
  <div className={styles.wrapper} ref={wrapperRef}>
91
- {!!loadedContent &&
98
+ {loading && <div>Lade Inhalte...</div>}
99
+ {!!loadedContent && !loading &&
92
100
  <Renderer
93
101
  value={loadedContent}
94
102
  storybookComponentLoader={componentLoader}