@blocklet/discuss-kit 2.3.28 → 2.3.30

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.
@@ -16,10 +16,6 @@ const locales = require("./locales");
16
16
  const utils = require("./lib/utils");
17
17
  const api = require("./api");
18
18
  const topicInfoSync = require("./hooks/topic-info-sync");
19
- const useAsyncRetry = (fn, deps = []) => {
20
- const state = ahooks.useRequest(fn, { refreshDeps: deps });
21
- return { ...state, value: state == null ? void 0 : state.data, retry: state == null ? void 0 : state.run };
22
- };
23
19
  const getCurrentBlockletComponentName = () => {
24
20
  var _a, _b;
25
21
  const ensureTrailingSlash = (str) => str.endsWith("/") ? str : `${str}/`;
@@ -137,7 +133,6 @@ const DiscussKitComments = react.forwardRef(
137
133
  const { state, sort, add, updateCommentState, interactive, findById, renderInnerFooter } = discussKitUx.useCommentsContext();
138
134
  const { total, order, initialized } = state;
139
135
  const { t } = context.useLocaleContext();
140
- const objectRatingState = useAsyncRetry(() => api.fetchRatings(object.id));
141
136
  topicInfoSync.useTopicInfoSync(object);
142
137
  const handlers = {
143
138
  ADD_COMMENT: (data) => {
@@ -155,7 +150,6 @@ const DiscussKitComments = react.forwardRef(
155
150
  });
156
151
  }
157
152
  },
158
- RATING: () => objectRatingState.retry(),
159
153
  RATING_COMMENT: async ({ commentId }) => {
160
154
  const rating = await api.fetchRatings(commentId);
161
155
  updateCommentState(commentId, (current) => ({
@@ -186,20 +180,6 @@ const DiscussKitComments = react.forwardRef(
186
180
  add(formatComment(data));
187
181
  onSendComment == null ? void 0 : onSendComment(data);
188
182
  };
189
- const handleOnRate = async ({ ratingType, value }) => {
190
- if (!session.user) {
191
- session.login();
192
- throw new Error("Unauthenticated.");
193
- }
194
- await api.post(`/topics/${object.id}/ratings`, { ratingType, value });
195
- };
196
- const handleOnUnrate = async () => {
197
- if (!session.user) {
198
- session.login();
199
- throw new Error("Unauthenticated.");
200
- }
201
- await api.delete(`/topics/${object.id}/ratings`);
202
- };
203
183
  const renderCommentInput = () => {
204
184
  return /* @__PURE__ */ jsxRuntime.jsx(
205
185
  discussKitUx.CommentInput,
@@ -222,16 +202,10 @@ const DiscussKitComments = react.forwardRef(
222
202
  return /* @__PURE__ */ jsxRuntime.jsxs(Container, { ref, children: [
223
203
  /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
224
204
  /* @__PURE__ */ jsxRuntime.jsxs(material.Box, { display: "flex", justifyContent: "space-between", alignItems: "end", children: [
225
- displayReaction && objectRatingState.value && /* @__PURE__ */ jsxRuntime.jsx(material.Box, { children: /* @__PURE__ */ jsxRuntime.jsx(
226
- discussKitUx.GithubReaction,
227
- {
228
- data: objectRatingState.value,
229
- onRate: handleOnRate,
230
- onUnrate: handleOnUnrate,
231
- interactive,
232
- append: reactionAppend
233
- }
234
- ) }),
205
+ displayReaction && /* @__PURE__ */ jsxRuntime.jsxs(discussKitUx.IconButtonGroup, { sx: { alignItems: "flex-end" }, children: [
206
+ /* @__PURE__ */ jsxRuntime.jsx(discussKitUx.GithubReactionContainer, { id: object.id, request: api, interactive }),
207
+ reactionAppend
208
+ ] }),
235
209
  displayConnectButton && (session.user ? /* @__PURE__ */ jsxRuntime.jsx(SessionManager, { style: { padding: 0 }, showText: true, showRole: true, session }) : /* @__PURE__ */ jsxRuntime.jsx(Button, { size: "medium", variant: "contained", color: "primary", onClick: () => session.login(), children: t("connect") }))
236
210
  ] }),
237
211
  displayConnectButton && !session.user && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "input-no-connect", children: /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "connect-tip", children: [
@@ -8,17 +8,13 @@ import Button from "@arcblock/ux/lib/Button";
8
8
  import { Alert, AlertTitle, Box, CircularProgress } from "@mui/material";
9
9
  import { useLocaleContext, LocaleProvider } from "@arcblock/ux/lib/Locale/context";
10
10
  import { ErrorBoundary } from "react-error-boundary";
11
- import { useDefaultApiErrorHandler, useCommentsContext, useSubscription, GithubReaction, SegmentedControl, CommentList, getWsClient, UploaderProvider, InternalThemeProvider, ConfirmProvider, DefaultEditorConfigProvider, CommentsProvider, CommentInput } from "@blocklet/discuss-kit-ux";
11
+ import { useDefaultApiErrorHandler, useCommentsContext, useSubscription, IconButtonGroup, GithubReactionContainer, SegmentedControl, CommentList, getWsClient, UploaderProvider, InternalThemeProvider, ConfirmProvider, DefaultEditorConfigProvider, CommentsProvider, CommentInput } from "@blocklet/discuss-kit-ux";
12
12
  import { useRequest } from "ahooks";
13
13
  import ErrorFallback from "./components/error-fallback";
14
14
  import { translations } from "./locales";
15
15
  import { discussKitPrefix } from "./lib/utils";
16
16
  import api, { fetchRatings } from "./api";
17
17
  import { useTopicInfoSync } from "./hooks/topic-info-sync";
18
- const useAsyncRetry = (fn, deps = []) => {
19
- const state = useRequest(fn, { refreshDeps: deps });
20
- return { ...state, value: state == null ? void 0 : state.data, retry: state == null ? void 0 : state.run };
21
- };
22
18
  const getCurrentBlockletComponentName = () => {
23
19
  var _a, _b;
24
20
  const ensureTrailingSlash = (str) => str.endsWith("/") ? str : `${str}/`;
@@ -136,7 +132,6 @@ const DiscussKitComments = forwardRef(
136
132
  const { state, sort, add, updateCommentState, interactive, findById, renderInnerFooter } = useCommentsContext();
137
133
  const { total, order, initialized } = state;
138
134
  const { t } = useLocaleContext();
139
- const objectRatingState = useAsyncRetry(() => fetchRatings(object.id));
140
135
  useTopicInfoSync(object);
141
136
  const handlers = {
142
137
  ADD_COMMENT: (data) => {
@@ -154,7 +149,6 @@ const DiscussKitComments = forwardRef(
154
149
  });
155
150
  }
156
151
  },
157
- RATING: () => objectRatingState.retry(),
158
152
  RATING_COMMENT: async ({ commentId }) => {
159
153
  const rating = await fetchRatings(commentId);
160
154
  updateCommentState(commentId, (current) => ({
@@ -185,20 +179,6 @@ const DiscussKitComments = forwardRef(
185
179
  add(formatComment(data));
186
180
  onSendComment == null ? void 0 : onSendComment(data);
187
181
  };
188
- const handleOnRate = async ({ ratingType, value }) => {
189
- if (!session.user) {
190
- session.login();
191
- throw new Error("Unauthenticated.");
192
- }
193
- await api.post(`/topics/${object.id}/ratings`, { ratingType, value });
194
- };
195
- const handleOnUnrate = async () => {
196
- if (!session.user) {
197
- session.login();
198
- throw new Error("Unauthenticated.");
199
- }
200
- await api.delete(`/topics/${object.id}/ratings`);
201
- };
202
182
  const renderCommentInput = () => {
203
183
  return /* @__PURE__ */ jsx(
204
184
  CommentInput,
@@ -221,16 +201,10 @@ const DiscussKitComments = forwardRef(
221
201
  return /* @__PURE__ */ jsxs(Container, { ref, children: [
222
202
  /* @__PURE__ */ jsxs(Fragment, { children: [
223
203
  /* @__PURE__ */ jsxs(Box, { display: "flex", justifyContent: "space-between", alignItems: "end", children: [
224
- displayReaction && objectRatingState.value && /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(
225
- GithubReaction,
226
- {
227
- data: objectRatingState.value,
228
- onRate: handleOnRate,
229
- onUnrate: handleOnUnrate,
230
- interactive,
231
- append: reactionAppend
232
- }
233
- ) }),
204
+ displayReaction && /* @__PURE__ */ jsxs(IconButtonGroup, { sx: { alignItems: "flex-end" }, children: [
205
+ /* @__PURE__ */ jsx(GithubReactionContainer, { id: object.id, request: api, interactive }),
206
+ reactionAppend
207
+ ] }),
234
208
  displayConnectButton && (session.user ? /* @__PURE__ */ jsx(SessionManager, { style: { padding: 0 }, showText: true, showRole: true, session }) : /* @__PURE__ */ jsx(Button, { size: "medium", variant: "contained", color: "primary", onClick: () => session.login(), children: t("connect") }))
235
209
  ] }),
236
210
  displayConnectButton && !session.user && /* @__PURE__ */ jsx("div", { className: "input-no-connect", children: /* @__PURE__ */ jsxs("span", { className: "connect-tip", children: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/discuss-kit",
3
- "version": "2.3.28",
3
+ "version": "2.3.30",
4
4
  "description": "A react component for Discuss Kit blocklet.",
5
5
  "main": "./lib/cjs/index.js",
6
6
  "module": "./lib/es/index.js",
@@ -49,8 +49,8 @@
49
49
  "rehype-sanitize": "^5.0.1",
50
50
  "timeago.js": "^4.0.2",
51
51
  "url-join": "^4.0.1",
52
- "@blocklet/discuss-kit-ux": "^2.3.28",
53
- "@blocklet/editor": "^2.3.28"
52
+ "@blocklet/discuss-kit-ux": "^2.3.30",
53
+ "@blocklet/editor": "^2.3.30"
54
54
  },
55
55
  "peerDependencies": {
56
56
  "@arcblock/did-connect": "^2.10.36",