import React, { useState, FC } from "react"; import { useRouter } from "next/router"; // hooks import useToast from "hooks/use-toast"; import useTheme from "hooks/use-theme"; import useUserAuth from "hooks/use-user-auth"; import useProjects from "hooks/use-projects"; // components import { DeleteProjectModal, SingleSidebarProject } from "components/project"; // icons import { PlusIcon } from "@heroicons/react/24/outline"; // helpers import { copyTextToClipboard } from "helpers/string.helper"; // types import { IProject } from "types"; export const ProjectSidebarList: FC = () => { const [deleteProjectModal, setDeleteProjectModal] = useState(false); const [projectToDelete, setProjectToDelete] = useState(null); // router const router = useRouter(); const { workspaceSlug } = router.query; const { user } = useUserAuth(); const { collapsed: sidebarCollapse } = useTheme(); const { setToastAlert } = useToast(); const { projects: allProjects } = useProjects(); const favoriteProjects = allProjects?.filter((p) => p.is_favorite); const handleDeleteProject = (project: IProject) => { setProjectToDelete(project); setDeleteProjectModal(true); }; const handleCopyText = (projectId: string) => { const originURL = typeof window !== "undefined" && window.location.origin ? window.location.origin : ""; copyTextToClipboard(`${originURL}/${workspaceSlug}/projects/${projectId}/issues`).then(() => { setToastAlert({ type: "success", title: "Link Copied!", message: "Project link copied to clipboard.", }); }); }; return ( <> setDeleteProjectModal(false)} data={projectToDelete} user={user} />
{favoriteProjects && favoriteProjects.length > 0 && (
{!sidebarCollapse && (
Favorites
)} {favoriteProjects.map((project) => ( handleDeleteProject(project)} handleCopyText={() => handleCopyText(project.id)} shortContextMenu /> ))}
)} {allProjects && allProjects.length > 0 && (
{!sidebarCollapse && (
Projects
)} {allProjects.map((project) => ( handleDeleteProject(project)} handleCopyText={() => handleCopyText(project.id)} /> ))}
)} {allProjects && allProjects.length === 0 && ( )}
); };