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' ;
132import { useEffect , useState } from 'react' ;
143import Select from 'react-select' ;
154import { cn } from '@/lib/utils' ;
@@ -19,7 +8,6 @@ import { TodosLocal } from './todo/todos-local';
198import { TodosPublic } from './todo/todos-public' ;
209import { Button } from './ui/button' ;
2110import { Input } from './ui/input' ;
22- import { Modal } from './ui/modal' ;
2311
2412export const Todos2 = ( ) => {
2513 const {
@@ -34,20 +22,14 @@ export const Todos2 = () => {
3422 isError : isErrorUsers ,
3523 // preparePublish: preparePublishUsers,
3624 } = useQuery ( User , { mode : 'private' } ) ;
37- const { ready : spaceReady , id : spaceId } = useSpace ( { mode : 'private' } ) ;
38- const { getSmartSessionClient } = useHypergraphApp ( ) ;
25+ const { ready : spaceReady } = useSpace ( { mode : 'private' } ) ;
3926 const createTodo = useCreateEntity ( Todo2 ) ;
4027 const updateTodo = useUpdateEntity ( Todo2 ) ;
4128 const createUser = useCreateEntity ( User ) ;
4229 const deleteEntity = useDeleteEntity ( ) ;
4330 const [ newTodoName , setNewTodoName ] = useState ( '' ) ;
4431 const [ newTodoAssignees , setNewTodoAssignees ] = useState < { value : string ; label : string } [ ] > ( [ ] ) ;
4532 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 ) ;
5133
5234 useEffect ( ( ) => {
5335 setNewTodoAssignees ( ( prevFilteredAssignees ) => {
@@ -74,8 +56,6 @@ export const Todos2 = () => {
7456 < div key = { user . id } className = "flex flex-row items-center gap-2" >
7557 < h2 > { user . name } </ h2 >
7658 < div className = "text-xs" > { user . id } </ div >
77- { /* @ts -expect-error */ }
78- < div className = "text-xs" > { user . __version } </ div >
7959 < Button variant = "outline" size = "sm" onClick = { ( ) => deleteEntity ( user . id ) } >
8060 Delete
8161 </ Button >
@@ -140,8 +120,6 @@ export const Todos2 = () => {
140120 ) ) }
141121 </ span >
142122 ) }
143- { /* @ts -expect-error */ }
144- < div className = "text-xs" > { todo . __version } </ div >
145123 < Button variant = "outline" size = "sm" onClick = { ( ) => deleteEntity ( todo . id ) } >
146124 Delete
147125 </ Button >
@@ -179,92 +157,6 @@ export const Todos2 = () => {
179157 </ Button >
180158 </ div >
181159
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-
268160 < TodosLocal />
269161
270162 < TodosPublic />
0 commit comments