@creopse/react 0.0.21 → 0.0.24
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/dist/{content-I5YJXH3C.cjs → content-Cgzd1E-Q.cjs} +32 -2
- package/dist/{content-BrpVuVxT.js → content-DP8wQsOf.js} +32 -2
- package/dist/hooks/index.cjs +230 -1
- package/dist/hooks/index.mjs +232 -3
- package/dist/index.cjs +20 -9
- package/dist/index.mjs +20 -9
- package/package.json +1 -1
- package/types/hooks/config.d.ts +1 -1
- package/types/hooks/content.d.ts +2 -0
- package/types/hooks/index.d.ts +2 -0
- package/types/hooks/news.d.ts +31 -0
- package/types/hooks/video.d.ts +16 -0
- package/types/types/news.d.ts +35 -0
- package/types/types/plugin.d.ts +1 -1
- package/types/types/video.d.ts +25 -0
|
@@ -7034,7 +7034,7 @@ const useHelper = () => {
|
|
|
7034
7034
|
userLanguage = props.userData.preferences.locale;
|
|
7035
7035
|
}
|
|
7036
7036
|
if (!lang2) {
|
|
7037
|
-
lang2 = localStorage.getItem(langKey) || props.appLocale || config?.locale ||
|
|
7037
|
+
lang2 = localStorage.getItem(langKey) || (config?.useUserLocaleAsFallback ? userLanguage : false) || props.appLocale || config?.locale || "en";
|
|
7038
7038
|
}
|
|
7039
7039
|
try {
|
|
7040
7040
|
parsedData = JSON.parse(data);
|
|
@@ -7043,7 +7043,13 @@ const useHelper = () => {
|
|
|
7043
7043
|
}
|
|
7044
7044
|
return parsedData ? parsedData[lang2.toUpperCase()] || parsedData[lang2] || "" : "";
|
|
7045
7045
|
},
|
|
7046
|
-
[
|
|
7046
|
+
[
|
|
7047
|
+
config?.locale,
|
|
7048
|
+
config?.useUserLocaleAsFallback,
|
|
7049
|
+
langKey,
|
|
7050
|
+
props.appLocale,
|
|
7051
|
+
props.userData
|
|
7052
|
+
]
|
|
7047
7053
|
);
|
|
7048
7054
|
const tr = React.useCallback(
|
|
7049
7055
|
(data, lang2) => {
|
|
@@ -7961,6 +7967,29 @@ const useContent = () => {
|
|
|
7961
7967
|
},
|
|
7962
7968
|
[request, formatContentModelItemData]
|
|
7963
7969
|
);
|
|
7970
|
+
const submitUserContentModelItem = React.useCallback(
|
|
7971
|
+
async (title, contentModelId, singletonsData = {}, collectionsData = {}, successCallback, errorCallback) => {
|
|
7972
|
+
const task = await request({
|
|
7973
|
+
url: `/content-model/user-items`,
|
|
7974
|
+
method: "post",
|
|
7975
|
+
data: {
|
|
7976
|
+
title,
|
|
7977
|
+
contentModelId,
|
|
7978
|
+
contentModelData: {
|
|
7979
|
+
index: { ...singletonsData },
|
|
7980
|
+
...collectionsData
|
|
7981
|
+
}
|
|
7982
|
+
}
|
|
7983
|
+
});
|
|
7984
|
+
if (task.failure && task.error) {
|
|
7985
|
+
if (errorCallback) errorCallback(task.error?.response?.data);
|
|
7986
|
+
} else {
|
|
7987
|
+
if (successCallback) successCallback();
|
|
7988
|
+
}
|
|
7989
|
+
return task;
|
|
7990
|
+
},
|
|
7991
|
+
[request]
|
|
7992
|
+
);
|
|
7964
7993
|
const getMenu = React.useCallback(
|
|
7965
7994
|
(name, filterByIsActive = true) => {
|
|
7966
7995
|
const menu = cloneDeep(props?.menus?.find((menu2) => menu2.name === name));
|
|
@@ -8138,6 +8167,7 @@ const useContent = () => {
|
|
|
8138
8167
|
getContentModelItems,
|
|
8139
8168
|
getPaginatedContentModelItems,
|
|
8140
8169
|
getAppInformationValue,
|
|
8170
|
+
submitUserContentModelItem,
|
|
8141
8171
|
appAccentColor,
|
|
8142
8172
|
appPrimaryColor,
|
|
8143
8173
|
appSecondaryColor
|
|
@@ -7033,7 +7033,7 @@ const useHelper = () => {
|
|
|
7033
7033
|
userLanguage = props.userData.preferences.locale;
|
|
7034
7034
|
}
|
|
7035
7035
|
if (!lang2) {
|
|
7036
|
-
lang2 = localStorage.getItem(langKey) || props.appLocale || config?.locale ||
|
|
7036
|
+
lang2 = localStorage.getItem(langKey) || (config?.useUserLocaleAsFallback ? userLanguage : false) || props.appLocale || config?.locale || "en";
|
|
7037
7037
|
}
|
|
7038
7038
|
try {
|
|
7039
7039
|
parsedData = JSON.parse(data);
|
|
@@ -7042,7 +7042,13 @@ const useHelper = () => {
|
|
|
7042
7042
|
}
|
|
7043
7043
|
return parsedData ? parsedData[lang2.toUpperCase()] || parsedData[lang2] || "" : "";
|
|
7044
7044
|
},
|
|
7045
|
-
[
|
|
7045
|
+
[
|
|
7046
|
+
config?.locale,
|
|
7047
|
+
config?.useUserLocaleAsFallback,
|
|
7048
|
+
langKey,
|
|
7049
|
+
props.appLocale,
|
|
7050
|
+
props.userData
|
|
7051
|
+
]
|
|
7046
7052
|
);
|
|
7047
7053
|
const tr = useCallback(
|
|
7048
7054
|
(data, lang2) => {
|
|
@@ -7960,6 +7966,29 @@ const useContent = () => {
|
|
|
7960
7966
|
},
|
|
7961
7967
|
[request, formatContentModelItemData]
|
|
7962
7968
|
);
|
|
7969
|
+
const submitUserContentModelItem = useCallback(
|
|
7970
|
+
async (title, contentModelId, singletonsData = {}, collectionsData = {}, successCallback, errorCallback) => {
|
|
7971
|
+
const task = await request({
|
|
7972
|
+
url: `/content-model/user-items`,
|
|
7973
|
+
method: "post",
|
|
7974
|
+
data: {
|
|
7975
|
+
title,
|
|
7976
|
+
contentModelId,
|
|
7977
|
+
contentModelData: {
|
|
7978
|
+
index: { ...singletonsData },
|
|
7979
|
+
...collectionsData
|
|
7980
|
+
}
|
|
7981
|
+
}
|
|
7982
|
+
});
|
|
7983
|
+
if (task.failure && task.error) {
|
|
7984
|
+
if (errorCallback) errorCallback(task.error?.response?.data);
|
|
7985
|
+
} else {
|
|
7986
|
+
if (successCallback) successCallback();
|
|
7987
|
+
}
|
|
7988
|
+
return task;
|
|
7989
|
+
},
|
|
7990
|
+
[request]
|
|
7991
|
+
);
|
|
7963
7992
|
const getMenu = useCallback(
|
|
7964
7993
|
(name, filterByIsActive = true) => {
|
|
7965
7994
|
const menu = cloneDeep(props?.menus?.find((menu2) => menu2.name === name));
|
|
@@ -8137,6 +8166,7 @@ const useContent = () => {
|
|
|
8137
8166
|
getContentModelItems,
|
|
8138
8167
|
getPaginatedContentModelItems,
|
|
8139
8168
|
getAppInformationValue,
|
|
8169
|
+
submitUserContentModelItem,
|
|
8140
8170
|
appAccentColor,
|
|
8141
8171
|
appPrimaryColor,
|
|
8142
8172
|
appSecondaryColor
|
package/dist/hooks/index.cjs
CHANGED
|
@@ -1,7 +1,234 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const content = require("../content-
|
|
3
|
+
const content = require("../content-Cgzd1E-Q.cjs");
|
|
4
4
|
const React = require("react");
|
|
5
|
+
const articlesUrlBuilder = (p) => {
|
|
6
|
+
const searchParams = new URLSearchParams();
|
|
7
|
+
searchParams.set("pageSize", String(p.pageSize));
|
|
8
|
+
if (p.query) searchParams.set("query", p.query);
|
|
9
|
+
if (p.page) searchParams.set("page", String(p.page));
|
|
10
|
+
if (p.status) searchParams.set("status", String(p.status));
|
|
11
|
+
if (p.categories?.length) {
|
|
12
|
+
p.categories.forEach(
|
|
13
|
+
(cat) => searchParams.append("categories[]", String(cat))
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
if (p.tags?.length) {
|
|
17
|
+
p.tags.forEach((tag) => searchParams.append("tags[]", String(tag)));
|
|
18
|
+
}
|
|
19
|
+
if (p.months?.length) {
|
|
20
|
+
p.months.forEach((month) => searchParams.append("months[]", month));
|
|
21
|
+
}
|
|
22
|
+
return `/news-articles?${searchParams.toString()}`;
|
|
23
|
+
};
|
|
24
|
+
const commentsUrlBuilder = (p) => {
|
|
25
|
+
const searchParams = new URLSearchParams();
|
|
26
|
+
Object.entries(p).forEach(([key, value]) => {
|
|
27
|
+
if (value !== void 0) searchParams.set(key, String(value));
|
|
28
|
+
});
|
|
29
|
+
return `/news-comments?${searchParams.toString()}`;
|
|
30
|
+
};
|
|
31
|
+
const useNews = () => {
|
|
32
|
+
const { request } = content.useApi();
|
|
33
|
+
const [isLoading, setIsLoading] = React.useState(false);
|
|
34
|
+
const loadCategories = React.useCallback(
|
|
35
|
+
async (filterByIsVisible = true) => {
|
|
36
|
+
setIsLoading(true);
|
|
37
|
+
const task = await request({ url: "/news-categories" });
|
|
38
|
+
setIsLoading(false);
|
|
39
|
+
if (task.success && task.result.data) {
|
|
40
|
+
return task.result.data.filter(
|
|
41
|
+
(p) => !filterByIsVisible || p.isActive
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
return [];
|
|
45
|
+
},
|
|
46
|
+
[request]
|
|
47
|
+
);
|
|
48
|
+
const loadTags = React.useCallback(
|
|
49
|
+
async (filterByIsVisible = true) => {
|
|
50
|
+
setIsLoading(true);
|
|
51
|
+
const task = await request({ url: "/news-tags" });
|
|
52
|
+
setIsLoading(false);
|
|
53
|
+
if (task.success && task.result.data) {
|
|
54
|
+
return task.result.data.filter(
|
|
55
|
+
(p) => !filterByIsVisible || p.isActive
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
return [];
|
|
59
|
+
},
|
|
60
|
+
[request]
|
|
61
|
+
);
|
|
62
|
+
const loadArticles = React.useCallback(
|
|
63
|
+
async (params) => {
|
|
64
|
+
setIsLoading(true);
|
|
65
|
+
const task = await request({ url: articlesUrlBuilder(params) });
|
|
66
|
+
setIsLoading(false);
|
|
67
|
+
if (task.success && task.result.data) {
|
|
68
|
+
return task.result.data;
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
articles: [],
|
|
72
|
+
meta: { total: 0, currentPage: 1, perPage: 1, lastPage: 1 }
|
|
73
|
+
};
|
|
74
|
+
},
|
|
75
|
+
[request]
|
|
76
|
+
);
|
|
77
|
+
const loadArticlesMonths = React.useCallback(async () => {
|
|
78
|
+
setIsLoading(true);
|
|
79
|
+
const task = await request({ url: "/news-articles/list/months" });
|
|
80
|
+
setIsLoading(false);
|
|
81
|
+
if (task.success && task.result.data) {
|
|
82
|
+
return task.result.data;
|
|
83
|
+
}
|
|
84
|
+
return [];
|
|
85
|
+
}, [request]);
|
|
86
|
+
const loadArticlesCount = React.useCallback(async () => {
|
|
87
|
+
setIsLoading(true);
|
|
88
|
+
const task = await request({ url: "/count/news-articles" });
|
|
89
|
+
setIsLoading(false);
|
|
90
|
+
if (task.success) {
|
|
91
|
+
return task.result.data;
|
|
92
|
+
}
|
|
93
|
+
return 0;
|
|
94
|
+
}, [request]);
|
|
95
|
+
const loadArticlesCountByStatus = React.useCallback(
|
|
96
|
+
async (status) => {
|
|
97
|
+
setIsLoading(true);
|
|
98
|
+
const task = await request({
|
|
99
|
+
url: `/count/news-articles/status/${status}`
|
|
100
|
+
});
|
|
101
|
+
setIsLoading(false);
|
|
102
|
+
if (task.success) {
|
|
103
|
+
return task.result.data;
|
|
104
|
+
}
|
|
105
|
+
return 0;
|
|
106
|
+
},
|
|
107
|
+
[request]
|
|
108
|
+
);
|
|
109
|
+
const loadArticlesCountByAuthor = React.useCallback(
|
|
110
|
+
async (id) => {
|
|
111
|
+
setIsLoading(true);
|
|
112
|
+
const task = await request({
|
|
113
|
+
url: `/count/news-articles/author/${id}`
|
|
114
|
+
});
|
|
115
|
+
setIsLoading(false);
|
|
116
|
+
if (task.success) {
|
|
117
|
+
return task.result.data;
|
|
118
|
+
}
|
|
119
|
+
return 0;
|
|
120
|
+
},
|
|
121
|
+
[request]
|
|
122
|
+
);
|
|
123
|
+
const loadComments = React.useCallback(
|
|
124
|
+
async (params) => {
|
|
125
|
+
setIsLoading(true);
|
|
126
|
+
const task = await request({ url: commentsUrlBuilder(params) });
|
|
127
|
+
setIsLoading(false);
|
|
128
|
+
if (task.success && task.result.data) {
|
|
129
|
+
return task.result.data;
|
|
130
|
+
}
|
|
131
|
+
return {
|
|
132
|
+
comments: [],
|
|
133
|
+
meta: { total: 0, currentPage: 1, perPage: 1, lastPage: 1 }
|
|
134
|
+
};
|
|
135
|
+
},
|
|
136
|
+
[request]
|
|
137
|
+
);
|
|
138
|
+
const addComment = React.useCallback(
|
|
139
|
+
async (comment, successCallback, errorCallback) => {
|
|
140
|
+
setIsLoading(true);
|
|
141
|
+
const task = await request({
|
|
142
|
+
url: "/news-comments",
|
|
143
|
+
method: "post",
|
|
144
|
+
data: comment
|
|
145
|
+
});
|
|
146
|
+
setIsLoading(false);
|
|
147
|
+
if (task.failure && task.error) {
|
|
148
|
+
if (errorCallback) errorCallback(task.error?.response?.data);
|
|
149
|
+
} else {
|
|
150
|
+
if (successCallback) successCallback();
|
|
151
|
+
}
|
|
152
|
+
return task;
|
|
153
|
+
},
|
|
154
|
+
[request]
|
|
155
|
+
);
|
|
156
|
+
return {
|
|
157
|
+
isLoading,
|
|
158
|
+
loadTags,
|
|
159
|
+
loadComments,
|
|
160
|
+
loadArticles,
|
|
161
|
+
loadCategories,
|
|
162
|
+
loadArticlesCount,
|
|
163
|
+
loadArticlesMonths,
|
|
164
|
+
loadArticlesCountByStatus,
|
|
165
|
+
loadArticlesCountByAuthor,
|
|
166
|
+
addComment
|
|
167
|
+
};
|
|
168
|
+
};
|
|
169
|
+
const videoItemsUrlBuilder = (p) => {
|
|
170
|
+
const searchParams = new URLSearchParams();
|
|
171
|
+
searchParams.set("pageSize", String(p.pageSize));
|
|
172
|
+
if (p.query) searchParams.set("query", p.query);
|
|
173
|
+
if (p.page) searchParams.set("page", String(p.page));
|
|
174
|
+
if (p.source) searchParams.set("source", p.source);
|
|
175
|
+
if (p.visible !== void 0) searchParams.set("visible", String(p.visible));
|
|
176
|
+
if (p.orderByPublishedAt !== void 0)
|
|
177
|
+
searchParams.set("orderByPublishedAt", String(p.orderByPublishedAt));
|
|
178
|
+
if (p.categories?.length) {
|
|
179
|
+
p.categories.forEach(
|
|
180
|
+
(cat) => searchParams.append("categories[]", String(cat))
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
return `/video-items?${searchParams.toString()}`;
|
|
184
|
+
};
|
|
185
|
+
const useVideo = () => {
|
|
186
|
+
const { request } = content.useApi();
|
|
187
|
+
const [isLoading, setIsLoading] = React.useState(false);
|
|
188
|
+
const loadCategories = React.useCallback(
|
|
189
|
+
async (filterByIsVisible = true) => {
|
|
190
|
+
setIsLoading(true);
|
|
191
|
+
const task = await request({
|
|
192
|
+
url: "/video-categories"
|
|
193
|
+
});
|
|
194
|
+
setIsLoading(false);
|
|
195
|
+
if (task.success && task.result.data) {
|
|
196
|
+
return task.result.data.filter(
|
|
197
|
+
(p) => !filterByIsVisible || p.isActive
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
return [];
|
|
201
|
+
},
|
|
202
|
+
[request]
|
|
203
|
+
);
|
|
204
|
+
const loadVideoItems = React.useCallback(
|
|
205
|
+
async (params) => {
|
|
206
|
+
setIsLoading(true);
|
|
207
|
+
const task = await request({
|
|
208
|
+
url: videoItemsUrlBuilder(params)
|
|
209
|
+
});
|
|
210
|
+
setIsLoading(false);
|
|
211
|
+
if (task.success && task.result.data) {
|
|
212
|
+
return task.result.data;
|
|
213
|
+
}
|
|
214
|
+
return {
|
|
215
|
+
videoItems: [],
|
|
216
|
+
meta: {
|
|
217
|
+
total: 0,
|
|
218
|
+
currentPage: 1,
|
|
219
|
+
perPage: 1,
|
|
220
|
+
lastPage: 1
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
},
|
|
224
|
+
[request]
|
|
225
|
+
);
|
|
226
|
+
return {
|
|
227
|
+
isLoading,
|
|
228
|
+
loadCategories,
|
|
229
|
+
loadVideoItems
|
|
230
|
+
};
|
|
231
|
+
};
|
|
5
232
|
const useNewsletter = () => {
|
|
6
233
|
const { request } = content.useApi();
|
|
7
234
|
const [isLoading, setIsLoading] = React.useState(false);
|
|
@@ -50,4 +277,6 @@ exports.useConfig = content.useConfig;
|
|
|
50
277
|
exports.useContent = content.useContent;
|
|
51
278
|
exports.useHelper = content.useHelper;
|
|
52
279
|
exports.useProps = content.useProps;
|
|
280
|
+
exports.useNews = useNews;
|
|
53
281
|
exports.useNewsletter = useNewsletter;
|
|
282
|
+
exports.useVideo = useVideo;
|
package/dist/hooks/index.mjs
CHANGED
|
@@ -1,6 +1,233 @@
|
|
|
1
|
-
import { e as useApi } from "../content-
|
|
2
|
-
import { f, a, u, b } from "../content-
|
|
1
|
+
import { e as useApi } from "../content-DP8wQsOf.js";
|
|
2
|
+
import { f, a, u, b } from "../content-DP8wQsOf.js";
|
|
3
3
|
import { useState, useCallback } from "react";
|
|
4
|
+
const articlesUrlBuilder = (p) => {
|
|
5
|
+
const searchParams = new URLSearchParams();
|
|
6
|
+
searchParams.set("pageSize", String(p.pageSize));
|
|
7
|
+
if (p.query) searchParams.set("query", p.query);
|
|
8
|
+
if (p.page) searchParams.set("page", String(p.page));
|
|
9
|
+
if (p.status) searchParams.set("status", String(p.status));
|
|
10
|
+
if (p.categories?.length) {
|
|
11
|
+
p.categories.forEach(
|
|
12
|
+
(cat) => searchParams.append("categories[]", String(cat))
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
if (p.tags?.length) {
|
|
16
|
+
p.tags.forEach((tag) => searchParams.append("tags[]", String(tag)));
|
|
17
|
+
}
|
|
18
|
+
if (p.months?.length) {
|
|
19
|
+
p.months.forEach((month) => searchParams.append("months[]", month));
|
|
20
|
+
}
|
|
21
|
+
return `/news-articles?${searchParams.toString()}`;
|
|
22
|
+
};
|
|
23
|
+
const commentsUrlBuilder = (p) => {
|
|
24
|
+
const searchParams = new URLSearchParams();
|
|
25
|
+
Object.entries(p).forEach(([key, value]) => {
|
|
26
|
+
if (value !== void 0) searchParams.set(key, String(value));
|
|
27
|
+
});
|
|
28
|
+
return `/news-comments?${searchParams.toString()}`;
|
|
29
|
+
};
|
|
30
|
+
const useNews = () => {
|
|
31
|
+
const { request } = useApi();
|
|
32
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
33
|
+
const loadCategories = useCallback(
|
|
34
|
+
async (filterByIsVisible = true) => {
|
|
35
|
+
setIsLoading(true);
|
|
36
|
+
const task = await request({ url: "/news-categories" });
|
|
37
|
+
setIsLoading(false);
|
|
38
|
+
if (task.success && task.result.data) {
|
|
39
|
+
return task.result.data.filter(
|
|
40
|
+
(p) => !filterByIsVisible || p.isActive
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
return [];
|
|
44
|
+
},
|
|
45
|
+
[request]
|
|
46
|
+
);
|
|
47
|
+
const loadTags = useCallback(
|
|
48
|
+
async (filterByIsVisible = true) => {
|
|
49
|
+
setIsLoading(true);
|
|
50
|
+
const task = await request({ url: "/news-tags" });
|
|
51
|
+
setIsLoading(false);
|
|
52
|
+
if (task.success && task.result.data) {
|
|
53
|
+
return task.result.data.filter(
|
|
54
|
+
(p) => !filterByIsVisible || p.isActive
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
return [];
|
|
58
|
+
},
|
|
59
|
+
[request]
|
|
60
|
+
);
|
|
61
|
+
const loadArticles = useCallback(
|
|
62
|
+
async (params) => {
|
|
63
|
+
setIsLoading(true);
|
|
64
|
+
const task = await request({ url: articlesUrlBuilder(params) });
|
|
65
|
+
setIsLoading(false);
|
|
66
|
+
if (task.success && task.result.data) {
|
|
67
|
+
return task.result.data;
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
articles: [],
|
|
71
|
+
meta: { total: 0, currentPage: 1, perPage: 1, lastPage: 1 }
|
|
72
|
+
};
|
|
73
|
+
},
|
|
74
|
+
[request]
|
|
75
|
+
);
|
|
76
|
+
const loadArticlesMonths = useCallback(async () => {
|
|
77
|
+
setIsLoading(true);
|
|
78
|
+
const task = await request({ url: "/news-articles/list/months" });
|
|
79
|
+
setIsLoading(false);
|
|
80
|
+
if (task.success && task.result.data) {
|
|
81
|
+
return task.result.data;
|
|
82
|
+
}
|
|
83
|
+
return [];
|
|
84
|
+
}, [request]);
|
|
85
|
+
const loadArticlesCount = useCallback(async () => {
|
|
86
|
+
setIsLoading(true);
|
|
87
|
+
const task = await request({ url: "/count/news-articles" });
|
|
88
|
+
setIsLoading(false);
|
|
89
|
+
if (task.success) {
|
|
90
|
+
return task.result.data;
|
|
91
|
+
}
|
|
92
|
+
return 0;
|
|
93
|
+
}, [request]);
|
|
94
|
+
const loadArticlesCountByStatus = useCallback(
|
|
95
|
+
async (status) => {
|
|
96
|
+
setIsLoading(true);
|
|
97
|
+
const task = await request({
|
|
98
|
+
url: `/count/news-articles/status/${status}`
|
|
99
|
+
});
|
|
100
|
+
setIsLoading(false);
|
|
101
|
+
if (task.success) {
|
|
102
|
+
return task.result.data;
|
|
103
|
+
}
|
|
104
|
+
return 0;
|
|
105
|
+
},
|
|
106
|
+
[request]
|
|
107
|
+
);
|
|
108
|
+
const loadArticlesCountByAuthor = useCallback(
|
|
109
|
+
async (id) => {
|
|
110
|
+
setIsLoading(true);
|
|
111
|
+
const task = await request({
|
|
112
|
+
url: `/count/news-articles/author/${id}`
|
|
113
|
+
});
|
|
114
|
+
setIsLoading(false);
|
|
115
|
+
if (task.success) {
|
|
116
|
+
return task.result.data;
|
|
117
|
+
}
|
|
118
|
+
return 0;
|
|
119
|
+
},
|
|
120
|
+
[request]
|
|
121
|
+
);
|
|
122
|
+
const loadComments = useCallback(
|
|
123
|
+
async (params) => {
|
|
124
|
+
setIsLoading(true);
|
|
125
|
+
const task = await request({ url: commentsUrlBuilder(params) });
|
|
126
|
+
setIsLoading(false);
|
|
127
|
+
if (task.success && task.result.data) {
|
|
128
|
+
return task.result.data;
|
|
129
|
+
}
|
|
130
|
+
return {
|
|
131
|
+
comments: [],
|
|
132
|
+
meta: { total: 0, currentPage: 1, perPage: 1, lastPage: 1 }
|
|
133
|
+
};
|
|
134
|
+
},
|
|
135
|
+
[request]
|
|
136
|
+
);
|
|
137
|
+
const addComment = useCallback(
|
|
138
|
+
async (comment, successCallback, errorCallback) => {
|
|
139
|
+
setIsLoading(true);
|
|
140
|
+
const task = await request({
|
|
141
|
+
url: "/news-comments",
|
|
142
|
+
method: "post",
|
|
143
|
+
data: comment
|
|
144
|
+
});
|
|
145
|
+
setIsLoading(false);
|
|
146
|
+
if (task.failure && task.error) {
|
|
147
|
+
if (errorCallback) errorCallback(task.error?.response?.data);
|
|
148
|
+
} else {
|
|
149
|
+
if (successCallback) successCallback();
|
|
150
|
+
}
|
|
151
|
+
return task;
|
|
152
|
+
},
|
|
153
|
+
[request]
|
|
154
|
+
);
|
|
155
|
+
return {
|
|
156
|
+
isLoading,
|
|
157
|
+
loadTags,
|
|
158
|
+
loadComments,
|
|
159
|
+
loadArticles,
|
|
160
|
+
loadCategories,
|
|
161
|
+
loadArticlesCount,
|
|
162
|
+
loadArticlesMonths,
|
|
163
|
+
loadArticlesCountByStatus,
|
|
164
|
+
loadArticlesCountByAuthor,
|
|
165
|
+
addComment
|
|
166
|
+
};
|
|
167
|
+
};
|
|
168
|
+
const videoItemsUrlBuilder = (p) => {
|
|
169
|
+
const searchParams = new URLSearchParams();
|
|
170
|
+
searchParams.set("pageSize", String(p.pageSize));
|
|
171
|
+
if (p.query) searchParams.set("query", p.query);
|
|
172
|
+
if (p.page) searchParams.set("page", String(p.page));
|
|
173
|
+
if (p.source) searchParams.set("source", p.source);
|
|
174
|
+
if (p.visible !== void 0) searchParams.set("visible", String(p.visible));
|
|
175
|
+
if (p.orderByPublishedAt !== void 0)
|
|
176
|
+
searchParams.set("orderByPublishedAt", String(p.orderByPublishedAt));
|
|
177
|
+
if (p.categories?.length) {
|
|
178
|
+
p.categories.forEach(
|
|
179
|
+
(cat) => searchParams.append("categories[]", String(cat))
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
return `/video-items?${searchParams.toString()}`;
|
|
183
|
+
};
|
|
184
|
+
const useVideo = () => {
|
|
185
|
+
const { request } = useApi();
|
|
186
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
187
|
+
const loadCategories = useCallback(
|
|
188
|
+
async (filterByIsVisible = true) => {
|
|
189
|
+
setIsLoading(true);
|
|
190
|
+
const task = await request({
|
|
191
|
+
url: "/video-categories"
|
|
192
|
+
});
|
|
193
|
+
setIsLoading(false);
|
|
194
|
+
if (task.success && task.result.data) {
|
|
195
|
+
return task.result.data.filter(
|
|
196
|
+
(p) => !filterByIsVisible || p.isActive
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
return [];
|
|
200
|
+
},
|
|
201
|
+
[request]
|
|
202
|
+
);
|
|
203
|
+
const loadVideoItems = useCallback(
|
|
204
|
+
async (params) => {
|
|
205
|
+
setIsLoading(true);
|
|
206
|
+
const task = await request({
|
|
207
|
+
url: videoItemsUrlBuilder(params)
|
|
208
|
+
});
|
|
209
|
+
setIsLoading(false);
|
|
210
|
+
if (task.success && task.result.data) {
|
|
211
|
+
return task.result.data;
|
|
212
|
+
}
|
|
213
|
+
return {
|
|
214
|
+
videoItems: [],
|
|
215
|
+
meta: {
|
|
216
|
+
total: 0,
|
|
217
|
+
currentPage: 1,
|
|
218
|
+
perPage: 1,
|
|
219
|
+
lastPage: 1
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
},
|
|
223
|
+
[request]
|
|
224
|
+
);
|
|
225
|
+
return {
|
|
226
|
+
isLoading,
|
|
227
|
+
loadCategories,
|
|
228
|
+
loadVideoItems
|
|
229
|
+
};
|
|
230
|
+
};
|
|
4
231
|
const useNewsletter = () => {
|
|
5
232
|
const { request } = useApi();
|
|
6
233
|
const [isLoading, setIsLoading] = useState(false);
|
|
@@ -49,6 +276,8 @@ export {
|
|
|
49
276
|
f as useConfig,
|
|
50
277
|
a as useContent,
|
|
51
278
|
u as useHelper,
|
|
279
|
+
useNews,
|
|
52
280
|
useNewsletter,
|
|
53
|
-
b as useProps
|
|
281
|
+
b as useProps,
|
|
282
|
+
useVideo
|
|
54
283
|
};
|
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const React = require("react");
|
|
4
|
-
const content = require("./content-
|
|
4
|
+
const content = require("./content-Cgzd1E-Q.cjs");
|
|
5
5
|
const react = require("@inertiajs/react");
|
|
6
6
|
const reactDom = require("react-dom");
|
|
7
7
|
function _interopNamespaceDefault(e) {
|
|
@@ -8247,6 +8247,11 @@ const RootContainer$1 = () => {
|
|
|
8247
8247
|
true
|
|
8248
8248
|
);
|
|
8249
8249
|
["assign", "replace"].forEach((method) => {
|
|
8250
|
+
const descriptor = Object.getOwnPropertyDescriptor(
|
|
8251
|
+
window.location,
|
|
8252
|
+
method
|
|
8253
|
+
);
|
|
8254
|
+
if (descriptor?.configurable === false) return;
|
|
8250
8255
|
Object.defineProperty(window.location, method, {
|
|
8251
8256
|
value: function() {
|
|
8252
8257
|
console.debug(`🚫 location.${method}() blocked`);
|
|
@@ -8255,14 +8260,20 @@ const RootContainer$1 = () => {
|
|
|
8255
8260
|
configurable: false
|
|
8256
8261
|
});
|
|
8257
8262
|
});
|
|
8258
|
-
const
|
|
8259
|
-
|
|
8260
|
-
|
|
8261
|
-
|
|
8262
|
-
|
|
8263
|
-
|
|
8264
|
-
|
|
8265
|
-
|
|
8263
|
+
const hrefDescriptor = Object.getOwnPropertyDescriptor(
|
|
8264
|
+
window.location,
|
|
8265
|
+
"href"
|
|
8266
|
+
);
|
|
8267
|
+
if (hrefDescriptor?.configurable !== false) {
|
|
8268
|
+
const currentHref = window.location.href;
|
|
8269
|
+
Object.defineProperty(window.location, "href", {
|
|
8270
|
+
get: () => currentHref,
|
|
8271
|
+
set: (value) => {
|
|
8272
|
+
console.debug("🚫 location.href = blocked:", value);
|
|
8273
|
+
},
|
|
8274
|
+
configurable: false
|
|
8275
|
+
});
|
|
8276
|
+
}
|
|
8266
8277
|
window.open = function() {
|
|
8267
8278
|
console.debug("🚫 window.open() blocked");
|
|
8268
8279
|
return null;
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import React__default, { useState, useEffect, createContext, useRef, useLayoutEffect, useId, useContext, useInsertionEffect, useMemo, useCallback, Children, isValidElement, Fragment, createElement, forwardRef, Component } from "react";
|
|
3
|
-
import { u as useHelper, a as useContent, b as useProps, P as PropsContext, R as ResolveSectionsContext, c as cloneDeep, s as slideToId, E as EditorMessageType, d as RouterContext, C as ConfigContext } from "./content-
|
|
3
|
+
import { u as useHelper, a as useContent, b as useProps, P as PropsContext, R as ResolveSectionsContext, c as cloneDeep, s as slideToId, E as EditorMessageType, d as RouterContext, C as ConfigContext } from "./content-DP8wQsOf.js";
|
|
4
4
|
import { router } from "@inertiajs/react";
|
|
5
5
|
import { createPortal } from "react-dom";
|
|
6
6
|
var jsxRuntime = { exports: {} };
|
|
@@ -8229,6 +8229,11 @@ const RootContainer$1 = () => {
|
|
|
8229
8229
|
true
|
|
8230
8230
|
);
|
|
8231
8231
|
["assign", "replace"].forEach((method) => {
|
|
8232
|
+
const descriptor = Object.getOwnPropertyDescriptor(
|
|
8233
|
+
window.location,
|
|
8234
|
+
method
|
|
8235
|
+
);
|
|
8236
|
+
if (descriptor?.configurable === false) return;
|
|
8232
8237
|
Object.defineProperty(window.location, method, {
|
|
8233
8238
|
value: function() {
|
|
8234
8239
|
console.debug(`🚫 location.${method}() blocked`);
|
|
@@ -8237,14 +8242,20 @@ const RootContainer$1 = () => {
|
|
|
8237
8242
|
configurable: false
|
|
8238
8243
|
});
|
|
8239
8244
|
});
|
|
8240
|
-
const
|
|
8241
|
-
|
|
8242
|
-
|
|
8243
|
-
|
|
8244
|
-
|
|
8245
|
-
|
|
8246
|
-
|
|
8247
|
-
|
|
8245
|
+
const hrefDescriptor = Object.getOwnPropertyDescriptor(
|
|
8246
|
+
window.location,
|
|
8247
|
+
"href"
|
|
8248
|
+
);
|
|
8249
|
+
if (hrefDescriptor?.configurable !== false) {
|
|
8250
|
+
const currentHref = window.location.href;
|
|
8251
|
+
Object.defineProperty(window.location, "href", {
|
|
8252
|
+
get: () => currentHref,
|
|
8253
|
+
set: (value) => {
|
|
8254
|
+
console.debug("🚫 location.href = blocked:", value);
|
|
8255
|
+
},
|
|
8256
|
+
configurable: false
|
|
8257
|
+
});
|
|
8258
|
+
}
|
|
8248
8259
|
window.open = function() {
|
|
8249
8260
|
console.debug("🚫 window.open() blocked");
|
|
8250
8261
|
return null;
|
package/package.json
CHANGED
package/types/hooks/config.d.ts
CHANGED
package/types/hooks/content.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Response } from '@/types/api';
|
|
1
2
|
import type { AppInformationKey, ContentModelItemModel, ContentModelModel, MenuItemGroupModel, MenuItemModel, MenuModel, NewsArticleModel, NewsCategoryModel, NewsTagModel, PageModel, SettingType, SharedProps } from '@creopse/utils';
|
|
2
3
|
/**
|
|
3
4
|
* A hook that provides a set of functions and properties for
|
|
@@ -41,6 +42,7 @@ export declare const useContent: () => {
|
|
|
41
42
|
currentPage: number;
|
|
42
43
|
}>;
|
|
43
44
|
getAppInformationValue: (key: AppInformationKey, type?: SettingType) => any;
|
|
45
|
+
submitUserContentModelItem: (title: string, contentModelId: string, singletonsData?: any, collectionsData?: any, successCallback?: () => void, errorCallback?: (errorData: any) => void) => Promise<Response<any>>;
|
|
44
46
|
appAccentColor: string;
|
|
45
47
|
appPrimaryColor: string;
|
|
46
48
|
appSecondaryColor: string;
|
package/types/hooks/index.d.ts
CHANGED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Response } from '@/types/api';
|
|
2
|
+
import type { ArticlesQueryParams, CommentsQueryParams, PaginatedArticles, PaginatedComments } from '@/types/news';
|
|
3
|
+
import type { NewsArticleStatus, NewsCategoryModel, NewsCommentModel, NewsTagModel } from '@creopse/utils';
|
|
4
|
+
/**
|
|
5
|
+
* A hook that provides a set of functions and properties for
|
|
6
|
+
* easily accessing and manipulating news articles, categories, tags, and comments.
|
|
7
|
+
*
|
|
8
|
+
* @returns {Object}
|
|
9
|
+
* @property {boolean} isLoading - A boolean that indicates whether a request is being processed.
|
|
10
|
+
* @property {function} loadTags - A function that loads news tags from the server.
|
|
11
|
+
* @property {function} loadComments - A function that loads news comments from the server.
|
|
12
|
+
* @property {function} loadArticles - A function that loads news articles from the server.
|
|
13
|
+
* @property {function} loadCategories - A function that loads news categories from the server.
|
|
14
|
+
* @property {function} loadArticlesCount - A function that loads the total count of news articles.
|
|
15
|
+
* @property {function} loadArticlesMonths - A function that loads months having at least one article.
|
|
16
|
+
* @property {function} loadArticlesCountByStatus - A function that loads the article count by status.
|
|
17
|
+
* @property {function} loadArticlesCountByAuthor - A function that loads the article count by author.
|
|
18
|
+
* @property {function} addComment - A function that adds a new news comment to the server.
|
|
19
|
+
*/
|
|
20
|
+
export declare const useNews: () => {
|
|
21
|
+
isLoading: boolean;
|
|
22
|
+
loadTags: (filterByIsVisible?: boolean) => Promise<NewsTagModel[]>;
|
|
23
|
+
loadComments: (params: CommentsQueryParams) => Promise<PaginatedComments>;
|
|
24
|
+
loadArticles: (params: ArticlesQueryParams) => Promise<PaginatedArticles>;
|
|
25
|
+
loadCategories: (filterByIsVisible?: boolean) => Promise<NewsCategoryModel[]>;
|
|
26
|
+
loadArticlesCount: () => Promise<number>;
|
|
27
|
+
loadArticlesMonths: () => Promise<string[]>;
|
|
28
|
+
loadArticlesCountByStatus: (status: NewsArticleStatus) => Promise<number>;
|
|
29
|
+
loadArticlesCountByAuthor: (id: number) => Promise<number>;
|
|
30
|
+
addComment: (comment: NewsCommentModel, successCallback?: () => void, errorCallback?: (errorData: any) => void) => Promise<Response<any>>;
|
|
31
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { PaginatedVideoItems, VideoItemsQueryParams } from '@/types/video';
|
|
2
|
+
import type { VideoCategoryModel } from '@creopse/utils';
|
|
3
|
+
/**
|
|
4
|
+
* A hook that provides a set of functions and properties for
|
|
5
|
+
* easily accessing and manipulating video categories and video items.
|
|
6
|
+
*
|
|
7
|
+
* @returns {Object}
|
|
8
|
+
* @property {boolean} isLoading - A boolean that indicates whether a request is being processed.
|
|
9
|
+
* @property {function} loadCategories - A function that loads video categories from the server.
|
|
10
|
+
* @property {function} loadVideoItems - A function that loads video items from the server.
|
|
11
|
+
*/
|
|
12
|
+
export declare const useVideo: () => {
|
|
13
|
+
isLoading: boolean;
|
|
14
|
+
loadCategories: (filterByIsVisible?: boolean) => Promise<VideoCategoryModel[]>;
|
|
15
|
+
loadVideoItems: (params: VideoItemsQueryParams) => Promise<PaginatedVideoItems>;
|
|
16
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { NewsArticleModel, NewsCommentModel } from '@creopse/utils';
|
|
2
|
+
export interface PaginatedResponseMeta {
|
|
3
|
+
links?: {
|
|
4
|
+
first: string;
|
|
5
|
+
last: string;
|
|
6
|
+
prev: string;
|
|
7
|
+
next: string;
|
|
8
|
+
};
|
|
9
|
+
currentPage: number;
|
|
10
|
+
perPage: number;
|
|
11
|
+
total: number;
|
|
12
|
+
lastPage: number;
|
|
13
|
+
}
|
|
14
|
+
export interface ArticlesQueryParams {
|
|
15
|
+
pageSize: number;
|
|
16
|
+
query?: string;
|
|
17
|
+
page?: number;
|
|
18
|
+
status?: number;
|
|
19
|
+
categories?: number[];
|
|
20
|
+
tags?: number[];
|
|
21
|
+
months?: string[];
|
|
22
|
+
}
|
|
23
|
+
export interface PaginatedArticles {
|
|
24
|
+
articles: NewsArticleModel[];
|
|
25
|
+
meta: PaginatedResponseMeta;
|
|
26
|
+
}
|
|
27
|
+
export interface CommentsQueryParams {
|
|
28
|
+
pageSize: number;
|
|
29
|
+
query?: string;
|
|
30
|
+
page?: number;
|
|
31
|
+
}
|
|
32
|
+
export interface PaginatedComments {
|
|
33
|
+
comments: NewsCommentModel[];
|
|
34
|
+
meta: PaginatedResponseMeta;
|
|
35
|
+
}
|
package/types/types/plugin.d.ts
CHANGED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { VideoItemModel } from '@creopse/utils';
|
|
2
|
+
export interface VideoItemsQueryParams {
|
|
3
|
+
pageSize: number;
|
|
4
|
+
source?: string;
|
|
5
|
+
query?: string;
|
|
6
|
+
page?: number;
|
|
7
|
+
visible?: boolean;
|
|
8
|
+
orderByPublishedAt?: boolean;
|
|
9
|
+
categories?: (string | number)[];
|
|
10
|
+
}
|
|
11
|
+
export interface PaginatedVideoItems {
|
|
12
|
+
videoItems: VideoItemModel[];
|
|
13
|
+
meta: {
|
|
14
|
+
links?: {
|
|
15
|
+
first: string;
|
|
16
|
+
last: string;
|
|
17
|
+
prev: string;
|
|
18
|
+
next: string;
|
|
19
|
+
};
|
|
20
|
+
currentPage: number;
|
|
21
|
+
perPage: number;
|
|
22
|
+
total: number;
|
|
23
|
+
lastPage: number;
|
|
24
|
+
};
|
|
25
|
+
}
|