From a1e249a5bbf7c6f766086aa616779ddebc30c4e6 Mon Sep 17 00:00:00 2001 From: sriram veeraghanta Date: Fri, 1 Sep 2023 14:31:48 +0530 Subject: [PATCH] reaction fixes --- .../peek-overview/comment-detail-card.tsx | 1 - .../peek-overview/issue-emoji-reactions.tsx | 35 ++++++++----------- .../issues/peek-overview/issue-reaction.tsx | 2 -- apps/space/components/tiptap/index.tsx | 1 - apps/space/store/issue_details.ts | 19 +++++----- 5 files changed, 24 insertions(+), 34 deletions(-) diff --git a/apps/space/components/issues/peek-overview/comment-detail-card.tsx b/apps/space/components/issues/peek-overview/comment-detail-card.tsx index f3a9e6834..7dee29aae 100644 --- a/apps/space/components/issues/peek-overview/comment-detail-card.tsx +++ b/apps/space/components/issues/peek-overview/comment-detail-card.tsx @@ -119,7 +119,6 @@ export const CommentCard: React.FC = observer((props) => {
- {comment.comment_html} { // router @@ -22,27 +20,22 @@ export const IssueEmojiReactions: React.FC = observer(() => { const reactions = issueId ? issueDetailsStore.details[issueId]?.reactions || [] : []; const groupedReactions = groupReactions(reactions, "reaction"); + const handleReactionSelectClick = (reactionHex: string) => { + if (!workspace_slug || !project_slug || !issueId) return; + const userReaction = reactions?.find((r) => r.actor_detail.id === user?.id && r.reaction === reactionHex); + if (userReaction) return; + issueDetailsStore.addIssueReaction(workspace_slug.toString(), project_slug.toString(), issueId, { + reaction: reactionHex, + }); + }; + const handleReactionClick = (reactionHex: string) => { if (!workspace_slug || !project_slug || !issueId) return; - - const userReaction = reactions?.find((r) => r.actor_detail.id === user?.id && r.reaction === reactionHex); - - if (userReaction) - issueDetailsStore.removeIssueReaction( - workspace_slug.toString(), - project_slug.toString(), - userReaction.issue, - reactionHex - ); - else - issueDetailsStore.addIssueReaction(workspace_slug.toString(), project_slug.toString(), issueId, { - reaction: reactionHex, - }); + issueDetailsStore.removeIssueReaction(workspace_slug.toString(), project_slug.toString(), issueId, reactionHex); }; useEffect(() => { if (user) return; - userStore.fetchCurrentUser(); }, [user, userStore]); @@ -51,7 +44,7 @@ export const IssueEmojiReactions: React.FC = observer(() => { { userStore.requiredLogin(() => { - handleReactionClick(value); + handleReactionSelectClick(value); }); }} /> @@ -69,7 +62,7 @@ export const IssueEmojiReactions: React.FC = observer(() => { }} key={reaction} className={`flex items-center gap-1 text-custom-text-100 text-sm h-full px-2 py-1 rounded-md border ${ - reactions?.some((r) => r.actor_detail.id === user?.id && r.reaction === reaction) + reactions?.some((r) => r?.actor_detail?.id === user?.id && r.reaction === reaction) ? "bg-custom-primary-100/10 border-custom-primary-100" : "bg-custom-background-80 border-transparent" }`} @@ -77,7 +70,7 @@ export const IssueEmojiReactions: React.FC = observer(() => { {renderEmoji(reaction)} r.actor_detail.id === user?.id && r.reaction === reaction) + reactions?.some((r) => r?.actor_detail?.id === user?.id && r.reaction === reaction) ? "text-custom-primary-100" : "" } diff --git a/apps/space/components/issues/peek-overview/issue-reaction.tsx b/apps/space/components/issues/peek-overview/issue-reaction.tsx index 790b5ccae..643ec7119 100644 --- a/apps/space/components/issues/peek-overview/issue-reaction.tsx +++ b/apps/space/components/issues/peek-overview/issue-reaction.tsx @@ -11,11 +11,9 @@ export const IssueReactions: React.FC = () => {
-
)} - {projectStore?.deploySettings?.reactions && (
diff --git a/apps/space/components/tiptap/index.tsx b/apps/space/components/tiptap/index.tsx index af02dccbc..44dcea516 100644 --- a/apps/space/components/tiptap/index.tsx +++ b/apps/space/components/tiptap/index.tsx @@ -37,7 +37,6 @@ const Tiptap = (props: ITipTapRichTextEditor) => { borderOnFocus, customClassName, } = props; - console.log("tiptap_value", value); const editor = useEditor({ editable: editable ?? true, editorProps: TiptapEditorProps(workspaceSlug, setIsSubmitting), diff --git a/apps/space/store/issue_details.ts b/apps/space/store/issue_details.ts index d36c59a9b..ba9554975 100644 --- a/apps/space/store/issue_details.ts +++ b/apps/space/store/issue_details.ts @@ -33,7 +33,7 @@ export interface IIssueDetailStore { deleteIssueComment: (workspaceId: string, projectId: string, issueId: string, comment_id: string) => void; // issue reactions addIssueReaction: (workspaceId: string, projectId: string, issueId: string, data: any) => void; - removeIssueReaction: (workspaceId: string, projectId: string, issueId: string, data: any) => void; + removeIssueReaction: (workspaceId: string, projectId: string, issueId: string, reactionId: string) => void; // issue votes addIssueVote: (workspaceId: string, projectId: string, issueId: string, data: { vote: 1 | -1 }) => Promise; removeIssueVote: (workspaceId: string, projectId: string, issueId: string) => Promise; @@ -177,14 +177,14 @@ class IssueDetailStore implements IssueDetailStore { addIssueReaction = async (workspaceSlug: string, projectId: string, issueId: string, data: any) => { try { const issueVoteResponse = await this.issueService.createIssueReaction(workspaceSlug, projectId, issueId, data); - const issueDetails = await this.issueService.getIssueById(workspaceSlug, projectId, issueId); if (issueVoteResponse) { runInAction(() => { this.details = { ...this.details, [issueId]: { - ...issueDetails, + ...this.details[issueId], + reactions: [...this.details[issueId].reactions, issueVoteResponse], }, }; }); @@ -194,23 +194,24 @@ class IssueDetailStore implements IssueDetailStore { } }; - removeIssueReaction = async (workspaceSlug: string, projectId: string, issueId: string, data: any) => { + removeIssueReaction = async (workspaceSlug: string, projectId: string, issueId: string, reactionId: string) => { try { - const issueVoteResponse = await this.issueService.deleteIssueReaction(workspaceSlug, projectId, issueId, data); - const issueDetails = await this.issueService.getIssueById(workspaceSlug, projectId, issueId); + await this.issueService.deleteIssueReaction(workspaceSlug, projectId, issueId, reactionId); + const reactions = await this.issueService.getIssueReactions(workspaceSlug, projectId, issueId); - if (issueVoteResponse && issueDetails) { + if (reactions) { runInAction(() => { this.details = { ...this.details, [issueId]: { - ...issueDetails, + ...this.details[issueId], + reactions: reactions, }, }; }); } } catch (error) { - console.log("Failed to add issue vote"); + console.log("Failed to remove issue reaction"); } };