@blocklet/discuss-kit 1.0.0
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/LICENSE +13 -0
- package/README.md +15 -0
- package/lib/cjs/api.js +45 -0
- package/lib/cjs/comment-list.js +117 -0
- package/lib/cjs/components/comment.js +335 -0
- package/lib/cjs/components/error-fallback.js +26 -0
- package/lib/cjs/components/menu.js +84 -0
- package/lib/cjs/components/rating/binary-thumb.js +199 -0
- package/lib/cjs/components/rating/emoji-based.js +39 -0
- package/lib/cjs/components/rating/index.js +9 -0
- package/lib/cjs/components/rating/rating.js +93 -0
- package/lib/cjs/context.js +77 -0
- package/lib/cjs/did-comment-with-session.js +25 -0
- package/lib/cjs/did-comment.js +389 -0
- package/lib/cjs/hooks.js +202 -0
- package/lib/cjs/index.js +21 -0
- package/lib/cjs/lib/utils.js +17 -0
- package/lib/cjs/locales/en.js +27 -0
- package/lib/cjs/locales/index.js +10 -0
- package/lib/cjs/locales/zh.js +27 -0
- package/lib/cjs/session.js +14 -0
- package/lib/cjs/theme-provider.js +48 -0
- package/lib/cjs/ws.js +39 -0
- package/lib/es/api.js +43 -0
- package/lib/es/comment-list.js +112 -0
- package/lib/es/components/comment.js +309 -0
- package/lib/es/components/error-fallback.js +23 -0
- package/lib/es/components/menu.js +77 -0
- package/lib/es/components/rating/binary-thumb.js +176 -0
- package/lib/es/components/rating/emoji-based.js +37 -0
- package/lib/es/components/rating/index.js +4 -0
- package/lib/es/components/rating/rating.js +91 -0
- package/lib/es/context.js +74 -0
- package/lib/es/did-comment-with-session.js +24 -0
- package/lib/es/did-comment.js +377 -0
- package/lib/es/hooks.js +197 -0
- package/lib/es/index.js +8 -0
- package/lib/es/lib/utils.js +17 -0
- package/lib/es/locales/en.js +26 -0
- package/lib/es/locales/index.js +7 -0
- package/lib/es/locales/zh.js +26 -0
- package/lib/es/session.js +14 -0
- package/lib/es/theme-provider.js +46 -0
- package/lib/es/ws.js +37 -0
- package/package.json +79 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Copyright 2018-2020 ArcBlock
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
package/README.md
ADDED
package/lib/cjs/api.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const axios = require("axios");
|
|
4
|
+
const _interopDefaultLegacy = (e) => e && typeof e === "object" && "default" in e ? e : { default: e };
|
|
5
|
+
const axios__default = /* @__PURE__ */ _interopDefaultLegacy(axios);
|
|
6
|
+
const request = axios__default.default.create({ baseURL: "/", timeout: 5e3 });
|
|
7
|
+
request.interceptors.request.use(
|
|
8
|
+
(config) => {
|
|
9
|
+
return config;
|
|
10
|
+
},
|
|
11
|
+
(error) => Promise.reject(error)
|
|
12
|
+
);
|
|
13
|
+
const fetchRatingStats = async (id) => {
|
|
14
|
+
const { data } = await request.get(`/ratings/${id}`);
|
|
15
|
+
return data;
|
|
16
|
+
};
|
|
17
|
+
const fetchComments = async (params) => {
|
|
18
|
+
try {
|
|
19
|
+
const { data } = await request.get("/comments", { params });
|
|
20
|
+
return data;
|
|
21
|
+
} catch (e) {
|
|
22
|
+
console.error(e);
|
|
23
|
+
throw e;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const reply = async ({ commentId, parentId, content }) => {
|
|
27
|
+
const { data } = await request.post(`/comments/${commentId}/replies`, { content, parentId });
|
|
28
|
+
return data;
|
|
29
|
+
};
|
|
30
|
+
const fetchMoreReplies = async ({ commentId, cursor, limit = 10 }) => {
|
|
31
|
+
try {
|
|
32
|
+
const { data } = await request.get(`/comments/${commentId}/replies`, {
|
|
33
|
+
params: { cursor, limit, embed: "rating" }
|
|
34
|
+
});
|
|
35
|
+
return data;
|
|
36
|
+
} catch (e) {
|
|
37
|
+
console.error(e);
|
|
38
|
+
throw e;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
exports.default = request;
|
|
42
|
+
exports.fetchComments = fetchComments;
|
|
43
|
+
exports.fetchMoreReplies = fetchMoreReplies;
|
|
44
|
+
exports.fetchRatingStats = fetchRatingStats;
|
|
45
|
+
exports.reply = reply;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const react = require("react");
|
|
3
|
+
const styled = require("@emotion/styled");
|
|
4
|
+
const Button = require("@arcblock/ux/lib/Button");
|
|
5
|
+
const CircularProgress = require("@mui/material/CircularProgress");
|
|
6
|
+
const context$1 = require("@arcblock/ux/lib/Locale/context");
|
|
7
|
+
const Dialog = require("@arcblock/ux/lib/Dialog");
|
|
8
|
+
const Comment = require("./components/comment");
|
|
9
|
+
const context = require("./context");
|
|
10
|
+
const api = require("./api");
|
|
11
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
12
|
+
const _interopDefaultLegacy = (e) => e && typeof e === "object" && "default" in e ? e : { default: e };
|
|
13
|
+
const styled__default = /* @__PURE__ */ _interopDefaultLegacy(styled);
|
|
14
|
+
const Button__default = /* @__PURE__ */ _interopDefaultLegacy(Button);
|
|
15
|
+
const CircularProgress__default = /* @__PURE__ */ _interopDefaultLegacy(CircularProgress);
|
|
16
|
+
const Comment__default = /* @__PURE__ */ _interopDefaultLegacy(Comment);
|
|
17
|
+
const api__default = /* @__PURE__ */ _interopDefaultLegacy(api);
|
|
18
|
+
function CommentList() {
|
|
19
|
+
const {
|
|
20
|
+
comments,
|
|
21
|
+
loadMore,
|
|
22
|
+
hasMore,
|
|
23
|
+
loading,
|
|
24
|
+
removeComment
|
|
25
|
+
} = context.useCommentsContext();
|
|
26
|
+
const {
|
|
27
|
+
t
|
|
28
|
+
} = react.useContext(context$1.LocaleContext);
|
|
29
|
+
const [waitDelRow, setWaitDelRow] = react.useState({});
|
|
30
|
+
const handleConfirmDelete = async (comment) => {
|
|
31
|
+
try {
|
|
32
|
+
setWaitDelRow({});
|
|
33
|
+
await api__default.default.delete(`/comments/${comment.id}`);
|
|
34
|
+
removeComment(comment);
|
|
35
|
+
} catch (e) {
|
|
36
|
+
console.error(e);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
if (loading) {
|
|
40
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Center, {
|
|
41
|
+
style: {
|
|
42
|
+
width: "100%"
|
|
43
|
+
},
|
|
44
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(CircularProgress__default.default, {})
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(Container, {
|
|
48
|
+
children: [comments.length === 0 && /* @__PURE__ */ jsxRuntime.jsx("div", {
|
|
49
|
+
className: "empty",
|
|
50
|
+
children: t("empty")
|
|
51
|
+
}), comments.length > 0 && comments.map((comment, index) => {
|
|
52
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Comment__default.default, {
|
|
53
|
+
comment,
|
|
54
|
+
index: index + 1,
|
|
55
|
+
onDelete: setWaitDelRow
|
|
56
|
+
}, comment.id);
|
|
57
|
+
}), hasMore && /* @__PURE__ */ jsxRuntime.jsx("div", {
|
|
58
|
+
className: "load-more",
|
|
59
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(Button__default.default, {
|
|
60
|
+
onClick: loadMore,
|
|
61
|
+
disabled: loading,
|
|
62
|
+
variant: "outlined",
|
|
63
|
+
color: "primary",
|
|
64
|
+
size: "small",
|
|
65
|
+
children: t("loadMore")
|
|
66
|
+
})
|
|
67
|
+
}), /* @__PURE__ */ jsxRuntime.jsx(Dialog.Confirm, {
|
|
68
|
+
open: !!waitDelRow.id,
|
|
69
|
+
title: t("tip"),
|
|
70
|
+
onConfirm: () => {
|
|
71
|
+
handleConfirmDelete(waitDelRow);
|
|
72
|
+
},
|
|
73
|
+
confirmButton: {
|
|
74
|
+
text: t("confirm"),
|
|
75
|
+
props: {
|
|
76
|
+
variant: "contained",
|
|
77
|
+
color: "error"
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
cancelButton: {
|
|
81
|
+
text: t("cancel"),
|
|
82
|
+
props: {
|
|
83
|
+
color: "inherit"
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
onCancel: () => {
|
|
87
|
+
setWaitDelRow({});
|
|
88
|
+
},
|
|
89
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("span", {
|
|
90
|
+
children: t("deleteCommentDesc")
|
|
91
|
+
})
|
|
92
|
+
})]
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
CommentList.propTypes = {};
|
|
96
|
+
CommentList.defaultProps = {};
|
|
97
|
+
const Center = styled__default.default.div`
|
|
98
|
+
width: 100%;
|
|
99
|
+
padding: 120px 0 0 0;
|
|
100
|
+
display: flex;
|
|
101
|
+
align-items: center;
|
|
102
|
+
justify-content: center;
|
|
103
|
+
`;
|
|
104
|
+
const Container = styled__default.default.div`
|
|
105
|
+
width: 100%;
|
|
106
|
+
.empty {
|
|
107
|
+
text-align: center;
|
|
108
|
+
color: #9397a1;
|
|
109
|
+
font-size: 16px;
|
|
110
|
+
margin-top: 44px;
|
|
111
|
+
}
|
|
112
|
+
.load-more {
|
|
113
|
+
text-align: center;
|
|
114
|
+
margin: 24px 0;
|
|
115
|
+
}
|
|
116
|
+
`;
|
|
117
|
+
module.exports = CommentList;
|
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const React = require("react");
|
|
3
|
+
const styled = require("@emotion/styled");
|
|
4
|
+
const Box = require("@mui/material/Box");
|
|
5
|
+
const Button = require("@mui/material/Button");
|
|
6
|
+
const PropTypes = require("prop-types");
|
|
7
|
+
const NavigateNextIcon = require("@mui/icons-material/NavigateNext");
|
|
8
|
+
const DIDAddress = require("@arcblock/did-connect/lib/Address");
|
|
9
|
+
const timeago_js = require("timeago.js");
|
|
10
|
+
const context$1 = require("@arcblock/ux/lib/Locale/context");
|
|
11
|
+
const discussKitUx = require("@blocklet/discuss-kit-ux");
|
|
12
|
+
const rating = require("./rating");
|
|
13
|
+
const Menu = require("./menu");
|
|
14
|
+
const api = require("../api");
|
|
15
|
+
const utils = require("../lib/utils");
|
|
16
|
+
const context = require("../context");
|
|
17
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
18
|
+
const _interopDefaultLegacy = (e) => e && typeof e === "object" && "default" in e ? e : { default: e };
|
|
19
|
+
function _interopNamespace(e) {
|
|
20
|
+
if (e && e.__esModule)
|
|
21
|
+
return e;
|
|
22
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
23
|
+
if (e) {
|
|
24
|
+
for (const k in e) {
|
|
25
|
+
if (k !== "default") {
|
|
26
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
27
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
get: () => e[k]
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
n.default = e;
|
|
35
|
+
return Object.freeze(n);
|
|
36
|
+
}
|
|
37
|
+
const React__namespace = /* @__PURE__ */ _interopNamespace(React);
|
|
38
|
+
const styled__default = /* @__PURE__ */ _interopDefaultLegacy(styled);
|
|
39
|
+
const Box__default = /* @__PURE__ */ _interopDefaultLegacy(Box);
|
|
40
|
+
const Button__default = /* @__PURE__ */ _interopDefaultLegacy(Button);
|
|
41
|
+
const PropTypes__default = /* @__PURE__ */ _interopDefaultLegacy(PropTypes);
|
|
42
|
+
const NavigateNextIcon__default = /* @__PURE__ */ _interopDefaultLegacy(NavigateNextIcon);
|
|
43
|
+
const DIDAddress__default = /* @__PURE__ */ _interopDefaultLegacy(DIDAddress);
|
|
44
|
+
const Menu__default = /* @__PURE__ */ _interopDefaultLegacy(Menu);
|
|
45
|
+
const api__default = /* @__PURE__ */ _interopDefaultLegacy(api);
|
|
46
|
+
const SvgMessage = (props) => /* @__PURE__ */ React__namespace.createElement("svg", {
|
|
47
|
+
width: 32,
|
|
48
|
+
height: 32,
|
|
49
|
+
viewBox: "0 0 24 24",
|
|
50
|
+
...props
|
|
51
|
+
}, /* @__PURE__ */ React__namespace.createElement("path", {
|
|
52
|
+
fill: "none",
|
|
53
|
+
stroke: "#888888",
|
|
54
|
+
strokeLinecap: "round",
|
|
55
|
+
strokeLinejoin: "round",
|
|
56
|
+
strokeWidth: 2,
|
|
57
|
+
d: "m3 20l1.3-3.9A9 8 0 1 1 7.7 19L3 20"
|
|
58
|
+
}));
|
|
59
|
+
function CommentReplies({
|
|
60
|
+
comment,
|
|
61
|
+
onDelete,
|
|
62
|
+
...rest
|
|
63
|
+
}) {
|
|
64
|
+
const {
|
|
65
|
+
t
|
|
66
|
+
} = React.useContext(context$1.LocaleContext);
|
|
67
|
+
const {
|
|
68
|
+
loadMoreReplies
|
|
69
|
+
} = context.useCommentsContext();
|
|
70
|
+
const {
|
|
71
|
+
replies,
|
|
72
|
+
totalReplies
|
|
73
|
+
} = comment;
|
|
74
|
+
if (!(replies == null ? void 0 : replies.length)) {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(Box__default.default, {
|
|
78
|
+
mt: 1,
|
|
79
|
+
...rest,
|
|
80
|
+
children: [replies.map((item) => {
|
|
81
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", {
|
|
82
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(Comment, {
|
|
83
|
+
comment: item,
|
|
84
|
+
onDelete,
|
|
85
|
+
rootComment: comment
|
|
86
|
+
})
|
|
87
|
+
}, item.id);
|
|
88
|
+
}), totalReplies > replies.length && /* @__PURE__ */ jsxRuntime.jsx(Button__default.default, {
|
|
89
|
+
onClick: () => loadMoreReplies(comment.id),
|
|
90
|
+
variant: "outlined",
|
|
91
|
+
color: "inherit",
|
|
92
|
+
size: "small",
|
|
93
|
+
endIcon: /* @__PURE__ */ jsxRuntime.jsx(NavigateNextIcon__default.default, {}),
|
|
94
|
+
sx: {
|
|
95
|
+
mt: 2,
|
|
96
|
+
ml: 6,
|
|
97
|
+
color: "grey.600",
|
|
98
|
+
borderColor: "grey.400",
|
|
99
|
+
fontSize: 12,
|
|
100
|
+
textTransform: "none"
|
|
101
|
+
},
|
|
102
|
+
children: t("showMoreReplies")
|
|
103
|
+
})]
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
CommentReplies.propTypes = {
|
|
107
|
+
comment: PropTypes__default.default.object.isRequired,
|
|
108
|
+
onDelete: PropTypes__default.default.func.isRequired
|
|
109
|
+
};
|
|
110
|
+
function Comment({
|
|
111
|
+
comment,
|
|
112
|
+
onDelete,
|
|
113
|
+
rootComment,
|
|
114
|
+
...rest
|
|
115
|
+
}) {
|
|
116
|
+
var _a, _b, _c, _d;
|
|
117
|
+
const {
|
|
118
|
+
session,
|
|
119
|
+
addComment,
|
|
120
|
+
updateComment,
|
|
121
|
+
manageMode,
|
|
122
|
+
flatMode
|
|
123
|
+
} = context.useCommentsContext();
|
|
124
|
+
const {
|
|
125
|
+
t,
|
|
126
|
+
locale
|
|
127
|
+
} = React.useContext(context$1.LocaleContext);
|
|
128
|
+
const [inputBoxVisible, setInputBoxVisible] = React.useState(false);
|
|
129
|
+
const [editMode, setEditMode] = React.useState(false);
|
|
130
|
+
const isCommenter = ((_a = session == null ? void 0 : session.user) == null ? void 0 : _a.did) === comment.commenter.did;
|
|
131
|
+
const canEditOrDelete = !comment.deletedAt && (isCommenter || manageMode);
|
|
132
|
+
const menuItems = [...canEditOrDelete ? [{
|
|
133
|
+
text: /* @__PURE__ */ jsxRuntime.jsx(Box__default.default, {
|
|
134
|
+
component: "span",
|
|
135
|
+
sx: {
|
|
136
|
+
color: "error.main"
|
|
137
|
+
},
|
|
138
|
+
children: t("delete")
|
|
139
|
+
}),
|
|
140
|
+
onClick: () => onDelete(comment)
|
|
141
|
+
}, {
|
|
142
|
+
text: /* @__PURE__ */ jsxRuntime.jsx(Box__default.default, {
|
|
143
|
+
component: "span",
|
|
144
|
+
children: t("edit")
|
|
145
|
+
}),
|
|
146
|
+
onClick: () => setEditMode(true)
|
|
147
|
+
}] : []];
|
|
148
|
+
const sendReply = async (content) => {
|
|
149
|
+
const commentId = (rootComment == null ? void 0 : rootComment.id) || comment.commentId || comment.id;
|
|
150
|
+
const data = await utils.minDelay(api.reply({
|
|
151
|
+
commentId,
|
|
152
|
+
parentId: comment.id,
|
|
153
|
+
content
|
|
154
|
+
}), 800);
|
|
155
|
+
setInputBoxVisible(false);
|
|
156
|
+
addComment(data);
|
|
157
|
+
};
|
|
158
|
+
const handleOnRate = async ({
|
|
159
|
+
ratingType,
|
|
160
|
+
value
|
|
161
|
+
}) => {
|
|
162
|
+
if (!session.user) {
|
|
163
|
+
session.login();
|
|
164
|
+
throw new Error("Unauthenticated.");
|
|
165
|
+
}
|
|
166
|
+
await api__default.default.post(`/objects/${comment.objectId}/comments/${comment.id}/ratings`, {
|
|
167
|
+
ratingType,
|
|
168
|
+
value
|
|
169
|
+
});
|
|
170
|
+
};
|
|
171
|
+
const handleOnUnrate = async () => {
|
|
172
|
+
if (!session.user) {
|
|
173
|
+
session.login();
|
|
174
|
+
throw new Error("Unauthenticated.");
|
|
175
|
+
}
|
|
176
|
+
await api__default.default.delete(`/objects/${comment.objectId}/comments/${comment.id}/ratings`);
|
|
177
|
+
};
|
|
178
|
+
const handleUpdateComment = async (content) => {
|
|
179
|
+
await api__default.default.put(`/comments/${comment.id}`, {
|
|
180
|
+
content
|
|
181
|
+
});
|
|
182
|
+
updateComment(comment.id, (current) => ({
|
|
183
|
+
...current,
|
|
184
|
+
content
|
|
185
|
+
}));
|
|
186
|
+
};
|
|
187
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(Root, {
|
|
188
|
+
...rest,
|
|
189
|
+
children: [/* @__PURE__ */ jsxRuntime.jsx(discussKitUx.Avatar, {
|
|
190
|
+
did: comment.commenter.did,
|
|
191
|
+
src: comment.commenter.avatar,
|
|
192
|
+
size: 36,
|
|
193
|
+
shape: "circle",
|
|
194
|
+
variant: "circle"
|
|
195
|
+
}), /* @__PURE__ */ jsxRuntime.jsxs(Box__default.default, {
|
|
196
|
+
flex: "1",
|
|
197
|
+
pl: 2,
|
|
198
|
+
overflow: "hidden",
|
|
199
|
+
children: [/* @__PURE__ */ jsxRuntime.jsxs(Box__default.default, {
|
|
200
|
+
display: "flex",
|
|
201
|
+
justifyContent: "space-between",
|
|
202
|
+
alignItems: "start",
|
|
203
|
+
children: [/* @__PURE__ */ jsxRuntime.jsxs(Box__default.default, {
|
|
204
|
+
children: [/* @__PURE__ */ jsxRuntime.jsxs(Box__default.default, {
|
|
205
|
+
display: "flex",
|
|
206
|
+
alignItems: "center",
|
|
207
|
+
gap: 1,
|
|
208
|
+
flexWrap: "wrap",
|
|
209
|
+
color: "#333",
|
|
210
|
+
lineHeight: 1,
|
|
211
|
+
children: [/* @__PURE__ */ jsxRuntime.jsx("span", {
|
|
212
|
+
children: comment.commenter.fullName || "Unknown"
|
|
213
|
+
}), /* @__PURE__ */ jsxRuntime.jsxs("div", {
|
|
214
|
+
children: ["(", /* @__PURE__ */ jsxRuntime.jsx(DIDAddress__default.default, {
|
|
215
|
+
copyable: false,
|
|
216
|
+
responsive: false,
|
|
217
|
+
compact: true,
|
|
218
|
+
inline: true,
|
|
219
|
+
children: comment.commenter.did
|
|
220
|
+
}), ")"]
|
|
221
|
+
}), /* @__PURE__ */ jsxRuntime.jsx(Box__default.default, {
|
|
222
|
+
width: {
|
|
223
|
+
xs: "100%",
|
|
224
|
+
md: "auto"
|
|
225
|
+
},
|
|
226
|
+
fontSize: 13,
|
|
227
|
+
color: "grey.500",
|
|
228
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("span", {
|
|
229
|
+
children: timeago_js.format(comment.createdAt, locale === "zh" ? "zh_CN" : "en_US")
|
|
230
|
+
})
|
|
231
|
+
})]
|
|
232
|
+
}), ((_b = comment.replyTo) == null ? void 0 : _b.did) && (flatMode || comment.parentId !== comment.commentId) && /* @__PURE__ */ jsxRuntime.jsxs(Box__default.default, {
|
|
233
|
+
mt: 0.5,
|
|
234
|
+
fontSize: 13,
|
|
235
|
+
lineHeight: 1,
|
|
236
|
+
color: "primary.light",
|
|
237
|
+
sx: {
|
|
238
|
+
".did-address-text": {
|
|
239
|
+
color: "primary.light"
|
|
240
|
+
}
|
|
241
|
+
},
|
|
242
|
+
children: ["@", /* @__PURE__ */ jsxRuntime.jsx(Box__default.default, {
|
|
243
|
+
component: "span",
|
|
244
|
+
mr: 1,
|
|
245
|
+
children: comment.replyTo.fullName
|
|
246
|
+
}), "(", /* @__PURE__ */ jsxRuntime.jsx(DIDAddress__default.default, {
|
|
247
|
+
copyable: false,
|
|
248
|
+
responsive: false,
|
|
249
|
+
compact: true,
|
|
250
|
+
inline: true,
|
|
251
|
+
children: comment.replyTo.did
|
|
252
|
+
}), ")"]
|
|
253
|
+
})]
|
|
254
|
+
}), !!(menuItems == null ? void 0 : menuItems.length) && /* @__PURE__ */ jsxRuntime.jsx(Menu__default.default, {
|
|
255
|
+
items: menuItems,
|
|
256
|
+
style: {
|
|
257
|
+
position: "absolute",
|
|
258
|
+
right: 0,
|
|
259
|
+
top: 16
|
|
260
|
+
}
|
|
261
|
+
})]
|
|
262
|
+
}), /* @__PURE__ */ jsxRuntime.jsxs(Box__default.default, {
|
|
263
|
+
mt: 1,
|
|
264
|
+
children: [!comment.deletedAt && /* @__PURE__ */ jsxRuntime.jsx(discussKitUx.PostContent, {
|
|
265
|
+
content: comment.content,
|
|
266
|
+
editing: editMode,
|
|
267
|
+
onExitEditing: () => setEditMode(false),
|
|
268
|
+
onSubmit: handleUpdateComment
|
|
269
|
+
}), comment.deletedAt && /* @__PURE__ */ jsxRuntime.jsx(Box__default.default, {
|
|
270
|
+
display: "inline-block",
|
|
271
|
+
px: 2,
|
|
272
|
+
py: 1,
|
|
273
|
+
mt: 1,
|
|
274
|
+
fontSize: 14,
|
|
275
|
+
bgcolor: "grey.100",
|
|
276
|
+
color: "grey.600",
|
|
277
|
+
borderRadius: 1,
|
|
278
|
+
children: t("deleted")
|
|
279
|
+
})]
|
|
280
|
+
}), !manageMode && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
281
|
+
children: [/* @__PURE__ */ jsxRuntime.jsxs(Box__default.default, {
|
|
282
|
+
display: "flex",
|
|
283
|
+
alignItems: "center",
|
|
284
|
+
mt: 1.5,
|
|
285
|
+
children: [/* @__PURE__ */ jsxRuntime.jsx(rating.BinaryThumb, {
|
|
286
|
+
selected: (_c = comment.rating) == null ? void 0 : _c.myRating,
|
|
287
|
+
countPerValue: (_d = comment.rating) == null ? void 0 : _d.counts,
|
|
288
|
+
onRate: handleOnRate,
|
|
289
|
+
onUnrate: handleOnUnrate
|
|
290
|
+
}), /* @__PURE__ */ jsxRuntime.jsx(Box__default.default, {
|
|
291
|
+
onClick: () => utils.protectLogin(session, () => setInputBoxVisible(!inputBoxVisible)),
|
|
292
|
+
sx: {
|
|
293
|
+
lineHeight: 1,
|
|
294
|
+
"&:hover": {
|
|
295
|
+
cursor: "pointer"
|
|
296
|
+
}
|
|
297
|
+
},
|
|
298
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(SvgMessage, {
|
|
299
|
+
style: {
|
|
300
|
+
width: "auto",
|
|
301
|
+
height: 16
|
|
302
|
+
}
|
|
303
|
+
})
|
|
304
|
+
})]
|
|
305
|
+
}), inputBoxVisible && /* @__PURE__ */ jsxRuntime.jsx(Box__default.default, {
|
|
306
|
+
my: 2,
|
|
307
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(discussKitUx.CommentInput, {
|
|
308
|
+
send: sendReply
|
|
309
|
+
})
|
|
310
|
+
})]
|
|
311
|
+
}), !comment.parentId && /* @__PURE__ */ jsxRuntime.jsx(CommentReplies, {
|
|
312
|
+
comment,
|
|
313
|
+
onDelete
|
|
314
|
+
})]
|
|
315
|
+
})]
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
Comment.propTypes = {
|
|
319
|
+
comment: PropTypes__default.default.object.isRequired,
|
|
320
|
+
onDelete: PropTypes__default.default.func,
|
|
321
|
+
rootComment: PropTypes__default.default.object
|
|
322
|
+
};
|
|
323
|
+
Comment.defaultProps = {
|
|
324
|
+
onDelete: void 0,
|
|
325
|
+
rootComment: void 0
|
|
326
|
+
};
|
|
327
|
+
const Root = styled__default.default(Box__default.default)`
|
|
328
|
+
display: flex;
|
|
329
|
+
position: relative;
|
|
330
|
+
padding: 24px 0 0 0;
|
|
331
|
+
&:first-of-type {
|
|
332
|
+
flex-shrink: 0;
|
|
333
|
+
}
|
|
334
|
+
`;
|
|
335
|
+
module.exports = Comment;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const PropTypes = require("prop-types");
|
|
3
|
+
const Alert = require("@mui/material/Alert");
|
|
4
|
+
const AlertTitle = require("@mui/material/AlertTitle");
|
|
5
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
6
|
+
const _interopDefaultLegacy = (e) => e && typeof e === "object" && "default" in e ? e : { default: e };
|
|
7
|
+
const PropTypes__default = /* @__PURE__ */ _interopDefaultLegacy(PropTypes);
|
|
8
|
+
const Alert__default = /* @__PURE__ */ _interopDefaultLegacy(Alert);
|
|
9
|
+
const AlertTitle__default = /* @__PURE__ */ _interopDefaultLegacy(AlertTitle);
|
|
10
|
+
function ErrorFallback({
|
|
11
|
+
error
|
|
12
|
+
}) {
|
|
13
|
+
const errorMessageElement = process.env.NODE_ENV === "production" ? null : /* @__PURE__ */ jsxRuntime.jsx("pre", {
|
|
14
|
+
children: error.message
|
|
15
|
+
});
|
|
16
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(Alert__default.default, {
|
|
17
|
+
severity: "warning",
|
|
18
|
+
children: [/* @__PURE__ */ jsxRuntime.jsx(AlertTitle__default.default, {
|
|
19
|
+
children: "Oops!"
|
|
20
|
+
}), "DID Comments is not working properly.", errorMessageElement]
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
ErrorFallback.propTypes = {
|
|
24
|
+
error: PropTypes__default.default.instanceOf(Error).isRequired
|
|
25
|
+
};
|
|
26
|
+
module.exports = ErrorFallback;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const react = require("react");
|
|
3
|
+
const PropTypes = require("prop-types");
|
|
4
|
+
const styled = require("@emotion/styled");
|
|
5
|
+
const IconButton = require("@mui/material/IconButton");
|
|
6
|
+
const MoreVertIcon = require("@mui/icons-material/MoreVert");
|
|
7
|
+
const Box = require("@mui/material/Box");
|
|
8
|
+
const MuiMenu = require("@mui/material/Menu");
|
|
9
|
+
const MuiMenuItem = require("@mui/material/MenuItem");
|
|
10
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
11
|
+
const _interopDefaultLegacy = (e) => e && typeof e === "object" && "default" in e ? e : { default: e };
|
|
12
|
+
const PropTypes__default = /* @__PURE__ */ _interopDefaultLegacy(PropTypes);
|
|
13
|
+
const styled__default = /* @__PURE__ */ _interopDefaultLegacy(styled);
|
|
14
|
+
const IconButton__default = /* @__PURE__ */ _interopDefaultLegacy(IconButton);
|
|
15
|
+
const MoreVertIcon__default = /* @__PURE__ */ _interopDefaultLegacy(MoreVertIcon);
|
|
16
|
+
const Box__default = /* @__PURE__ */ _interopDefaultLegacy(Box);
|
|
17
|
+
const MuiMenu__default = /* @__PURE__ */ _interopDefaultLegacy(MuiMenu);
|
|
18
|
+
const MuiMenuItem__default = /* @__PURE__ */ _interopDefaultLegacy(MuiMenuItem);
|
|
19
|
+
function Menu({
|
|
20
|
+
items,
|
|
21
|
+
...rest
|
|
22
|
+
}) {
|
|
23
|
+
const [anchorEl, setAnchorEl] = react.useState(null);
|
|
24
|
+
const open = Boolean(anchorEl);
|
|
25
|
+
const handleClick = (event) => {
|
|
26
|
+
setAnchorEl(event.currentTarget);
|
|
27
|
+
};
|
|
28
|
+
const handleClose = () => {
|
|
29
|
+
setAnchorEl(null);
|
|
30
|
+
};
|
|
31
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(Root, {
|
|
32
|
+
...rest,
|
|
33
|
+
children: [/* @__PURE__ */ jsxRuntime.jsx(IconButton__default.default, {
|
|
34
|
+
size: "medium",
|
|
35
|
+
onClick: handleClick,
|
|
36
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(MoreVertIcon__default.default, {
|
|
37
|
+
sx: {
|
|
38
|
+
fontSize: 18
|
|
39
|
+
}
|
|
40
|
+
})
|
|
41
|
+
}), /* @__PURE__ */ jsxRuntime.jsx(MuiMenu__default.default, {
|
|
42
|
+
anchorEl,
|
|
43
|
+
anchorOrigin: {
|
|
44
|
+
vertical: "bottom",
|
|
45
|
+
horizontal: "right"
|
|
46
|
+
},
|
|
47
|
+
transformOrigin: {
|
|
48
|
+
vertical: "top",
|
|
49
|
+
horizontal: "right"
|
|
50
|
+
},
|
|
51
|
+
open,
|
|
52
|
+
onClose: handleClose,
|
|
53
|
+
children: items.map(({
|
|
54
|
+
onClick,
|
|
55
|
+
text,
|
|
56
|
+
...itemProps
|
|
57
|
+
}, index) => {
|
|
58
|
+
const _onClick = () => {
|
|
59
|
+
onClick();
|
|
60
|
+
handleClose();
|
|
61
|
+
};
|
|
62
|
+
return /* @__PURE__ */ jsxRuntime.jsx(StyledMenuItem, {
|
|
63
|
+
onClick: _onClick,
|
|
64
|
+
...itemProps,
|
|
65
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(Box__default.default, {
|
|
66
|
+
minWidth: 100,
|
|
67
|
+
children: text
|
|
68
|
+
})
|
|
69
|
+
}, index);
|
|
70
|
+
})
|
|
71
|
+
})]
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
Menu.propTypes = {
|
|
75
|
+
items: PropTypes__default.default.array.isRequired
|
|
76
|
+
};
|
|
77
|
+
Menu.defaultProps = {};
|
|
78
|
+
const Root = styled__default.default("div")`
|
|
79
|
+
display: inline-block;
|
|
80
|
+
`;
|
|
81
|
+
const StyledMenuItem = styled__default.default(MuiMenuItem__default.default)`
|
|
82
|
+
font-size: 14px;
|
|
83
|
+
`;
|
|
84
|
+
module.exports = Menu;
|