2023-09-01 11:12:30 +00:00
|
|
|
import React from "react";
|
2023-09-06 06:29:57 +00:00
|
|
|
import { observer } from "mobx-react-lite";
|
2023-10-23 09:37:09 +00:00
|
|
|
import { MoveRight } from "lucide-react";
|
2024-03-19 14:38:35 +00:00
|
|
|
import { Listbox, Transition } from "@headlessui/react";
|
2023-09-01 11:12:30 +00:00
|
|
|
// ui
|
2024-05-22 10:09:28 +00:00
|
|
|
import { setToast, TOAST_TYPE } from "@plane/ui";
|
2024-03-19 14:38:35 +00:00
|
|
|
import { Icon } from "@/components/ui";
|
2023-09-01 11:12:30 +00:00
|
|
|
// helpers
|
2024-03-19 14:38:35 +00:00
|
|
|
import { copyTextToClipboard } from "@/helpers/string.helper";
|
2024-05-14 08:56:54 +00:00
|
|
|
// hooks
|
|
|
|
import { useIssueDetails } from "@/hooks/store";
|
2024-05-22 07:09:34 +00:00
|
|
|
import useClipboardWritePermission from "@/hooks/use-clipboard-write-permission";
|
2023-09-01 11:12:30 +00:00
|
|
|
// types
|
2024-05-22 10:09:28 +00:00
|
|
|
import { IIssue, IPeekMode } from "@/types/issue";
|
2023-09-01 11:12:30 +00:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
handleClose: () => void;
|
|
|
|
issueDetails: IIssue | undefined;
|
|
|
|
};
|
|
|
|
|
|
|
|
const peekModes: {
|
|
|
|
key: IPeekMode;
|
|
|
|
icon: string;
|
|
|
|
label: string;
|
|
|
|
}[] = [
|
|
|
|
{ key: "side", icon: "side_navigation", label: "Side Peek" },
|
|
|
|
{
|
|
|
|
key: "modal",
|
|
|
|
icon: "dialogs",
|
|
|
|
label: "Modal Peek",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: "full",
|
|
|
|
icon: "nearby",
|
|
|
|
label: "Full Screen Peek",
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2023-09-06 06:29:57 +00:00
|
|
|
export const PeekOverviewHeader: React.FC<Props> = observer((props) => {
|
2023-10-23 09:37:09 +00:00
|
|
|
const { handleClose } = props;
|
2023-09-01 11:12:30 +00:00
|
|
|
|
2024-05-14 08:56:54 +00:00
|
|
|
const { peekMode, setPeekMode } = useIssueDetails();
|
2024-05-22 07:09:34 +00:00
|
|
|
const isClipboardWriteAllowed = useClipboardWritePermission();
|
2023-09-01 11:12:30 +00:00
|
|
|
|
|
|
|
const handleCopyLink = () => {
|
2023-09-04 09:17:28 +00:00
|
|
|
const urlToCopy = window.location.href;
|
2023-09-01 11:12:30 +00:00
|
|
|
|
2023-09-04 09:17:28 +00:00
|
|
|
copyTextToClipboard(urlToCopy).then(() => {
|
2024-05-22 10:09:28 +00:00
|
|
|
setToast({
|
|
|
|
type: TOAST_TYPE.INFO,
|
2023-09-01 11:12:30 +00:00
|
|
|
title: "Link copied!",
|
|
|
|
message: "Issue link copied to clipboard",
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2023-12-10 10:18:10 +00:00
|
|
|
<div className="flex items-center justify-between">
|
2023-09-01 11:12:30 +00:00
|
|
|
<div className="flex items-center gap-4">
|
2024-05-14 08:56:54 +00:00
|
|
|
{peekMode === "side" && (
|
2023-09-01 15:08:53 +00:00
|
|
|
<button type="button" onClick={handleClose}>
|
2024-05-21 10:59:30 +00:00
|
|
|
<MoveRight className="h-4 w-4" strokeWidth={2} />
|
2023-09-01 11:12:30 +00:00
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
<Listbox
|
|
|
|
as="div"
|
2024-05-14 08:56:54 +00:00
|
|
|
value={peekMode}
|
|
|
|
onChange={(val) => setPeekMode(val)}
|
2023-09-01 11:12:30 +00:00
|
|
|
className="relative flex-shrink-0 text-left"
|
|
|
|
>
|
2024-05-14 08:56:54 +00:00
|
|
|
<Listbox.Button className={`grid place-items-center ${peekMode === "full" ? "rotate-45" : ""}`}>
|
2024-05-21 10:59:30 +00:00
|
|
|
<Icon iconName={peekModes.find((m) => m.key === peekMode)?.icon ?? ""} className="text-[1rem]" />
|
2023-09-01 11:12:30 +00:00
|
|
|
</Listbox.Button>
|
|
|
|
|
|
|
|
<Transition
|
|
|
|
as={React.Fragment}
|
|
|
|
enter="transition ease-out duration-100"
|
|
|
|
enterFrom="transform opacity-0 scale-95"
|
|
|
|
enterTo="transform opacity-100 scale-100"
|
|
|
|
leave="transition ease-in duration-75"
|
|
|
|
leaveFrom="transform opacity-100 scale-100"
|
|
|
|
leaveTo="transform opacity-0 scale-95"
|
|
|
|
>
|
2023-12-10 10:18:10 +00:00
|
|
|
<Listbox.Options className="absolute left-0 z-10 mt-1 min-w-[8rem] origin-top-left overflow-y-auto whitespace-nowrap rounded-md border border-custom-border-300 bg-custom-background-90 text-xs shadow-lg focus:outline-none">
|
2023-09-01 11:12:30 +00:00
|
|
|
<div className="space-y-1 p-2">
|
|
|
|
{peekModes.map((mode) => (
|
|
|
|
<Listbox.Option
|
|
|
|
key={mode.key}
|
|
|
|
value={mode.key}
|
|
|
|
className={({ active, selected }) =>
|
|
|
|
`cursor-pointer select-none truncate rounded px-1 py-1.5 ${
|
|
|
|
active || selected ? "bg-custom-background-80" : ""
|
|
|
|
} ${selected ? "text-custom-text-100" : "text-custom-text-200"}`
|
|
|
|
}
|
|
|
|
>
|
|
|
|
{({ selected }) => (
|
|
|
|
<div className="flex items-center justify-between gap-2">
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
<div className="flex items-center gap-1.5">
|
|
|
|
<Icon
|
|
|
|
iconName={mode.icon}
|
2023-12-10 10:18:10 +00:00
|
|
|
className={`-my-1 flex-shrink-0 !text-base ${mode.key === "full" ? "rotate-45" : ""}`}
|
2023-09-01 11:12:30 +00:00
|
|
|
/>
|
|
|
|
{mode.label}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{selected && <Icon iconName="done" />}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</Listbox.Option>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
</Listbox.Options>
|
|
|
|
</Transition>
|
|
|
|
</Listbox>
|
|
|
|
</div>
|
2024-05-22 07:09:34 +00:00
|
|
|
{isClipboardWriteAllowed && (peekMode === "side" || peekMode === "modal") && (
|
2023-12-10 10:18:10 +00:00
|
|
|
<div className="flex flex-shrink-0 items-center gap-2">
|
2023-09-01 15:08:53 +00:00
|
|
|
<button type="button" onClick={handleCopyLink} className="-rotate-45 focus:outline-none" tabIndex={1}>
|
2024-05-21 10:59:30 +00:00
|
|
|
<Icon iconName="link" className="text-[1rem]" />
|
2023-09-01 11:12:30 +00:00
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
);
|
2023-09-06 06:29:57 +00:00
|
|
|
});
|