2023-10-20 07:03:39 +00:00
|
|
|
import { FC } from "react";
|
|
|
|
// components
|
2023-12-07 12:43:27 +00:00
|
|
|
import { IssueReactionPreview, IssueReactionSelector } from "components/issues";
|
|
|
|
// types
|
|
|
|
import { IUser } from "types";
|
2023-10-20 07:03:39 +00:00
|
|
|
|
|
|
|
interface IIssueReaction {
|
|
|
|
issueReactions: any;
|
2023-12-07 12:43:27 +00:00
|
|
|
user: IUser | null;
|
2023-10-20 07:03:39 +00:00
|
|
|
issueReactionCreate: (reaction: string) => void;
|
|
|
|
issueReactionRemove: (reaction: string) => void;
|
2023-10-20 12:25:20 +00:00
|
|
|
position?: "top" | "bottom";
|
2023-10-20 07:03:39 +00:00
|
|
|
}
|
|
|
|
|
2023-12-07 12:43:27 +00:00
|
|
|
export const IssuePeekOverviewReactions: FC<IIssueReaction> = (props) => {
|
2023-10-20 12:25:20 +00:00
|
|
|
const { issueReactions, user, issueReactionCreate, issueReactionRemove, position = "bottom" } = props;
|
2023-10-20 07:03:39 +00:00
|
|
|
|
|
|
|
const handleReaction = (reaction: string) => {
|
|
|
|
const isReactionAvailable =
|
2023-10-25 13:54:14 +00:00
|
|
|
issueReactions?.[reaction].find((_reaction: any) => _reaction.actor === user?.id) ?? false;
|
2023-10-20 07:03:39 +00:00
|
|
|
|
|
|
|
if (isReactionAvailable) issueReactionRemove(reaction);
|
|
|
|
else issueReactionCreate(reaction);
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2023-12-10 10:18:10 +00:00
|
|
|
<div className="relative flex flex-wrap items-center gap-2">
|
2023-10-20 12:25:20 +00:00
|
|
|
<IssueReactionSelector onSelect={handleReaction} position={position} />
|
2023-10-20 07:03:39 +00:00
|
|
|
<IssueReactionPreview issueReactions={issueReactions} user={user} handleReaction={handleReaction} />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|