mirror of
https://github.com/supabase/supabase.git
synced 2026-10-08 10:55:06 +03:00
* Only show RR UI if project is enabled * Only show RR UI if project has read replicas enabled, shift DatabaseSelector state to valtio, add Database Selector to API URl * Update usage of Project interface from types to Project from project-details-query * Fix ts errors * Another one * Another one... * God one more * Fingers crossed * jesus * Add deprecate mark on ProjectBase * Resolve conflicts * Rename ProjectState from valtio to DatabaseSelectorState * Rename file * fix imports * tiny code changes * Fixes --------- Co-authored-by: Alaister Young <a@alaisteryoung.com>
22 lines
749 B
TypeScript
22 lines
749 B
TypeScript
import { useIsLoggedIn, useParams } from 'common'
|
|
import { useProjectDetailQuery } from 'data/projects/project-detail-query'
|
|
import { useProjectsQuery } from 'data/projects/projects-query'
|
|
import { useMemo } from 'react'
|
|
|
|
export function useSelectedProject() {
|
|
const { ref } = useParams()
|
|
const { data } = useProjectDetailQuery({ ref })
|
|
|
|
if (data) return { ...data, parentRef: data?.parent_project_ref ?? data?.ref ?? undefined }
|
|
return data
|
|
}
|
|
|
|
export function useProjectByRef(ref?: string) {
|
|
const isLoggedIn = useIsLoggedIn()
|
|
const { data: projects } = useProjectsQuery({ enabled: isLoggedIn })
|
|
return useMemo(() => {
|
|
if (!ref) return undefined
|
|
return projects?.find((project) => project.ref === ref)
|
|
}, [projects, ref])
|
|
}
|