2025-09-01 23:05:22 -05:00
|
|
|
import { ExternalLinkIcon, LoopIcon, TrashIcon } from "@radix-ui/react-icons";
|
|
|
|
|
import { Dialog, Flex, IconButton } from "@radix-ui/themes";
|
|
|
|
|
import { useState } from "react";
|
|
|
|
|
import { awaitableProvisionDefinitions } from "../../core/awaitables/provisionDefinitions";
|
|
|
|
|
import { tankToCompareMember } from "../../core/blitzkit/tankToCompareMember";
|
|
|
|
|
import { useLocale } from "../../hooks/useLocale";
|
|
|
|
|
import { CompareEphemeral } from "../../stores/compareEphemeral";
|
|
|
|
|
import { LinkI18n } from "../LinkI18n";
|
|
|
|
|
import { TankSearch } from "../TankSearch";
|
2024-04-04 18:56:51 -05:00
|
|
|
|
|
|
|
|
interface TankControlProps {
|
|
|
|
|
index: number;
|
2025-05-15 23:44:20 -05:00
|
|
|
slug: string;
|
2024-04-04 18:56:51 -05:00
|
|
|
}
|
|
|
|
|
|
2025-08-29 13:42:44 -05:00
|
|
|
const provisionDefinitions = await awaitableProvisionDefinitions;
|
2024-09-23 10:49:54 -05:00
|
|
|
|
2025-05-15 23:44:20 -05:00
|
|
|
export function TankControl({ index, slug }: TankControlProps) {
|
2025-09-18 10:41:42 -05:00
|
|
|
const { locale, strings } = useLocale();
|
2024-04-04 18:56:51 -05:00
|
|
|
const [switchTankDialogOpen, setSwitchTankDialogOpen] = useState(false);
|
|
|
|
|
|
|
|
|
|
return (
|
2025-09-01 23:05:22 -05:00
|
|
|
<Flex gap="3" justify="center" style={{ width: "100%" }}>
|
2024-04-05 13:40:18 -05:00
|
|
|
<IconButton
|
|
|
|
|
variant="ghost"
|
|
|
|
|
onClick={() => {
|
2025-09-01 23:05:22 -05:00
|
|
|
CompareEphemeral.mutate((draft) => {
|
2024-04-05 13:40:18 -05:00
|
|
|
draft.members.splice(index, 1);
|
2024-04-06 18:19:45 -05:00
|
|
|
draft.sorting = undefined;
|
2024-04-05 13:40:18 -05:00
|
|
|
});
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<TrashIcon />
|
|
|
|
|
</IconButton>
|
2024-04-19 09:59:21 -05:00
|
|
|
|
2024-04-05 13:40:18 -05:00
|
|
|
<Dialog.Root
|
|
|
|
|
open={switchTankDialogOpen}
|
|
|
|
|
onOpenChange={setSwitchTankDialogOpen}
|
|
|
|
|
>
|
|
|
|
|
<Dialog.Trigger>
|
|
|
|
|
<IconButton variant="ghost">
|
2024-04-05 17:53:56 -05:00
|
|
|
<LoopIcon />
|
2024-04-04 18:56:51 -05:00
|
|
|
</IconButton>
|
2024-04-05 13:40:18 -05:00
|
|
|
</Dialog.Trigger>
|
|
|
|
|
|
|
|
|
|
<Dialog.Content>
|
2025-09-18 10:41:42 -05:00
|
|
|
<Dialog.Title align="center">
|
|
|
|
|
{strings.website.common.tank_search.swap_dialog_title}
|
|
|
|
|
</Dialog.Title>
|
2024-09-01 21:14:15 -05:00
|
|
|
|
2024-04-05 13:40:18 -05:00
|
|
|
<Flex gap="4" direction="column">
|
|
|
|
|
<Flex
|
|
|
|
|
direction="column"
|
|
|
|
|
gap="4"
|
|
|
|
|
style={{ flex: 1 }}
|
|
|
|
|
justify="center"
|
|
|
|
|
>
|
|
|
|
|
<TankSearch
|
|
|
|
|
compact
|
|
|
|
|
onSelect={(tank) => {
|
2025-09-01 23:05:22 -05:00
|
|
|
CompareEphemeral.mutate((draft) => {
|
2024-04-06 10:17:48 -05:00
|
|
|
draft.members[index] = tankToCompareMember(
|
|
|
|
|
tank,
|
2025-09-01 23:05:22 -05:00
|
|
|
provisionDefinitions
|
2024-04-06 10:17:48 -05:00
|
|
|
);
|
2024-04-06 18:19:45 -05:00
|
|
|
draft.sorting = undefined;
|
2024-04-05 13:40:18 -05:00
|
|
|
});
|
|
|
|
|
setSwitchTankDialogOpen(false);
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</Flex>
|
|
|
|
|
</Flex>
|
|
|
|
|
</Dialog.Content>
|
|
|
|
|
</Dialog.Root>
|
2024-04-19 09:59:21 -05:00
|
|
|
|
2025-05-15 23:44:20 -05:00
|
|
|
<LinkI18n locale={locale} href={`/tanks/${slug}`} target="_blank">
|
2024-04-19 09:59:21 -05:00
|
|
|
<IconButton variant="ghost">
|
|
|
|
|
<ExternalLinkIcon />
|
|
|
|
|
</IconButton>
|
2024-12-27 14:01:59 -06:00
|
|
|
</LinkI18n>
|
2024-04-05 13:40:18 -05:00
|
|
|
</Flex>
|
2024-04-04 18:56:51 -05:00
|
|
|
);
|
|
|
|
|
}
|