chore: add tooltip for user info

This commit is contained in:
Aaryan Khandelwal 2023-09-06 12:04:18 +05:30
parent 60c3d1a6e9
commit ac4127c93d

View File

@ -6,7 +6,7 @@ import { useRouter } from "next/router";
import { observer } from "mobx-react-lite"; import { observer } from "mobx-react-lite";
import { useMobxStore } from "lib/mobx/store-provider"; import { useMobxStore } from "lib/mobx/store-provider";
// ui // ui
import { ReactionSelector } from "components/ui"; import { ReactionSelector, Tooltip } from "components/ui";
// helpers // helpers
import { groupReactions, renderEmoji } from "helpers/emoji.helper"; import { groupReactions, renderEmoji } from "helpers/emoji.helper";
@ -77,10 +77,24 @@ export const CommentReactions: React.FC<Props> = observer((props) => {
size="md" size="md"
/> />
{Object.keys(groupedReactions || {}).map( {Object.keys(groupedReactions || {}).map((reaction) => {
(reaction) => const reactions = groupedReactions?.[reaction] ?? [];
groupedReactions?.[reaction]?.length && const REACTIONS_LIMIT = 1000;
groupedReactions[reaction].length > 0 && (
if (reactions.length > 0)
return (
<Tooltip
key={reaction}
tooltipContent={
<div>
{reactions
.map((r) => r.actor_detail.display_name)
.splice(0, REACTIONS_LIMIT)
.join(", ")}
{reactions.length > REACTIONS_LIMIT && " and " + (reactions.length - REACTIONS_LIMIT) + " more"}
</div>
}
>
<button <button
type="button" type="button"
onClick={() => { onClick={() => {
@ -88,7 +102,6 @@ export const CommentReactions: React.FC<Props> = observer((props) => {
handleReactionClick(reaction); handleReactionClick(reaction);
}); });
}} }}
key={reaction}
className={`flex items-center gap-1 text-custom-text-100 text-sm h-full px-2 py-1 rounded-md ${ className={`flex items-center gap-1 text-custom-text-100 text-sm h-full px-2 py-1 rounded-md ${
commentReactions?.some( commentReactions?.some(
(r) => r.actor_detail.id === userStore.currentUser?.id && r.reaction === reaction (r) => r.actor_detail.id === userStore.currentUser?.id && r.reaction === reaction
@ -110,8 +123,9 @@ export const CommentReactions: React.FC<Props> = observer((props) => {
{groupedReactions?.[reaction].length}{" "} {groupedReactions?.[reaction].length}{" "}
</span> </span>
</button> </button>
) </Tooltip>
)} );
})}
</div> </div>
); );
}); });