mirror of
https://github.com/supabase/supabase.git
synced 2026-10-08 19:05:06 +03:00
* Show correct number of private snippets for SQL folders * Ensure that private snippet count is updated when sharing / unsharing queries * Fix snippets caching issuie * Fix move query modal showing more than just the project's folders
42 lines
1.3 KiB
TypeScript
42 lines
1.3 KiB
TypeScript
import { useQuery, UseQueryOptions } from '@tanstack/react-query'
|
|
|
|
import { get, handleError } from 'data/fetchers'
|
|
import { ResponseError } from 'types'
|
|
import { contentKeys } from './keys'
|
|
|
|
interface getContentCountVariables {
|
|
projectRef?: string
|
|
type: 'sql' | 'report' | 'log_sql'
|
|
}
|
|
|
|
export async function getContentCount(
|
|
{ projectRef, type }: getContentCountVariables,
|
|
signal?: AbortSignal
|
|
) {
|
|
if (typeof projectRef === 'undefined') throw new Error('projectRef is required')
|
|
|
|
const { data, error } = await get('/platform/projects/{ref}/content/count', {
|
|
params: { path: { ref: projectRef }, query: { type } },
|
|
signal,
|
|
})
|
|
|
|
if (error) throw handleError(error)
|
|
return data
|
|
}
|
|
|
|
export type ContentIdData = Awaited<ReturnType<typeof getContentCount>>
|
|
export type ContentIdError = ResponseError
|
|
|
|
export const useContentCountQuery = <TData = ContentIdData>(
|
|
{ projectRef, type }: getContentCountVariables,
|
|
{ enabled = true, ...options }: UseQueryOptions<ContentIdData, ContentIdError, TData> = {}
|
|
) =>
|
|
useQuery<ContentIdData, ContentIdError, TData>(
|
|
contentKeys.count(projectRef, type),
|
|
({ signal }) => getContentCount({ projectRef, type }, signal),
|
|
{
|
|
enabled: enabled && typeof projectRef !== 'undefined',
|
|
...options,
|
|
}
|
|
)
|