mirror of
https://github.com/supabase/supabase.git
synced 2026-10-09 19:35: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>
65 lines
1.7 KiB
TypeScript
65 lines
1.7 KiB
TypeScript
import { useQuery, UseQueryOptions } from '@tanstack/react-query'
|
|
|
|
import { components } from 'api-types'
|
|
import { get } from 'data/fetchers'
|
|
import type { Dashboards, LogSqlSnippets, SqlSnippets } from 'types'
|
|
import { contentKeys } from './keys'
|
|
|
|
export type ContentBase = components['schemas']['GetUserContentObject']
|
|
|
|
export type Content = Omit<ContentBase, 'content' | 'type'> &
|
|
(
|
|
| {
|
|
type: 'sql'
|
|
content: SqlSnippets.Content
|
|
}
|
|
| {
|
|
type: 'report'
|
|
content: Dashboards.Content
|
|
}
|
|
| {
|
|
type: 'log_sql'
|
|
content: LogSqlSnippets.Content
|
|
}
|
|
)
|
|
|
|
export type ContentType = Content['type']
|
|
|
|
interface GetContentVariables {
|
|
projectRef?: string
|
|
type: ContentType
|
|
}
|
|
|
|
export async function getContent({ projectRef, type }: GetContentVariables, signal?: AbortSignal) {
|
|
if (typeof projectRef === 'undefined') {
|
|
throw new Error('projectRef is required for getContent')
|
|
}
|
|
|
|
const { data, error } = await get('/platform/projects/{ref}/content', {
|
|
params: { path: { ref: projectRef }, query: { type } },
|
|
signal,
|
|
})
|
|
|
|
if (error) {
|
|
throw error
|
|
}
|
|
|
|
return {
|
|
cursor: data.cursor,
|
|
content: data.data as unknown as Content[],
|
|
}
|
|
}
|
|
|
|
export type ContentData = Awaited<ReturnType<typeof getContent>>
|
|
export type ContentError = unknown
|
|
|
|
export const useContentQuery = <TData = ContentData>(
|
|
{ projectRef, type }: GetContentVariables,
|
|
{ enabled = true, ...options }: UseQueryOptions<ContentData, ContentError, TData> = {}
|
|
) =>
|
|
useQuery<ContentData, ContentError, TData>(
|
|
contentKeys.list(projectRef, type),
|
|
({ signal }) => getContent({ projectRef, type }, signal),
|
|
{ enabled: enabled && typeof projectRef !== 'undefined', ...options }
|
|
)
|