Skip to content

Commit 57db48e

Browse files
committed
use modal for renaming
1 parent 6f00a6a commit 57db48e

File tree

1 file changed

+58
-48
lines changed
  • apps/onelauncher/frontend/src/routes/app

1 file changed

+58
-48
lines changed

apps/onelauncher/frontend/src/routes/app/index.tsx

Lines changed: 58 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ import type { ClusterModel } from '@/bindings.gen';
22
import DefaultBanner from '@/assets/images/default_banner.png';
33
import DefaultInstancePhoto from '@/assets/images/default_instance_cover.jpg';
44
import { NewClusterCreate } from '@/components/launcher/cluster/ClusterCreation';
5+
import Modal from '@/components/overlay/Modal';
56
import { useRecentCluster } from '@/hooks/useCluster';
67
import { bindings } from '@/main';
78
import { formatAsDuration, upperFirst } from '@/utils';
89
import { useCommand, useCommandMut } from '@onelauncher/common';
910
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';
1112
import { convertFileSrc } from '@tauri-apps/api/core';
1213
import { dataDir, join } from '@tauri-apps/api/path';
1314
import { open } from '@tauri-apps/plugin-dialog';
@@ -167,6 +168,7 @@ function ClusterCard({
167168
id,
168169
mc_loader,
169170
mc_version,
171+
stage,
170172
}: ClusterModel) {
171173
const launch = useCommandMut(() => bindings.core.launchCluster(id, null));
172174
const ref = useRef<HTMLDivElement>(null);
@@ -176,8 +178,7 @@ function ClusterCard({
176178
const cluster = useCommand(`getClusterById-${id}`, () => bindings.core.getClusterById(id));
177179
const [newCover, setNewCover] = useState<string>(cluster.data?.icon_url as string);
178180
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);
181182

182183
const handleLaunch = () => {
183184
launch.mutate();
@@ -248,55 +249,48 @@ function ClusterCard({
248249
}
249250

250251
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"
254259
>
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"
277266
>
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()}
287273
/>
288-
</Show>
289-
<p className="h-4 text-xs">
290-
{mc_loader}
291-
{' '}
292-
{mc_version}
293-
</p>
274+
</div>
294275
</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>
295288

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>
298292
</div>
299-
</div>
293+
</Link>
300294

301295
<ContextMenu
302296
isOpen={isOpen}
@@ -308,14 +302,14 @@ function ClusterCard({
308302
<PlayIcon className="pb-0.5" height={14} width={14} />
309303
</ContextMenu.Item>
310304
<ContextMenu.Separator />
311-
<ContextMenu.Item onAction={() => setEdit(true)}>
305+
<ContextMenu.Item onAction={() => setModalOpen(true)}>
312306
Rename
313307
</ContextMenu.Item>
314308
<ContextMenu.Item onAction={launchFilePicker}>
315309
Change Icon
316310
</ContextMenu.Item>
317311
<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 } }); }}>
319313
Properties
320314
</ContextMenu.Item>
321315
<ContextMenu.Item onAction={openClusterDir}>
@@ -328,6 +322,22 @@ function ClusterCard({
328322
Export
329323
</ContextMenu.Item> */}
330324
</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>
331341
</div>
332342
);
333343
}

0 commit comments

Comments
 (0)