@@ -2,12 +2,13 @@ import type { ClusterModel } from '@/bindings.gen';
2
2
import DefaultBanner from '@/assets/images/default_banner.png' ;
3
3
import DefaultInstancePhoto from '@/assets/images/default_instance_cover.jpg' ;
4
4
import { NewClusterCreate } from '@/components/launcher/cluster/ClusterCreation' ;
5
+ import Modal from '@/components/overlay/Modal' ;
5
6
import { useRecentCluster } from '@/hooks/useCluster' ;
6
7
import { bindings } from '@/main' ;
7
8
import { formatAsDuration , upperFirst } from '@/utils' ;
8
9
import { useCommand , useCommandMut } from '@onelauncher/common' ;
9
10
import { Button , ContextMenu , Show , TextField } from '@onelauncher/common/components' ;
10
- import { createFileRoute , useNavigate } from '@tanstack/react-router' ;
11
+ import { createFileRoute , Link , useNavigate } from '@tanstack/react-router' ;
11
12
import { convertFileSrc } from '@tauri-apps/api/core' ;
12
13
import { dataDir , join } from '@tauri-apps/api/path' ;
13
14
import { open } from '@tauri-apps/plugin-dialog' ;
@@ -167,6 +168,7 @@ function ClusterCard({
167
168
id,
168
169
mc_loader,
169
170
mc_version,
171
+ stage,
170
172
} : ClusterModel ) {
171
173
const launch = useCommandMut ( ( ) => bindings . core . launchCluster ( id , null ) ) ;
172
174
const ref = useRef < HTMLDivElement > ( null ) ;
@@ -176,8 +178,7 @@ function ClusterCard({
176
178
const cluster = useCommand ( `getClusterById-${ id } ` , ( ) => bindings . core . getClusterById ( id ) ) ;
177
179
const [ newCover , setNewCover ] = useState < string > ( cluster . data ?. icon_url as string ) ;
178
180
const [ newName , setNewName ] = useState < string > ( cluster . data ?. name as string ) ;
179
- const [ edit , setEdit ] = useState ( false ) ;
180
- const [ hover , setHover ] = useState ( false ) ;
181
+ const [ modalOpen , setModalOpen ] = useState ( false ) ;
181
182
182
183
const handleLaunch = ( ) => {
183
184
launch . mutate ( ) ;
@@ -248,55 +249,48 @@ function ClusterCard({
248
249
}
249
250
250
251
return (
251
- < div onMouseEnter = { ( ) => setHover ( true ) } onMouseLeave = { ( ) => setHover ( false ) } ref = { ref } >
252
- < div
253
- className = "group relative h-[152px] flex flex-col rounded-xl border border-component-border/5 bg-component-bg active:bg-component-bg-pressed hover:bg-component-bg-hover"
252
+ < div ref = { ref } >
253
+ < Link
254
+ disabled = { stage === 'downloading' }
255
+ search = { {
256
+ id,
257
+ } }
258
+ to = "/app/cluster"
254
259
>
255
- < div className = "relative flex-1 overflow-hidden rounded-t-xl" >
256
- < div
257
- className = "absolute h-full w-full transition-transform group-hover:!scale-110"
258
- >
259
- < img
260
- className = "h-full w-full object-cover"
261
- onError = { ( e ) => {
262
- ( e . target as HTMLImageElement ) . src = DefaultInstancePhoto ;
263
- } }
264
- src = { image ( ) }
265
- />
266
- </ div >
267
- </ div >
268
- < div className = "z-10 flex flex-row items-center justify-between gap-x-3 p-3" >
269
- < div className = "h-full flex flex-col gap-1.5 overflow-hidden" >
270
- < Show
271
- fallback = { (
272
- < p className = "h-4 text-ellipsis whitespace-nowrap font-medium" >
273
- { cluster . data ?. name }
274
- </ p >
275
- ) }
276
- when = { edit }
260
+ < div
261
+ className = "group relative h-[152px] flex flex-col rounded-xl border border-component-border/5 bg-component-bg active:bg-component-bg-pressed hover:bg-component-bg-hover"
262
+ >
263
+ < div className = "relative flex-1 overflow-hidden rounded-t-xl" >
264
+ < div
265
+ className = "absolute h-full w-full transition-transform group-hover:!scale-110"
277
266
>
278
- < TextField
279
- className = "text-xl font-bold"
280
- iconRight = { (
281
- < Button className = "px-1.5" onClick = { ( ) => setEdit ( false ) } >
282
- < CheckIcon height = { 10 } width = { 10 } />
283
- </ Button >
284
- ) }
285
- onChange = { e => updateName ( e . target . value ) }
286
- placeholder = { cluster . data ?. name }
267
+ < img
268
+ className = "h-full w-full object-cover"
269
+ onError = { ( e ) => {
270
+ ( e . target as HTMLImageElement ) . src = DefaultInstancePhoto ;
271
+ } }
272
+ src = { image ( ) }
287
273
/>
288
- </ Show >
289
- < p className = "h-4 text-xs" >
290
- { mc_loader }
291
- { ' ' }
292
- { mc_version }
293
- </ p >
274
+ </ div >
294
275
</ div >
276
+ < div className = "z-10 flex flex-row items-center justify-between gap-x-3 p-3" >
277
+ < div className = "h-full flex flex-col gap-1.5 overflow-hidden" >
278
+ < p className = "h-4 text-ellipsis whitespace-nowrap font-medium" >
279
+ { cluster . data ?. name }
280
+ </ p >
281
+
282
+ < p className = "h-4 text-xs" >
283
+ { mc_loader }
284
+ { ' ' }
285
+ { mc_version }
286
+ </ p >
287
+ </ div >
295
288
296
- { /* <LaunchButton cluster={props} iconOnly /> */ }
297
- < Button onClick = { handleLaunch } size = "icon" > < PlayIcon /> </ Button >
289
+ { /* <LaunchButton cluster={props} iconOnly /> */ }
290
+ < Button onClick = { handleLaunch } size = "icon" > < PlayIcon /> </ Button >
291
+ </ div >
298
292
</ div >
299
- </ div >
293
+ </ Link >
300
294
301
295
< ContextMenu
302
296
isOpen = { isOpen }
@@ -308,14 +302,14 @@ function ClusterCard({
308
302
< PlayIcon className = "pb-0.5" height = { 14 } width = { 14 } />
309
303
</ ContextMenu . Item >
310
304
< ContextMenu . Separator />
311
- < ContextMenu . Item onAction = { ( ) => setEdit ( true ) } >
305
+ < ContextMenu . Item onAction = { ( ) => setModalOpen ( true ) } >
312
306
Rename
313
307
</ ContextMenu . Item >
314
308
< ContextMenu . Item onAction = { launchFilePicker } >
315
309
Change Icon
316
310
</ ContextMenu . Item >
317
311
< ContextMenu . Separator />
318
- < ContextMenu . Item onAction = { ( ) => { navigate ( { to : '/app/cluster' , search : { id } } ) ; } } >
312
+ < ContextMenu . Item isDisabled = { stage === 'downloading' } onAction = { ( ) => { navigate ( { to : '/app/cluster' , search : { id } } ) ; } } >
319
313
Properties
320
314
</ ContextMenu . Item >
321
315
< ContextMenu . Item onAction = { openClusterDir } >
@@ -328,6 +322,22 @@ function ClusterCard({
328
322
Export
329
323
</ContextMenu.Item> */ }
330
324
</ ContextMenu >
325
+
326
+ < Modal isDismissable isOpen = { modalOpen } >
327
+ < div className = "min-w-sm flex flex-col rounded-lg bg-page text-center" >
328
+ < Modal . Header name = "New Cluster name:" />
329
+ < TextField
330
+ className = "text-xl font-bold m-3"
331
+ iconRight = { (
332
+ < Button className = "px-1.5" onClick = { ( ) => setModalOpen ( false ) } >
333
+ < CheckIcon height = { 10 } width = { 10 } />
334
+ </ Button >
335
+ ) }
336
+ onChange = { e => updateName ( e . target . value ) }
337
+ placeholder = { cluster . data ?. name }
338
+ />
339
+ </ div >
340
+ </ Modal >
331
341
</ div >
332
342
) ;
333
343
}
0 commit comments