From f518333ca27755e5f47117ba130e02c89caecad7 Mon Sep 17 00:00:00 2001 From: kamtschatka Date: Wed, 11 Sep 2024 23:49:17 +0200 Subject: [PATCH] long delay when selecting tags in UI #382 improved performance by not handling hover in css also rendering the draggable div only if draggable mode is active --- .../web/components/dashboard/tags/TagPill.tsx | 61 ++++++++++++------- 1 file changed, 40 insertions(+), 21 deletions(-) diff --git a/apps/web/components/dashboard/tags/TagPill.tsx b/apps/web/components/dashboard/tags/TagPill.tsx index 88b88b52..5a0f9943 100644 --- a/apps/web/components/dashboard/tags/TagPill.tsx +++ b/apps/web/components/dashboard/tags/TagPill.tsx @@ -1,4 +1,4 @@ -import React from "react"; +import React, { useState } from "react"; import Link from "next/link"; import { Button } from "@/components/ui/button"; import { Separator } from "@/components/ui/separator"; @@ -22,6 +22,11 @@ export function TagPill({ count: number; isDraggable: boolean; }) { + const [isHovered, setIsHovered] = useState(false); + + const handleMouseOver = () => setIsHovered(true); + const handleMouseOut = () => setIsHovered(false); + const { mutate: mergeTag } = useMergeTag({ onSuccess: () => { toast({ @@ -62,27 +67,25 @@ export function TagPill({ }, ); - return ( - -
- - {name} {count} - + + {name} {count} + + {isHovered && ( -
+ )} + + ); + if (!isDraggable) { + return pill; + } + return ( + + {pill} ); }