11import type { Address } from '@solana/kit'
22import { type MutateOptions , mutationOptions , queryOptions } from '@tanstack/react-query'
3- import { bookmarkAccountCreate } from '@workspace/db/bookmark-account/bookmark-account-create'
4- import type { BookmarkAccountCreateInput } from '@workspace/db/bookmark-account/bookmark-account-create-input'
5- import { bookmarkAccountDelete } from '@workspace/db/bookmark-account/bookmark-account-delete'
63import { bookmarkAccountFindByAddress } from '@workspace/db/bookmark-account/bookmark-account-find-by-address'
74import { bookmarkAccountFindMany } from '@workspace/db/bookmark-account/bookmark-account-find-many'
85import type { BookmarkAccountFindManyInput } from '@workspace/db/bookmark-account/bookmark-account-find-many-input'
9- import { bookmarkAccountFindUnique } from '@workspace/db/bookmark-account/bookmark-account-find-unique '
6+ import { bookmarkAccountToggle } from '@workspace/db/bookmark-account/bookmark-account-toggle '
107import { bookmarkAccountUpdate } from '@workspace/db/bookmark-account/bookmark-account-update'
118import type { BookmarkAccountUpdateInput } from '@workspace/db/bookmark-account/bookmark-account-update-input'
129import { db } from '@workspace/db/db'
1310import { queryClient } from './query-client.tsx'
1411
15- export type BookmarkAccountCreateMutateOptions = MutateOptions <
16- string ,
17- Error ,
18- { input : Omit < BookmarkAccountCreateInput , 'address' > }
19- > & {
20- address : Address
21- }
22- export type BookmarkAccountDeleteMutateOptions = MutateOptions < void , Error , { id : string } > & {
23- address : Address
24- }
12+ export type BookmarkAccountToggleMutateOptions = MutateOptions < 'created' | 'deleted' , Error , { address : Address } >
2513export type BookmarkAccountUpdateMutateOptions = MutateOptions <
2614 number ,
2715 Error ,
2816 { address : Address ; input : BookmarkAccountUpdateInput }
2917>
30-
3118export const optionsBookmarkAccount = {
32- create : ( props : BookmarkAccountCreateMutateOptions ) =>
33- mutationOptions ( {
34- mutationFn : ( { input } : { input : Omit < BookmarkAccountCreateInput , 'address' > } ) =>
35- bookmarkAccountCreate ( db , { ...input , address : props . address } ) ,
36- onSuccess : ( ) => {
37- queryClient . invalidateQueries ( optionsBookmarkAccount . findByAddress ( props . address ) )
38- } ,
39- ...props ,
40- } ) ,
41- delete : ( props : BookmarkAccountDeleteMutateOptions ) =>
42- mutationOptions ( {
43- mutationFn : ( { id } : { id : string } ) => bookmarkAccountDelete ( db , id ) ,
44- onSuccess : ( ) => {
45- queryClient . invalidateQueries ( optionsBookmarkAccount . findByAddress ( props . address ) )
46- } ,
47- ...props ,
48- } ) ,
4919 findByAddress : ( address : Address ) =>
5020 queryOptions ( {
5121 queryFn : ( ) => bookmarkAccountFindByAddress ( db , address ) ,
@@ -56,10 +26,13 @@ export const optionsBookmarkAccount = {
5626 queryFn : ( ) => bookmarkAccountFindMany ( db , input ) ,
5727 queryKey : [ 'bookmarkAccountFindMany' , input ] ,
5828 } ) ,
59- findUnique : ( id : string ) =>
60- queryOptions ( {
61- queryFn : ( ) => bookmarkAccountFindUnique ( db , id ) ,
62- queryKey : [ 'bookmarkAccountFindUnique' , id ] ,
29+ toggle : ( props : BookmarkAccountToggleMutateOptions ) =>
30+ mutationOptions ( {
31+ mutationFn : ( { address } : { address : Address } ) => bookmarkAccountToggle ( db , address ) ,
32+ onSuccess : ( _ , { address } ) => {
33+ queryClient . invalidateQueries ( optionsBookmarkAccount . findByAddress ( address ) )
34+ } ,
35+ ...props ,
6336 } ) ,
6437 update : ( props : BookmarkAccountUpdateMutateOptions = { } ) =>
6538 mutationOptions ( {
0 commit comments