diff --git a/src/AccountProfileOverlay.jsx b/src/AccountProfileOverlay.jsx index a0668831..21d6f7b8 100644 --- a/src/AccountProfileOverlay.jsx +++ b/src/AccountProfileOverlay.jsx @@ -37,7 +37,8 @@ const Card = styled.div` const FollowButtonWrapper = styled.div` width: 100%; - div, button { + div, + button { width: 100%; } `; @@ -61,6 +62,7 @@ const overlay = ( src="${REPL_ACCOUNT}/widget/FlagButton" props={{ item: contentModerationItem, + disabled: !context.accountId || context.accountId === accountId, onFlag: () => { State.update({ hasBeenFlagged: true }); }, @@ -110,12 +112,13 @@ return ( props={{ type: "info", title: "Flagged for moderation", - description: "Thanks for helping our Content Moderators. The item you flagged will be reviewed.", + description: + "Thanks for helping our Content Moderators. The item you flagged will be reviewed.", open: state.hasBeenFlagged, onOpenChange: (open) => { State.update({ hasBeenFlagged: open }); }, - duration: 10000 + duration: 10000, }} /> )} diff --git a/src/Comments/Comment.jsx b/src/Comments/Comment.jsx index afbc6933..64addbfe 100644 --- a/src/Comments/Comment.jsx +++ b/src/Comments/Comment.jsx @@ -193,7 +193,7 @@ return ( {blockHeight !== "now" && ( { State.update({ hasBeenFlagged: true }); }, diff --git a/src/Feed/Post.jsx b/src/Feed/Post.jsx index fd5492d7..1d5d2f71 100644 --- a/src/Feed/Post.jsx +++ b/src/Feed/Post.jsx @@ -39,7 +39,7 @@ return ( {blockHeight !== "now" && (
( + +); + +if (disabled) { + return ( + + ); +} + return ( Flag for moderation} > - + ); diff --git a/src/NestedDiscussions/Compose.jsx b/src/NestedDiscussions/Compose.jsx index 9067eccc..d275e0b8 100644 --- a/src/NestedDiscussions/Compose.jsx +++ b/src/NestedDiscussions/Compose.jsx @@ -349,7 +349,7 @@ return ( {state.showPreview ? ( { State.update({ hasBeenFlagged: true }); }, diff --git a/src/Posts/Compose.jsx b/src/Posts/Compose.jsx index 112bd545..16d738b9 100644 --- a/src/Posts/Compose.jsx +++ b/src/Posts/Compose.jsx @@ -325,7 +325,7 @@ return ( {state.showPreview ? ( { State.update({ hasBeenFlagged: true }); }, diff --git a/src/v1/LikeButton.jsx b/src/v1/LikeButton.jsx new file mode 100644 index 00000000..be07a68a --- /dev/null +++ b/src/v1/LikeButton.jsx @@ -0,0 +1,108 @@ +const item = props.item; + +if (!item) { + return ""; +} + +const likes = Social.index("like", item); + +const dataLoading = likes === null; + +const likesByUsers = {}; + +(likes || []).forEach((like) => { + if (like.value.type === "like") { + likesByUsers[like.accountId] = like; + } else if (like.value.type === "unlike") { + delete likesByUsers[like.accountId]; + } +}); +if (state.hasLike === true) { + likesByUsers[context.accountId] = { + accountId: context.accountId, + }; +} else if (state.hasLike === false) { + delete likesByUsers[context.accountId]; +} + +const accountsWithLikes = Object.keys(likesByUsers); +const hasLike = context.accountId && !!likesByUsers[context.accountId]; +const totalLikes = accountsWithLikes.length; + +const LikeButton = styled.button` + border: 0 !important; + display: inline-flex; + align-items: center; + justify-content: center; + border-radius: 50%; + width: 2.5em; + height: 2.5em; + &:hover { + color: red; + background: pink; + } + .bi-heart-fill { + color: red; + } +`; + +const likeClick = () => { + if (state.loading) { + return; + } + State.update({ + loading: true, + }); + const data = { + index: { + like: JSON.stringify({ + key: item, + value: { + type: hasLike ? "unlike" : "like", + }, + }), + }, + }; + + if (!hasLike && props.notifyAccountId) { + data.index.notify = JSON.stringify({ + key: props.notifyAccountId, + value: { + type: "like", + item, + }, + }); + } + Social.set(data, { + onCommit: () => State.update({ loading: false, hasLike: !hasLike }), + onCancel: () => State.update({ loading: false }), + }); +}; + +const title = hasLike ? "Unlike" : "Like"; + +return ( +
+ + {state.loading || dataLoading ? ( + + {totalLikes == 0 ? ( + "0" + ) : ( + + )} +
+); diff --git a/src/v1/Posts/Post.jsx b/src/v1/Posts/Post.jsx index b355869a..c7f69a99 100644 --- a/src/v1/Posts/Post.jsx +++ b/src/v1/Posts/Post.jsx @@ -178,7 +178,7 @@ return ( {blockHeight !== "now" && ( { State.update({ hasBeenFlagged: true }); },