plane/web/components/issues/peek-overview/activity/comment-reaction.tsx
Aaryan Khandelwal 539c7a3455 refactor: issue peek overview (#3001)
* refactor: peek overview components

* fix: issue reactions

* chore: update comment types

* fix: access sepcifier value

* chore: remove unused vars

* fix: build errors

* build-error: build error resolved

---------

Co-authored-by: sriram veeraghanta <veeraghanta.sriram@gmail.com>
Co-authored-by: gurusainath <gurusainath007@gmail.com>
2023-12-07 19:59:35 +05:30

62 lines
2.0 KiB
TypeScript

import { FC } from "react";
import useSWR from "swr";
import { observer } from "mobx-react-lite";
// components
import { IssuePeekOverviewReactions } from "components/issues";
// hooks
import { useMobxStore } from "lib/mobx/store-provider";
// types
import { RootStore } from "store/root";
interface IIssueCommentReaction {
workspaceSlug: string;
projectId: string;
issueId: string;
user: any;
comment: any;
issueCommentReactionCreate: (commentId: string, reaction: string) => void;
issueCommentReactionRemove: (commentId: string, reaction: string) => void;
}
export const IssueCommentReaction: FC<IIssueCommentReaction> = observer((props) => {
const { workspaceSlug, projectId, issueId, user, comment, issueCommentReactionCreate, issueCommentReactionRemove } =
props;
const { issueDetail: issueDetailStore }: RootStore = useMobxStore();
const handleCommentReactionCreate = (reaction: string) => {
if (issueCommentReactionCreate && comment?.id) issueCommentReactionCreate(comment?.id, reaction);
};
const handleCommentReactionRemove = (reaction: string) => {
if (issueCommentReactionRemove && comment?.id) issueCommentReactionRemove(comment?.id, reaction);
};
useSWR(
workspaceSlug && projectId && issueId && comment && comment?.id
? `ISSUE+PEEK_OVERVIEW_COMMENT_${comment?.id}`
: null,
() => {
if (workspaceSlug && projectId && issueId && comment && comment.id) {
issueDetailStore.fetchIssueCommentReactions(workspaceSlug, projectId, issueId, comment?.id);
}
}
);
let issueReactions = issueDetailStore?.getIssueCommentReactions || null;
issueReactions = issueReactions && comment.id ? issueReactions?.[comment.id] : [];
return (
<div>
<IssuePeekOverviewReactions
issueReactions={issueReactions}
user={user}
issueReactionCreate={handleCommentReactionCreate}
issueReactionRemove={handleCommentReactionRemove}
position="top"
/>
</div>
);
});