From de213d2fa94f39c3147cddcd1df3d2a9c7b994bd Mon Sep 17 00:00:00 2001 From: Nya Candy Date: Wed, 26 Apr 2023 22:01:39 +0800 Subject: [PATCH] feat/revert like (#429) --- package.json | 2 +- public/locales/ja/common.json | 5 ++++ public/locales/zh-TW/common.json | 5 ++++ public/locales/zh/common.json | 5 ++++ src/components/common/Reactions.tsx | 44 +++++++++++++++++++++++++++-- src/middleware.ts | 10 ++++--- 6 files changed, 64 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index b1bd4de8..e931c44d 100644 --- a/package.json +++ b/package.json @@ -205,4 +205,4 @@ "minimumChangeThreshold": 0, "showDetails": true } -} \ No newline at end of file +} diff --git a/public/locales/ja/common.json b/public/locales/ja/common.json index 9120a73f..2dd0cc98 100644 --- a/public/locales/ja/common.json +++ b/public/locales/ja/common.json @@ -38,6 +38,11 @@ "Got it, thanks!": "了解しました、ありがとうございます!", "Like List": "いいねリスト", "Mint List": "ミントリスト", + "Revert": "退会済み", + "Confirm to revert": "退会確認", + "like revert": "このライクアクションを撤回したい場合は、チェックしてください。", + "Cancel": "キャンセル", + "Confirm": "確認", "No Content Yet.": "まだ何もありません。", "Close": "閉じる", "Dashboard": "ダッシュボード", diff --git a/public/locales/zh-TW/common.json b/public/locales/zh-TW/common.json index ab3f344c..32a10dc5 100644 --- a/public/locales/zh-TW/common.json +++ b/public/locales/zh-TW/common.json @@ -44,6 +44,11 @@ "Got it, thanks!": "知道啦,感恩的心~", "Like List": "按讚列表", "Mint List": "珍藏列表", + "Revert": "撤銷", + "Confirm to revert": "確認撤銷", + "like revert": "請確認您是否想要撤銷這個點贊操作?", + "Cancel": "取消", + "Confirm": "確認", "No Content Yet.": "什麼都沒", "Close": "關閉", "Dashboard": "主控臺", diff --git a/public/locales/zh/common.json b/public/locales/zh/common.json index 043393c9..2918aace 100644 --- a/public/locales/zh/common.json +++ b/public/locales/zh/common.json @@ -44,6 +44,11 @@ "Got it, thanks!": "好的,谢谢!", "Like List": "点赞列表", "Mint List": "珍藏列表", + "Revert": "撤销", + "Confirm to revert": "确认撤销", + "like revert": "请确认您是否想要撤销这个点赞操作?", + "Cancel": "取消", + "Confirm": "确认", "No Content Yet.": "暂无内容", "Close": "关闭", "Dashboard": "仪表盘", diff --git a/src/components/common/Reactions.tsx b/src/components/common/Reactions.tsx index 1dd8a705..9a7d955b 100644 --- a/src/components/common/Reactions.tsx +++ b/src/components/common/Reactions.tsx @@ -51,6 +51,8 @@ export const Reactions: React.FC<{ }) const { data: likeCount = 0 } = useGetLikeCounts({ pageId }) + const [isUnlikeOpen, setIsUnlikeOpen] = useState(false) + const like = () => { if (pageId) { if (likeStatus.isLiked) { @@ -61,9 +63,18 @@ export const Reactions: React.FC<{ } } + const unlike = () => { + if (pageId) { + setIsUnlikeOpen(false) + if (likeStatus.isLiked) { + toggleLikePage.mutate({ ...parsePageId(pageId), action: "unlink" }) + } // else do nothing + } + } + useEffect(() => { if (toggleLikePage.isSuccess) { - if (likeRef.current?.getBoundingClientRect()) { + if (likeRef.current?.getBoundingClientRect() && likeStatus.isLiked) { confetti({ particleCount: 150, spread: 70, @@ -347,10 +358,39 @@ export const Reactions: React.FC<{ -
+
+ +
+ + +
+ + Do you really want to revert this like action? + +
+
+ +