@@ -11,39 +11,47 @@ import { useActivePlanet } from "@/context/ActivePlanet";
11
11
export default function InventoryPage ( ) {
12
12
const supabase = useSupabaseClient ( ) ;
13
13
const session = useSession ( ) ;
14
-
15
14
const { activePlanet } = useActivePlanet ( ) ;
16
15
17
16
const [ inventoryItems , setInventoryItems ] = useState < InventoryItem [ ] > ( [ ] ) ;
18
17
const [ userInventory , setUserInventory ] = useState < UserInventoryItem [ ] > ( [ ] ) ;
19
18
const [ loading , setLoading ] = useState < boolean > ( true ) ;
19
+ const [ isOverlayOpen , setOverlayOpen ] = useState < boolean > ( false ) ; // State to track overlay visibility
20
20
21
- const GRID_SIZE = 4 ;
21
+ const GRID_SIZE = 8 ; // Adjusting the size for horizontal scroll
22
22
23
23
useEffect ( ( ) => {
24
24
fetchData ( ) ;
25
- } , [ ] ) ;
25
+ } , [ activePlanet , supabase ] ) ;
26
26
27
27
async function fetchData ( ) {
28
+ if ( ! activePlanet ) {
29
+ console . log ( "No active planet" ) ;
30
+ return ;
31
+ }
32
+
28
33
try {
29
34
const [ itemsRes , { data : { session } } ] = await Promise . all ( [
30
35
fetch ( "/api/gameplay/inventory" ) ,
31
- supabase . auth . getSession ( )
36
+ supabase . auth . getSession ( ) ,
32
37
] ) ;
33
38
34
39
let items : InventoryItem [ ] = await itemsRes . json ( ) ;
35
- items = items . filter ( item =>
36
- ( item . ItemCategory === "Structure" || item . ItemCategory === "CommunityStation" ) &&
37
- item . locationType === "Surface"
40
+ items = items . filter (
41
+ ( item ) =>
42
+ ( item . ItemCategory === "Structure" ||
43
+ item . ItemCategory === "CommunityStation" ) &&
44
+ item . locationType === "Surface"
38
45
) ;
39
46
40
47
setInventoryItems ( items ) ;
48
+ console . log ( inventoryItems ) ;
41
49
42
50
if ( session ?. user ) {
43
51
const { data : userItems } = await supabase
44
52
. from ( "inventory" )
45
53
. select ( "*" )
46
- . eq ( "anomaly" , activePlanet ? .id )
54
+ . eq ( "anomaly" , activePlanet . id )
47
55
. eq ( "owner" , session . user . id ) ;
48
56
49
57
setUserInventory ( userItems || [ ] ) ;
@@ -59,12 +67,12 @@ export default function InventoryPage() {
59
67
const { data : { session } } = await supabase . auth . getSession ( ) ;
60
68
if ( ! session ?. user ) return ;
61
69
62
- const inventoryItem = userInventory . find ( item => item . id === itemId ) ;
70
+ const inventoryItem = userInventory . find ( ( item ) => item . id === itemId ) ;
63
71
if ( ! inventoryItem ) return ;
64
72
65
73
const newConfig = {
66
74
...inventoryItem . configuration ,
67
- slot : slotIndex
75
+ slot : slotIndex ,
68
76
} ;
69
77
70
78
const { error } = await supabase
@@ -75,8 +83,8 @@ export default function InventoryPage() {
75
83
if ( error ) {
76
84
toast . error ( "Failed to update item position" ) ;
77
85
} else {
78
- setUserInventory ( prev =>
79
- prev . map ( item =>
86
+ setUserInventory ( ( prev ) =>
87
+ prev . map ( ( item ) =>
80
88
item . id === itemId
81
89
? { ...item , configuration : newConfig }
82
90
: item
@@ -89,14 +97,16 @@ export default function InventoryPage() {
89
97
if ( ! result . destination ) return ;
90
98
91
99
const sourceId = result . draggableId ;
92
- const destinationIndex = parseInt ( result . destination . droppableId . split ( "-" ) [ 1 ] ) ;
100
+ const destinationIndex = parseInt (
101
+ result . destination . droppableId . split ( "-" ) [ 1 ]
102
+ ) ;
93
103
94
104
updateItemConfiguration ( parseInt ( sourceId ) , destinationIndex ) ;
95
105
} ;
96
106
97
107
return (
98
108
< DragDropContext onDragEnd = { onDragEnd } >
99
- < div className = "p-4 max-w-7xl mx-auto" >
109
+ < div className = "p-4 max-w-full mx-auto overflow-x -auto" >
100
110
< div className = "relative" >
101
111
< div className = "sci-fi-shape sci-fi-shape-1" />
102
112
< div className = "sci-fi-shape sci-fi-shape-2" />
@@ -113,10 +123,42 @@ export default function InventoryPage() {
113
123
< div className = "sci-fi-wire sci-fi-wire-2" />
114
124
< div className = "sci-fi-signal sci-fi-signal-2" />
115
125
116
- < InventoryList
117
- userInventory = { userInventory }
118
- inventoryItems = { inventoryItems }
119
- />
126
+ { /* Open Overlay Button directly below the main grid */ }
127
+ < button
128
+ onClick = { ( ) => setOverlayOpen ( ! isOverlayOpen ) } // Toggle overlay
129
+ className = "mt-4 bg-blue-600 text-white px-4 py-2 rounded-lg"
130
+ >
131
+ { isOverlayOpen ? "Close Inventory Items" : "Open Inventory Items" }
132
+ </ button >
133
+
134
+ { /* Sliding Inventory Overlay */ }
135
+ < div
136
+ className = { `fixed bottom-0 left-0 right-0 z-50 transition-transform duration-500 ${
137
+ isOverlayOpen ? "translate-y-0" : "translate-y-full"
138
+ } `}
139
+ style = { { height : "40vh" } } // Occupy 40% of the screen height
140
+ >
141
+ { /* No border or background, just the items */ }
142
+ < div className = "p-4 h-full overflow-y-auto" >
143
+ < div className = "flex justify-between items-center" >
144
+ < h2 className = "text-2xl font-bold mb-4 text-white" > Inventory Items</ h2 >
145
+
146
+ { /* Close Overlay Button */ }
147
+ < button
148
+ onClick = { ( ) => setOverlayOpen ( false ) }
149
+ className = "bg-red-500 text-white px-3 py-1 rounded-lg"
150
+ >
151
+ Close
152
+ </ button >
153
+ </ div >
154
+
155
+ { /* Inventory Items List */ }
156
+ < InventoryList
157
+ userInventory = { userInventory }
158
+ inventoryItems = { inventoryItems }
159
+ />
160
+ </ div >
161
+ </ div >
120
162
</ div >
121
163
</ div >
122
164
</ DragDropContext >
@@ -135,6 +177,7 @@ interface InventoryItem {
135
177
locationType ?: string ;
136
178
recipe ?: { [ key : string ] : number } ;
137
179
gif ?: string ;
180
+ configuration ?: { slot ?: number } | null ;
138
181
} ;
139
182
140
183
interface UserInventoryItem {
0 commit comments