mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 09:55:06 +03:00
* chore: paginate user content * progress * loading states * add load more buttons to private snippets * working pagination * fix some types * always show snippet counts * support new api parameters * favorite snippets * progress * searching * paginate root folder * fix renaming snippets * fix ts * removed unused prop * Shift sharing/unsharing query logic outside of valtio to leverage on RQ only * Fix invalidation on an unsaved snippet * Clean up * Fix * Clean up * Update API type * Update API * fix duplicate snippets error after moving a snippet * add currently selected snippet * Fix unsharing a snippet that has yet to be opened * i'm dumb * fix sharing a snippet * fix sharing and unsharing * show favorite or shared snippet in list even if it's in another page * Fix wrong import for debounce * Fix false positive toast error when creating custom report * Update API type * Change create new snippet CTA to link back to /new with skip flag * Fix saving logs explorer query * Bump page number --------- Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
48 lines
1.6 KiB
TypeScript
48 lines
1.6 KiB
TypeScript
import { useQuery, UseQueryOptions } from '@tanstack/react-query'
|
|
|
|
import { components } from 'api-types'
|
|
import { get, handleError } from 'data/fetchers'
|
|
import type { ResponseError } from 'types'
|
|
import type { Content } from './content-query'
|
|
import { contentKeys } from './keys'
|
|
|
|
export type GetUserContentByIdResponse = Omit<
|
|
components['schemas']['GetUserContentByIdResponse'],
|
|
'content'
|
|
> & {
|
|
content: Content['content']
|
|
}
|
|
|
|
export async function getContentById(
|
|
{ projectRef, id }: { projectRef?: string; id?: string },
|
|
signal?: AbortSignal
|
|
) {
|
|
if (typeof projectRef === 'undefined') throw new Error('projectRef is required')
|
|
if (typeof id === 'undefined') throw new Error('Content ID is required')
|
|
|
|
const { data, error } = await get('/platform/projects/{ref}/content/item/{id}', {
|
|
params: { path: { ref: projectRef, id } },
|
|
signal,
|
|
})
|
|
|
|
if (error) throw handleError(error)
|
|
// override content type
|
|
return data as unknown as GetUserContentByIdResponse
|
|
}
|
|
|
|
export type ContentIdData = Awaited<ReturnType<typeof getContentById>>
|
|
export type ContentIdError = ResponseError
|
|
|
|
export const useContentIdQuery = <TData = ContentIdData>(
|
|
{ projectRef, id }: { projectRef?: string; id?: string },
|
|
{ enabled = true, ...options }: UseQueryOptions<ContentIdData, ContentIdError, TData> = {}
|
|
) =>
|
|
useQuery<ContentIdData, ContentIdError, TData>(
|
|
contentKeys.resource(projectRef, id),
|
|
({ signal }) => getContentById({ projectRef, id }, signal),
|
|
{
|
|
enabled: enabled && typeof projectRef !== 'undefined' && typeof id !== 'undefined',
|
|
...options,
|
|
}
|
|
)
|