From cb4d294608a976aec94aba8c0b5486c2dd148200 Mon Sep 17 00:00:00 2001 From: Aaryan Khandelwal <65252264+aaryan610@users.noreply.github.com> Date: Tue, 1 Aug 2023 12:24:34 +0530 Subject: [PATCH] style: sidebar projects design (#1736) * chore: disclosure menu for sidebar projects * fix: projects list spacing * style: new design --- apps/app/components/project/sidebar-list.tsx | 225 +++++++++++++----- .../project/single-sidebar-project.tsx | 46 ++-- .../app/components/workspace/sidebar-menu.tsx | 2 +- apps/app/hooks/use-profile-issues.tsx | 2 - apps/app/hooks/use-user.tsx | 1 - apps/app/types/projects.d.ts | 2 +- 6 files changed, 187 insertions(+), 91 deletions(-) diff --git a/apps/app/components/project/sidebar-list.tsx b/apps/app/components/project/sidebar-list.tsx index 5a35d5625..eab2206b1 100644 --- a/apps/app/components/project/sidebar-list.tsx +++ b/apps/app/components/project/sidebar-list.tsx @@ -5,6 +5,8 @@ import { mutate } from "swr"; // react-beautiful-dnd import { DragDropContext, Draggable, DropResult, Droppable } from "react-beautiful-dnd"; +// headless ui +import { Disclosure } from "@headlessui/react"; // hooks import useToast from "hooks/use-toast"; import useTheme from "hooks/use-theme"; @@ -15,6 +17,7 @@ import { DeleteProjectModal, SingleSidebarProject } from "components/project"; // services import projectService from "services/project.service"; // icons +import { Icon } from "components/ui"; import { PlusIcon } from "@heroicons/react/24/outline"; // helpers import { copyTextToClipboard } from "helpers/string.helper"; @@ -30,7 +33,7 @@ export const ProjectSidebarList: FC = () => { // router const router = useRouter(); - const { workspaceSlug } = router.query; + const { workspaceSlug, projectId } = router.query; const { user } = useUserAuth(); @@ -38,15 +41,18 @@ export const ProjectSidebarList: FC = () => { const { setToastAlert } = useToast(); const { projects: allProjects } = useProjects(); + + const joinedProjects = allProjects?.filter((p) => p.sort_order); const favoriteProjects = allProjects?.filter((p) => p.is_favorite); + const otherProjects = allProjects?.filter((p) => p.sort_order === null); - const orderedAllProjects = allProjects - ? orderArrayBy(allProjects, "sort_order", "ascending") - : []; + const orderedJoinedProjects: IProject[] | undefined = joinedProjects + ? orderArrayBy(joinedProjects, "sort_order", "ascending") + : undefined; - const orderedFavProjects = favoriteProjects + const orderedFavProjects: IProject[] | undefined = favoriteProjects ? orderArrayBy(favoriteProjects, "sort_order", "ascending") - : []; + : undefined; const handleDeleteProject = (project: IProject) => { setProjectToDelete(project); @@ -69,22 +75,25 @@ export const ProjectSidebarList: FC = () => { const { source, destination, draggableId } = result; if (!destination || !workspaceSlug) return; + if (source.index === destination.index) return; - const projectList = - destination.droppableId === "all-projects" ? orderedAllProjects : orderedFavProjects; + const projectsList = + (destination.droppableId === "joined-projects" + ? orderedJoinedProjects + : orderedFavProjects) ?? []; - let updatedSortOrder = projectList[source.index].sort_order; - if (destination.index === 0) { - updatedSortOrder = projectList[0].sort_order - 1000; - } else if (destination.index === projectList.length - 1) { - updatedSortOrder = projectList[projectList.length - 1].sort_order + 1000; - } else { - const destinationSortingOrder = projectList[destination.index].sort_order; + let updatedSortOrder = projectsList[source.index].sort_order; + + if (destination.index === 0) updatedSortOrder = (projectsList[0].sort_order as number) - 1000; + else if (destination.index === projectsList.length - 1) + updatedSortOrder = (projectsList[projectsList.length - 1].sort_order as number) + 1000; + else { + const destinationSortingOrder = projectsList[destination.index].sort_order as number; const relativeDestinationSortingOrder = source.index < destination.index - ? projectList[destination.index + 1].sort_order - : projectList[destination.index - 1].sort_order; + ? (projectsList[destination.index + 1].sort_order as number) + : (projectsList[destination.index - 1].sort_order as number); updatedSortOrder = Math.round( (destinationSortingOrder + relativeDestinationSortingOrder) / 2 @@ -121,76 +130,162 @@ export const ProjectSidebarList: FC = () => { data={projectToDelete} user={user} /> -