mirror of
https://github.com/supabase/supabase.git
synced 2026-06-12 17:27:58 +08:00
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com>
31 lines
811 B
TypeScript
31 lines
811 B
TypeScript
import { useMemo } from 'react'
|
|
|
|
import { useOrganizationsQuery } from '@/data/organizations/organizations-query'
|
|
import { useProjectsInfiniteQuery } from '@/data/projects/projects-infinite-query'
|
|
|
|
interface UseOrgAndProjectDataOptions {
|
|
enabled?: boolean
|
|
}
|
|
|
|
export const useOrgAndProjectData = (options: UseOrgAndProjectDataOptions = {}) => {
|
|
const { enabled = true } = options
|
|
|
|
const { data: organizations = [], isLoading: isLoadingOrgs } = useOrganizationsQuery({ enabled })
|
|
|
|
const { data: projectsData, isLoading: isLoadingProjects } = useProjectsInfiniteQuery({
|
|
limit: 100,
|
|
})
|
|
|
|
const projects = useMemo(
|
|
() => projectsData?.pages.flatMap((page) => page.projects) ?? [],
|
|
[projectsData]
|
|
)
|
|
|
|
return {
|
|
organizations,
|
|
projects,
|
|
isLoadingOrgs,
|
|
isLoadingProjects,
|
|
}
|
|
}
|