@@ -160,6 +160,8 @@ <h3>Register New Field</h3>
160160 </ div >
161161
162162 < script >
163+ let uploadedMedia = [ ] ;
164+
163165 // Load fields from localStorage
164166 function loadFields ( ) {
165167 const fieldsGrid = document . getElementById ( 'fieldsGrid' ) ;
@@ -198,7 +200,6 @@ <h3>${field.name}</h3>
198200 document . getElementById ( 'mediaUpload' ) . addEventListener ( 'change' , function ( e ) {
199201 const files = Array . from ( e . target . files ) ;
200202 const mediaPreview = document . getElementById ( 'mediaPreview' ) ;
201- let fieldData = JSON . parse ( localStorage . getItem ( 'fieldData' ) ) || { fields : [ ] } ;
202203
203204 files . forEach ( file => {
204205 const reader = new FileReader ( ) ;
@@ -212,19 +213,14 @@ <h3>${field.name}</h3>
212213 mediaPreview . appendChild ( mediaItem ) ;
213214
214215 // Store media reference
215- if ( fieldData . fields . length > 0 ) {
216- fieldData . fields [ 0 ] . media . push ( {
217- type : file . type . startsWith ( 'image' ) ? 'image' : 'video' ,
218- url : e . target . result ,
219- timestamp : new Date ( ) . toISOString ( )
220- } ) ;
221- }
216+ uploadedMedia . push ( {
217+ type : file . type . startsWith ( 'image' ) ? 'image' : 'video' ,
218+ url : e . target . result ,
219+ timestamp : new Date ( ) . toISOString ( )
220+ } ) ;
222221 } ;
223222 reader . readAsDataURL ( file ) ;
224223 } ) ;
225-
226- // Update localStorage
227- localStorage . setItem ( 'fieldData' , JSON . stringify ( fieldData ) ) ;
228224 } ) ;
229225
230226 // Register new field
@@ -245,7 +241,7 @@ <h3>${field.name}</h3>
245241 health : fieldHealth ,
246242 yield : 'N/A' ,
247243 lastUpdated : new Date ( ) . toISOString ( ) ,
248- media : [ ]
244+ media : uploadedMedia
249245 } ) ;
250246
251247 localStorage . setItem ( 'fieldData' , JSON . stringify ( fieldData ) ) ;
@@ -290,4 +286,4 @@ <h3>${field.name}</h3>
290286 } ) ;
291287 </ script >
292288</ body >
293- </ html >
289+ </ html >
0 commit comments