bb-plane-fork/web/core/components/stickies/action-bar.tsx
Akshita Goyal cb045abfe1
[WEB-3048] feat: added-stickies (#6339)
* feat: added-stickies

* fix: recents empty state fixed

* fix: added border

* Change sort_order field

* fix: remvoved btn

* fix: sticky toolbar

* fix: build

* fix: sticky search

* fix: minor css fix

* fix: issue identifier css handled

* fix: issue type default icon

* fix: added tooltip for color palette and delete

---------

Co-authored-by: sangeethailango <sangeethailango21@gmail.com>
2025-01-07 20:30:42 +05:30

129 lines
5.1 KiB
TypeScript

import { useRef, useState } from "react";
import { observer } from "mobx-react";
import { useParams } from "next/navigation";
import useSWR from "swr";
import { Plus, StickyNote as StickyIcon, X } from "lucide-react";
import { useOutsideClickDetector } from "@plane/hooks";
import { RecentStickyIcon, StickyNoteIcon, Tooltip } from "@plane/ui";
import { cn } from "@plane/utils";
import { useCommandPalette } from "@/hooks/store";
import { useSticky } from "@/hooks/use-stickies";
import { AllStickiesModal } from "./modal";
import { StickyNote } from "./sticky";
export const StickyActionBar = observer(() => {
const { workspaceSlug } = useParams();
const [isExpanded, setIsExpanded] = useState(false);
const [newSticky, setNewSticky] = useState(false);
const [showRecentSticky, setShowRecentSticky] = useState(false);
const ref = useRef(null);
// hooks
const { stickies, activeStickyId, recentStickyId, updateActiveStickyId, fetchRecentSticky, toggleShowNewSticky } =
useSticky();
const { toggleAllStickiesModal, allStickiesModal } = useCommandPalette();
useSWR(
workspaceSlug ? `WORKSPACE_STICKIES_RECENT_${workspaceSlug}` : null,
workspaceSlug ? () => fetchRecentSticky(workspaceSlug.toString()) : null
);
useOutsideClickDetector(ref, () => {
setNewSticky(false);
setShowRecentSticky(false);
setIsExpanded(false);
});
return (
<div
ref={ref}
className="sticky-action-bar__item flex flex-col bg-custom-background-90 rounded-full p-[2px] border-2 border-custom-primary-100/10 overflow-hidden"
>
<div
className={`flex flex-col gap-2 transition-all duration-300 ease-in-out origin-bottom ${isExpanded ? "scale-y-100 opacity-100 mb-2 " : "scale-y-0 opacity-0 h-0"}`}
>
<Tooltip tooltipContent="All stickies" isMobile={false} position="left">
<button
className="btn btn--icon rounded-full w-10 h-10 flex items-center justify-center shadow-sm bg-custom-background-100"
onClick={() => toggleAllStickiesModal(true)}
>
<RecentStickyIcon className="size-5 rotate-90 text-custom-text-350" />
</button>
</Tooltip>
{recentStickyId && (
<Tooltip
className="scale-75 -mr-30 translate-x-10"
tooltipContent={
<div className="-m-2 max-h-[150px]">
<StickyNote
className={"w-[290px]"}
workspaceSlug={workspaceSlug.toString()}
stickyId={newSticky ? activeStickyId : recentStickyId || ""}
/>
<div
className="absolute top-0 right-0 h-full w-full"
style={{
background: `linear-gradient(to top, ${stickies[recentStickyId]?.color}, transparent)`,
}}
/>
</div>
}
isMobile={false}
position="left"
disabled={showRecentSticky}
>
<button
className="btn btn--icon rounded-full w-10 h-10 flex items-center justify-center shadow-sm bg-custom-background-100"
onClick={() => setShowRecentSticky(true)}
style={{ color: stickies[recentStickyId]?.color }}
>
<StickyNoteIcon className={cn("size-5 rotate-90")} color={stickies[recentStickyId]?.color} />
</button>
</Tooltip>
)}
<Tooltip tooltipContent="Add sticky" isMobile={false} position="left">
<button
className="btn btn--icon rounded-full w-10 h-10 flex items-center justify-center shadow-sm bg-custom-background-100"
onClick={() => {
updateActiveStickyId("");
toggleShowNewSticky(true);
setNewSticky(true);
}}
>
<Plus className="size-5 rotate-90 text-custom-text-350" />
</button>
</Tooltip>
</div>
<button
className={`btn btn--icon rounded-full w-10 h-10 flex items-center justify-center shadow-sm bg-custom-background-100 transition-transform duration-300 ${isExpanded ? "rotate-180" : ""}`}
onClick={() => setIsExpanded(!isExpanded)}
>
{isExpanded ? (
<X className="size-5 text-custom-text-350" />
) : (
<StickyIcon className="size-5 rotate-90 text-custom-text-350" />
)}
</button>
<div
className={cn(
"absolute bottom-16 right-0 z-[20]",
"transform transition-all duration-300 ease-in-out",
newSticky || showRecentSticky ? "translate-y-[0%] min-h-[300px]" : "translate-y-[100%] h-0"
)}
>
{(newSticky || (showRecentSticky && recentStickyId)) && (
<StickyNote
className={"w-[290px]"}
onClose={() => (newSticky ? setNewSticky(false) : setShowRecentSticky(false))}
workspaceSlug={workspaceSlug.toString()}
stickyId={newSticky ? activeStickyId : recentStickyId || ""}
/>
)}
</div>
<AllStickiesModal isOpen={allStickiesModal} handleClose={() => toggleAllStickiesModal(false)} />
</div>
);
});