plane/apps/app/hooks/use-projects.tsx
Aaryan Khandelwal df96d40cfa
fix: views issues mutation, sidebar link highlight (#1025)
* fix: views issues mutation, sidebar link highlight

* fix: show only specific states when type filter is set

* fix: delete comment mutation

* style: bulk delete issues modal

* fix: project settings features mutation
2023-05-11 02:15:39 +05:30

34 lines
968 B
TypeScript

import { useRouter } from "next/router";
import useSWR from "swr";
// services
import projectService from "services/project.service";
// helpers
import { orderArrayBy } from "helpers/array.helper";
// fetch-keys
import { PROJECTS_LIST } from "constants/fetch-keys";
const useProjects = () => {
// router
const router = useRouter();
const { workspaceSlug } = router.query;
// api fetching
const { data: projects, mutate: mutateProjects } = useSWR(
workspaceSlug ? PROJECTS_LIST(workspaceSlug as string) : null,
workspaceSlug ? () => projectService.getProjects(workspaceSlug as string) : null
);
const recentProjects = projects
?.sort((a, b) => Date.parse(`${a.updated_at}`) - Date.parse(`${b.updated_at}`))
.filter((_item, index) => index < 3);
return {
projects: orderArrayBy(projects ?? [], "is_favorite", "descending") || [],
recentProjects: recentProjects || [],
mutateProjects,
};
};
export default useProjects;