1
- import type { PublishDiffInfo } from '@graphprotocol/hypergraph-react' ;
2
- import {
3
- PublishDiff ,
4
- publishOps ,
5
- useCreateEntity ,
6
- useDeleteEntity ,
7
- useHypergraphApp ,
8
- useQuery ,
9
- useSpace ,
10
- useUpdateEntity ,
11
- } from '@graphprotocol/hypergraph-react' ;
12
- import { useQueryClient } from '@tanstack/react-query' ;
1
+ import { useCreateEntity , useDeleteEntity , useQuery , useSpace , useUpdateEntity } from '@graphprotocol/hypergraph-react' ;
13
2
import { useEffect , useState } from 'react' ;
14
3
import Select from 'react-select' ;
15
4
import { cn } from '@/lib/utils' ;
@@ -19,7 +8,6 @@ import { TodosLocal } from './todo/todos-local';
19
8
import { TodosPublic } from './todo/todos-public' ;
20
9
import { Button } from './ui/button' ;
21
10
import { Input } from './ui/input' ;
22
- import { Modal } from './ui/modal' ;
23
11
24
12
export const Todos2 = ( ) => {
25
13
const {
@@ -34,20 +22,14 @@ export const Todos2 = () => {
34
22
isError : isErrorUsers ,
35
23
// preparePublish: preparePublishUsers,
36
24
} = useQuery ( User , { mode : 'private' } ) ;
37
- const { ready : spaceReady , id : spaceId } = useSpace ( { mode : 'private' } ) ;
38
- const { getSmartSessionClient } = useHypergraphApp ( ) ;
25
+ const { ready : spaceReady } = useSpace ( { mode : 'private' } ) ;
39
26
const createTodo = useCreateEntity ( Todo2 ) ;
40
27
const updateTodo = useUpdateEntity ( Todo2 ) ;
41
28
const createUser = useCreateEntity ( User ) ;
42
29
const deleteEntity = useDeleteEntity ( ) ;
43
30
const [ newTodoName , setNewTodoName ] = useState ( '' ) ;
44
31
const [ newTodoAssignees , setNewTodoAssignees ] = useState < { value : string ; label : string } [ ] > ( [ ] ) ;
45
32
const [ newUserName , setNewUserName ] = useState ( '' ) ;
46
- const queryClient = useQueryClient ( ) ;
47
- const [ publishData , setPublishData ] = useState < PublishDiffInfo | null > ( null ) ;
48
- const [ isPublishDiffModalOpen , setIsPublishDiffModalOpen ] = useState ( false ) ;
49
- const [ isPreparingPublish , setIsPreparingPublish ] = useState ( false ) ;
50
- const [ isPublishing , setIsPublishing ] = useState ( false ) ;
51
33
52
34
useEffect ( ( ) => {
53
35
setNewTodoAssignees ( ( prevFilteredAssignees ) => {
@@ -74,8 +56,6 @@ export const Todos2 = () => {
74
56
< div key = { user . id } className = "flex flex-row items-center gap-2" >
75
57
< h2 > { user . name } </ h2 >
76
58
< div className = "text-xs" > { user . id } </ div >
77
- { /* @ts -expect-error */ }
78
- < div className = "text-xs" > { user . __version } </ div >
79
59
< Button variant = "outline" size = "sm" onClick = { ( ) => deleteEntity ( user . id ) } >
80
60
Delete
81
61
</ Button >
@@ -140,8 +120,6 @@ export const Todos2 = () => {
140
120
) ) }
141
121
</ span >
142
122
) }
143
- { /* @ts -expect-error */ }
144
- < div className = "text-xs" > { todo . __version } </ div >
145
123
< Button variant = "outline" size = "sm" onClick = { ( ) => deleteEntity ( todo . id ) } >
146
124
Delete
147
125
</ Button >
@@ -179,92 +157,6 @@ export const Todos2 = () => {
179
157
</ Button >
180
158
</ div >
181
159
182
- < Button
183
- onClick = { async ( ) => {
184
- try {
185
- setIsPreparingPublish ( true ) ;
186
- // const usersResult = await preparePublishUsers();
187
- // console.log('users ops & diff', usersResult);
188
- // const todosResult = await preparePublishTodos();
189
- // console.log('todos ops & diff', todosResult);
190
-
191
- // if (todosResult && usersResult) {
192
- // setPublishData({
193
- // newEntities: [...todosResult.newEntities, ...usersResult.newEntities],
194
- // deletedEntities: [...todosResult.deletedEntities, ...usersResult.deletedEntities],
195
- // updatedEntities: [...todosResult.updatedEntities, ...usersResult.updatedEntities],
196
- // });
197
- // setIsPublishDiffModalOpen(true);
198
- // } else {
199
- // console.error('preparing publishing error', todosResult, usersResult);
200
- // throw new Error('Failed to prepare the publishing operations');
201
- // }
202
- } catch ( error ) {
203
- console . error ( 'preparing publishing error' , error ) ;
204
- alert ( 'Failed to prepare the publishing operations' ) ;
205
- } finally {
206
- setIsPreparingPublish ( false ) ;
207
- }
208
- } }
209
- disabled = { isPreparingPublish }
210
- >
211
- { isPreparingPublish ? 'Preparing …' : 'Prepare Publish' }
212
- </ Button >
213
-
214
- < Modal isOpen = { isPublishDiffModalOpen } onOpenChange = { setIsPublishDiffModalOpen } >
215
- < div className = "p-4 flex flex-col gap-4 min-w-96" >
216
- < PublishDiff
217
- newEntities = { publishData ?. newEntities ?? [ ] }
218
- deletedEntities = { publishData ?. deletedEntities ?? [ ] }
219
- updatedEntities = { publishData ?. updatedEntities ?? [ ] }
220
- />
221
- < Button
222
- onClick = { async ( ) => {
223
- try {
224
- const smartSessionClient = await getSmartSessionClient ( ) ;
225
- if ( ! smartSessionClient ) {
226
- throw new Error ( 'Missing smartSessionClient' ) ;
227
- }
228
- if ( publishData ) {
229
- setIsPublishing ( true ) ;
230
- const ops = [
231
- ...publishData . newEntities . map ( ( entity ) => entity . ops ) ,
232
- ...publishData . updatedEntities . map ( ( entity ) => entity . ops ) ,
233
- ...publishData . deletedEntities . map ( ( entity ) => entity . ops ) ,
234
- ] . flat ( ) ;
235
- const publishOpsResult = await publishOps ( {
236
- ops,
237
- walletClient : smartSessionClient ,
238
- space : spaceId ,
239
- name : 'Update users and todos' ,
240
- } ) ;
241
- console . log ( 'publishOpsResult' , publishOpsResult ) ;
242
- setIsPublishDiffModalOpen ( false ) ;
243
- setPublishData ( null ) ;
244
- setTimeout ( ( ) => {
245
- queryClient . invalidateQueries ( {
246
- queryKey : [ 'hypergraph-public-entities' , Todo2 . name ] ,
247
- } ) ;
248
- } , 1000 ) ;
249
- }
250
- } catch ( error ) {
251
- console . error ( 'publishing error' , error ) ;
252
- } finally {
253
- setIsPublishing ( false ) ;
254
- }
255
- } }
256
- disabled = {
257
- ( publishData ?. newEntities . length === 0 &&
258
- publishData ?. updatedEntities . length === 0 &&
259
- publishData ?. deletedEntities . length === 0 ) ||
260
- isPublishing
261
- }
262
- >
263
- { isPublishing ? 'Publishing …' : 'Publish' }
264
- </ Button >
265
- </ div >
266
- </ Modal >
267
-
268
160
< TodosLocal />
269
161
270
162
< TodosPublic />
0 commit comments