mirror of
https://github.com/supabase/supabase.git
synced 2026-10-07 10:25:06 +03:00
## Context API changes are ready so hooking up the endpoints for full CRUD UX E2E - Can create notebooks - Can load notebooks - Can delete notebooks - Can update notebooks
44 lines
1.1 KiB
TypeScript
44 lines
1.1 KiB
TypeScript
import { type InfiniteData } from '@tanstack/react-query'
|
|
|
|
import { ContentData, ContentError, useContentInfiniteQuery } from '../content-infinite-query'
|
|
import type { ContentOfType } from '../content-query'
|
|
import type { UseCustomInfiniteQueryOptions } from '@/types'
|
|
|
|
export type NotebookRow = ContentOfType<'notebook'>
|
|
|
|
export interface NotebooksVariables {
|
|
projectRef?: string
|
|
name?: string
|
|
limit?: number
|
|
sort?: 'name' | 'inserted_at'
|
|
}
|
|
|
|
export interface NotebooksPage {
|
|
cursor: string | undefined
|
|
content: NotebookRow[]
|
|
}
|
|
|
|
export const useNotebooksInfiniteQuery = (
|
|
{ projectRef, name, limit, sort }: NotebooksVariables,
|
|
options: Omit<
|
|
UseCustomInfiniteQueryOptions<
|
|
ContentData,
|
|
ContentError,
|
|
InfiniteData<NotebooksPage>,
|
|
ReadonlyArray<unknown>,
|
|
string | undefined
|
|
>,
|
|
'select'
|
|
> = {}
|
|
) =>
|
|
useContentInfiniteQuery<NotebooksPage>(
|
|
{ projectRef, type: 'notebook', name, limit, sort },
|
|
{
|
|
...options,
|
|
select: (data) => ({
|
|
...data,
|
|
pages: data.pages.map((page) => ({ ...page, content: page.content as NotebookRow[] })),
|
|
}),
|
|
}
|
|
)
|