@@ -262,7 +262,7 @@ export function MiningComponentComponent() {
262
262
owner : session . user . id ,
263
263
quantity : minedAmount ,
264
264
anomaly : activePlanet . id ,
265
- configuration : { Uses : 1 } ,
265
+ configuration : { Uses : 1 , CommunityExpedition : "1 Mars 29 Nov 2024" } ,
266
266
} ,
267
267
] )
268
268
. select ( ) ;
@@ -305,97 +305,200 @@ export function MiningComponentComponent() {
305
305
}
306
306
} ;
307
307
308
- return (
309
- < div className = "relative h-screen w-full overflow-hidden bg-gray-100 text-[#2C4F64] flex flex-col" >
310
- < div className = "flex justify-between items-center p-4" >
311
- < h2 className = "text-2xl font-bold" > Mining Operations</ h2 >
312
- < Button
313
- onClick = { toggleMap }
314
- variant = "outline"
315
- className = "text-[#ffffff] hover:bg-[#5FCBC3]/20"
316
- >
317
- Switch to { activeMap === '2D' ? '3D' : '2D' } Map
318
- </ Button >
319
- </ div >
320
- < div className = "flex-grow flex flex-col md:flex-row overflow-hidden" >
321
- < div className = "w-full md:w-3/4 h-1/2 md:h-full relative" >
322
- { activeMap === '2D' ? (
323
- < TopographicMap
324
- deposits = { mineralDeposits }
325
- roverPosition = { roverPosition }
326
- selectedDeposit = { selectedDeposit }
327
- landmarks = { landmarks }
328
- onLandmarkClick = { handleLandmarkClick }
329
- onDepositSelect = { handleDepositSelect }
330
- />
331
- ) : (
332
- < TerrainMap
333
- deposits = { mineralDeposits }
334
- roverPosition = { roverPosition }
335
- selectedDeposit = { selectedDeposit }
336
- landmarks = { landmarks }
337
- onLandmarkClick = { handleLandmarkClick }
338
- />
339
- ) }
340
- </ div >
341
- < div className = "w-full md:w-1/4 h-1/2 md:h-full overflow-y-auto bg-white bg-opacity-90 p-4" >
342
- < div className = "space-y-4" >
343
- { selectedDeposit ? (
344
- < div >
345
- < h3 className = "text-lg font-semibold mb-2" > Selected Deposit: { selectedDeposit . name } </ h3 >
346
- < p > Amount: { selectedDeposit . amount } units</ p >
347
- < Button
348
- onClick = { handleStartMining }
349
- disabled = { isMining }
350
- className = "w-full mt-4"
351
- >
352
- { isMining ? 'Mining...' : 'Start Mining' }
353
- </ Button >
308
+ return (
309
+ < div className = "fixed inset-0 flex items-center justify-center bg-gray-900 bg-opacity-50 z-50" >
310
+ < div className = "relative w-[90%] h-[90%] bg-gray-100 text-[#2C4F64] flex flex-col rounded-lg overflow-hidden md:w-[90%] md:h-[90%] sm:w-full sm:h-full" >
311
+ < div className = "flex justify-between items-center p-4 bg-white shadow" >
312
+ < h2 className = "text-2xl font-bold" > Mining Operations</ h2 >
313
+ < Button
314
+ onClick = { toggleMap }
315
+ variant = "outline"
316
+ className = "text-[#ffffff] hover:bg-[#5FCBC3]/20"
317
+ >
318
+ Switch to { activeMap === '2D' ? '3D' : '2D' } Map
319
+ </ Button >
320
+ </ div >
321
+ < div className = "flex-grow flex flex-col md:flex-row overflow-hidden" >
322
+ < div className = "w-full md:w-3/4 h-1/2 md:h-full relative" >
323
+ { activeMap === '2D' ? (
324
+ < TopographicMap
325
+ deposits = { mineralDeposits }
326
+ roverPosition = { roverPosition }
327
+ selectedDeposit = { selectedDeposit }
328
+ landmarks = { landmarks }
329
+ onLandmarkClick = { handleLandmarkClick }
330
+ onDepositSelect = { handleDepositSelect }
331
+ />
332
+ ) : (
333
+ < TerrainMap
334
+ deposits = { mineralDeposits }
335
+ roverPosition = { roverPosition }
336
+ selectedDeposit = { selectedDeposit }
337
+ landmarks = { landmarks }
338
+ onLandmarkClick = { handleLandmarkClick }
339
+ />
340
+ ) }
341
+ </ div >
342
+ < div className = "w-full md:w-1/4 h-1/2 md:h-full overflow-y-auto bg-white bg-opacity-90 p-4" >
343
+ < div className = "space-y-4" >
344
+ { selectedDeposit ? (
345
+ < div >
346
+ < h3 className = "text-lg font-semibold mb-2" > Selected Deposit</ h3 >
347
+ < p > { selectedDeposit . name } </ p >
348
+ < Button
349
+ onClick = { handleStartMining }
350
+ className = "mt-2 bg-green-500 hover:bg-green-600 text-white"
351
+ >
352
+ Start Mining
353
+ </ Button >
354
+ </ div >
355
+ ) : (
356
+ < p className = "text-gray-500" > Select a deposit to start mining.</ p >
357
+ ) }
354
358
</ div >
355
- ) : (
359
+ < div >
356
360
< MineralDepositList
357
361
deposits = { mineralDeposits }
358
362
onSelect = { handleDepositSelect }
359
363
selectedDeposit = { selectedDeposit }
360
364
/>
361
- ) }
365
+ < MineralDepositsGenerator />
366
+ </ div >
367
+ < Inventory />
368
+ </ div >
362
369
</ div >
370
+ { activeLandmark && (
371
+ < div
372
+ className = "absolute inset-0 bg-black bg-opacity-75 flex items-center justify-center z-50"
373
+ onClick = { closeModal }
374
+ >
375
+ < div
376
+ className = "bg-white rounded-lg p-4 max-w-md w-full"
377
+ onClick = { ( e ) => e . stopPropagation ( ) }
378
+ >
379
+ < h3 className = "text-xl font-bold" > { activeLandmark . name } </ h3 >
380
+ < p > { activeLandmark . description } </ p >
381
+ < Button
382
+ onClick = { closeModal }
383
+ className = "mt-4 bg-red-500 hover:bg-red-600 text-white"
384
+ >
385
+ Close
386
+ </ Button >
387
+ </ div >
388
+ </ div >
389
+ ) }
363
390
</ div >
364
391
</ div >
365
- < div className = "bg-white bg-opacity-90 p-4 border-t border-gray-200" >
366
- < Inventory />
367
- </ div >
368
- { activeLandmark && (
369
- < LandmarkModal
370
- landmark = { activeLandmark }
371
- isOpen = { activeLandmark . isOpen }
372
- onClose = { closeModal }
373
- />
374
- ) }
375
- </ div >
376
- ) ;
392
+ ) ;
377
393
} ;
378
394
379
- type LandmarkModalProps = {
380
- landmark : Landmark | null ;
381
- isOpen : boolean ;
382
- onClose : ( ) => void ;
383
- } ;
395
+ // type LandmarkModalProps = {
396
+ // landmark: Landmark | null;
397
+ // isOpen: boolean;
398
+ // onClose: () => void;
399
+ // };
400
+
401
+ // const LandmarkModal: React.FC<LandmarkModalProps> = ({ landmark, isOpen, onClose }) => {
402
+ // if (!isOpen || !landmark) return null;
403
+
404
+ // return (
405
+ // <div className="fixed inset-0 z-50 flex items-center justify-center bg-black bg-opacity-50">
406
+ // <div className="bg-white rounded-lg shadow-lg max-w-md w-full p-6 relative">
407
+ // <button
408
+ // className="absolute top-3 right-3 text-gray-500 hover:text-gray-800"
409
+ // onClick={onClose}
410
+ // >
411
+ // ×
412
+ // </button>
413
+ // <h2 className="text-2xl font-bold mb-2">{landmark.name}</h2>
414
+ // <p className="text-gray-700">{landmark.description}</p>
415
+ // </div>
416
+ // </div>
417
+ // );
418
+ // };
419
+
420
+ const MineralDepositsGenerator : React . FC = ( ) => {
421
+ const supabase = useSupabaseClient ( ) ;
422
+ const session = useSession ( ) ;
423
+ const { activePlanet } = useActivePlanet ( ) ;
424
+
425
+ const [ classificationsCount , setClassificationsCount ] = useState ( 0 ) ;
426
+ const [ creatingDeposits , setCreatingDeposits ] = useState ( false ) ;
427
+ const [ mineralDeposits , setMineralDeposits ] = useState < any [ ] > ( [ ] ) ; // Track created deposits
428
+ const [ notification , setNotification ] = useState < string | null > ( null ) ;
429
+
430
+ const availableMinerals = [ 11 , 13 , 15 , 16 , 18 , 19 ] ;
431
+
432
+ useEffect ( ( ) => {
433
+ const fetchClassifications = async ( ) => {
434
+ if ( ! session ?. user ?. id || ! activePlanet ?. id ) {
435
+ console . error ( "User or activePlanet is undefined." ) ;
436
+ return ;
437
+ }
438
+ const { data : classifications , error } = await supabase
439
+ . from ( 'classifications' )
440
+ . select ( '*' )
441
+ . eq ( 'user' , session . user . id )
442
+ . eq ( 'planet_id' , activePlanet . id ) ;
443
+
444
+ if ( error ) {
445
+ console . error ( "Error fetching classifications:" , error ) ;
446
+ } else {
447
+ console . log ( "Fetched classifications:" , classifications ) ;
448
+ // Make sure to set the classifications state correctly
449
+ }
450
+ } ;
451
+ fetchClassifications ( ) ;
452
+ } , [ session , activePlanet , supabase ] ) ;
453
+
454
+ const handleCreateDeposits = async ( ) => {
455
+ if ( ! session ?. user ?. id || ! activePlanet ?. id ) {
456
+ console . error ( "User or activePlanet is undefined." ) ;
457
+ return ;
458
+ }
459
+
460
+ // Randomly pick a mineral ID from availableMinerals
461
+ const randomMineral = availableMinerals [ Math . floor ( Math . random ( ) * availableMinerals . length ) ] ;
462
+
463
+ const newDeposit = {
464
+ mineralconfiguration : {
465
+ mineral : randomMineral , // Use the mineral ID (number)
466
+ quantity : 100 ,
467
+ icon_url : `https://example.com/mineral-icon-${ randomMineral } .png` , // Assuming different icons for each mineral
468
+ level : 1 ,
469
+ uses : [ 'Mining' , 'Excavation' ] ,
470
+ position : { x : Math . random ( ) * 100 , y : Math . random ( ) * 100 } // Random position
471
+ } ,
472
+ owner : session . user . id ,
473
+ anomaly : activePlanet . id ,
474
+ } ;
475
+
476
+ const { data, error } = await supabase
477
+ . from ( 'mineralDeposits' )
478
+ . insert ( [ newDeposit ] )
479
+ . select ( ) ;
480
+
481
+ if ( error ) {
482
+ console . error ( "Error creating deposit:" , error ) ;
483
+ return ;
484
+ }
384
485
385
- const LandmarkModal : React . FC < LandmarkModalProps > = ( { landmark, isOpen, onClose } ) => {
386
- if ( ! isOpen || ! landmark ) return null ;
486
+ console . log ( "Created new deposit:" , data ) ;
487
+ // Optionally, update the local state to reflect the new deposit
488
+ setMineralDeposits ( prevDeposits => [
489
+ ...prevDeposits ,
490
+ { ...newDeposit . mineralconfiguration , id : data [ 0 ] . id }
491
+ ] ) ;
492
+ } ;
387
493
388
494
return (
389
- < div className = "fixed inset-0 z-50 flex items-center justify-center bg-black bg-opacity-50" >
390
- < div className = "bg-white rounded-lg shadow-lg max-w-md w-full p-6 relative" >
391
- < button
392
- className = "absolute top-3 right-3 text-gray-500 hover:text-gray-800"
393
- onClick = { onClose }
394
- >
395
- ×
396
- </ button >
397
- < h2 className = "text-2xl font-bold mb-2" > { landmark . name } </ h2 >
398
- < p className = "text-gray-700" > { landmark . description } </ p >
495
+ < div className = "mineral-deposits-container" >
496
+ < div className = "content" >
497
+ < h2 > Create Mineral Deposits</ h2 >
498
+ < p > You have { classificationsCount } classifications. You can create up to 3 mineral deposits.</ p >
499
+ < Button onClick = { handleCreateDeposits } disabled = { creatingDeposits } >
500
+ { creatingDeposits ? 'Creating...' : 'Create Deposits' }
501
+ </ Button >
399
502
</ div >
400
503
</ div >
401
504
) ;
0 commit comments