mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
df96d40cfa
* 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
34 lines
968 B
TypeScript
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;
|