1- import { useState , useEffect } from 'react'
2- import { useIPFS } from './context/IPFSContext'
3- import { Task , TaskDifficulty } from '../../objects/BoardTask'
1+ import { useState } from 'react'
42import reactLogo from './assets/react.svg'
53import viteLogo from '/vite.svg'
64import './App.css'
75
86
97function App ( ) {
10- const { ipfsBoard, loading : configLoading , error } = useIPFS ( ) ;
118 const [ count , setCount ] = useState ( 0 )
12- const [ title , setTitle ] = useState ( "" ) ;
13- const [ description , setDescription ] = useState ( "" ) ;
14- const [ cid , setCid ] = useState < string | null > ( null ) ;
15- const [ loading , setLoading ] = useState ( false ) ;
16-
17- // Sync config loading with local loading
18- useEffect ( ( ) => {
19- setLoading ( configLoading ) ;
20- } , [ configLoading ] ) ;
21-
22- if ( loading ) return < p > Loading configuration...</ p > ;
23- if ( error ) return < p > Error loading config: { error . message } </ p > ;
24- if ( ! ipfsBoard ) return < p > No config loaded</ p > ;
25-
26- const createAndUploadTask = async ( ) => {
27- setLoading ( true ) ;
28- try {
29- const task = new Task ( {
30- title,
31- description,
32- difficulty : TaskDifficulty . EASY ,
33- tags : [ "demo" ] ,
34- createdBy : "User123" ,
35- } ) ;
36-
37- const newCid = await ipfsBoard . publishTask ( task ) ;
38- setCid ( newCid ) ;
39- } catch ( err ) {
40- console . error ( err ) ;
41- } finally {
42- setLoading ( false ) ;
43- }
44- } ;
45-
46- const downloadTask = async ( ) => {
47- if ( ! cid ) return ;
48- try {
49- const task = await ipfsBoard . loadTaskFromIPFS ( cid ) ;
50- alert ( `Loaded task: ${ task . title } ` ) ;
51- } catch ( err ) {
52- console . error ( err ) ;
53- }
54- } ;
559
5610 return (
5711 < >
@@ -75,31 +29,6 @@ function App() {
7529 < p className = "read-the-docs" >
7630 Click on the Vite and React logos to learn more
7731 </ p >
78- < div style = { { padding : 20 } } >
79- < h2 > Create Task</ h2 >
80- < input
81- type = "text"
82- placeholder = "Task title"
83- value = { title }
84- onChange = { ( e ) => setTitle ( e . target . value ) }
85- />
86- < br />
87- < textarea
88- placeholder = "Task description"
89- value = { description }
90- onChange = { ( e ) => setDescription ( e . target . value ) }
91- />
92- < br />
93- < button onClick = { createAndUploadTask } disabled = { loading } >
94- { loading ? "Uploading..." : "Upload to IPFS" }
95- </ button >
96- { cid && (
97- < >
98- < p > ✅ Task uploaded with CID: { cid } </ p >
99- < button onClick = { downloadTask } > Download Task from IPFS</ button >
100- </ >
101- ) }
102- </ div >
10332 </ >
10433 )
10534}
0 commit comments