"use client"; import { FC, useRef, useState } from "react"; import { observer } from "mobx-react-lite"; import { useParams } from "next/navigation"; // types import { IProjectView, TLogoProps } from "@plane/types"; // ui import { EmojiIconPicker, EmojiIconPickerTypes, PhotoFilterIcon, TOAST_TYPE, setToast } from "@plane/ui"; // components import { Logo } from "@/components/common"; import { ListItem } from "@/components/core/list"; import { ViewListItemAction } from "@/components/views"; // helpers import { convertHexEmojiToDecimal } from "@/helpers/emoji.helper"; // hooks import { useProjectView } from "@/hooks/store"; import { usePlatformOS } from "@/hooks/use-platform-os"; type Props = { view: IProjectView; }; export const ProjectViewListItem: FC = observer((props) => { const { view } = props; // refs const parentRef = useRef(null); // state const [isOpen, setIsOpen] = useState(false); // router const { workspaceSlug, projectId } = useParams(); // store hooks const { isMobile } = usePlatformOS(); const { updateView } = useProjectView(); const handleViewLogoUpdate = async (data: TLogoProps) => { if (!workspaceSlug || !projectId || !view.id || !data) return; updateView(workspaceSlug.toString(), projectId.toString(), view.id.toString(), { logo_props: data, }) .then(() => { setToast({ type: TOAST_TYPE.SUCCESS, title: "Success!", message: "Logo Updated successfully.", }); }) .catch(() => { setToast({ type: TOAST_TYPE.ERROR, title: "Error!", message: "Something went wrong. Please try again.", }); }); }; return ( setIsOpen(val)} className="flex items-center justify-center" buttonClassName="flex items-center justify-center" label={ <> {view?.logo_props?.in_use ? ( ) : ( )} } onChange={(val) => { let logoValue = {}; if (val?.type === "emoji") logoValue = { value: convertHexEmojiToDecimal(val.value.unified), url: val.value.imageUrl, }; else if (val?.type === "icon") logoValue = val.value; handleViewLogoUpdate({ in_use: val?.type, [val?.type]: logoValue, }).finally(() => setIsOpen(false)); }} defaultIconColor={ view?.logo_props?.in_use && view?.logo_props.in_use === "icon" ? view?.logo_props?.icon?.color : undefined } defaultOpen={ view?.logo_props?.in_use && view?.logo_props?.in_use === "emoji" ? EmojiIconPickerTypes.EMOJI : EmojiIconPickerTypes.ICON } /> } title={view.name} itemLink={`/${workspaceSlug}/projects/${projectId}/views/${view.id}`} actionableItems={} isMobile={isMobile} parentRef={parentRef} disableLink={isOpen} /> ); });