-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
325f0b2
commit 50c03ab
Showing
4 changed files
with
171 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import { useState } from "react"; | ||
import { Button } from "@/components/ui/button"; | ||
import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog"; | ||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; | ||
import { Input } from "@/components/ui/input"; | ||
import type { Jutsu, UserJutsu } from "@/drizzle/schema"; | ||
|
||
interface JutsuTransferModalProps { | ||
isOpen: boolean; | ||
onClose: () => void; | ||
sourceJutsu: Jutsu & UserJutsu; | ||
availableJutsus: (Jutsu & UserJutsu)[]; | ||
maxTransferLevel: number; | ||
usedTransfers: number; | ||
freeTransfers: number; | ||
transferCost: number; | ||
onTransfer: (toJutsuId: string, levels: number) => void; | ||
} | ||
|
||
export function JutsuTransferModal({ | ||
isOpen, | ||
onClose, | ||
sourceJutsu, | ||
availableJutsus, | ||
maxTransferLevel, | ||
usedTransfers, | ||
freeTransfers, | ||
transferCost, | ||
onTransfer, | ||
}: JutsuTransferModalProps) { | ||
const [selectedJutsuId, setSelectedJutsuId] = useState<string>(""); | ||
const [levels, setLevels] = useState<number>(1); | ||
|
||
const selectedJutsu = availableJutsus.find(j => j.jutsuId === selectedJutsuId); | ||
const maxLevels = Math.min(sourceJutsu.level - 1, maxTransferLevel); | ||
|
||
return ( | ||
<Dialog open={isOpen} onOpenChange={onClose}> | ||
<DialogContent> | ||
<DialogHeader> | ||
<DialogTitle>Transfer Level</DialogTitle> | ||
</DialogHeader> | ||
<div className="flex flex-col gap-4"> | ||
<div className="flex flex-col gap-2"> | ||
<label htmlFor="target-jutsu">Target Jutsu:</label> | ||
<Select value={selectedJutsuId} onValueChange={setSelectedJutsuId}> | ||
<SelectTrigger> | ||
<SelectValue placeholder="Select a jutsu..." /> | ||
</SelectTrigger> | ||
<SelectContent> | ||
{availableJutsus | ||
.filter( | ||
j => | ||
j.jutsuId !== sourceJutsu.jutsuId && | ||
j.jutsuType === sourceJutsu.jutsuType && | ||
j.jutsuRank === sourceJutsu.jutsuRank | ||
) | ||
.map(j => ( | ||
<SelectItem key={j.jutsuId} value={j.jutsuId}> | ||
{j.name} (Level {j.level}) | ||
</SelectItem> | ||
))} | ||
</SelectContent> | ||
</Select> | ||
</div> | ||
|
||
{selectedJutsu && ( | ||
<div className="flex flex-col gap-4"> | ||
<div className="flex flex-col gap-2"> | ||
<label htmlFor="transfer-levels">Levels to Transfer:</label> | ||
<Input | ||
id="transfer-levels" | ||
type="number" | ||
min={1} | ||
max={maxLevels} | ||
value={levels} | ||
onChange={e => setLevels(parseInt(e.target.value))} | ||
/> | ||
</div> | ||
|
||
<div className="mt-4"> | ||
<p>Transfer {levels} level(s) from {sourceJutsu.name} to {selectedJutsu.name}?</p> | ||
<p>This will reduce {sourceJutsu.name} to level {sourceJutsu.level - levels} and increase {selectedJutsu.name} to level {selectedJutsu.level + levels}.</p> | ||
</div> | ||
|
||
<p className="mt-2"> | ||
Cost: {usedTransfers >= freeTransfers ? `${transferCost} reputation points` : "Free"} | ||
</p> | ||
|
||
<div className="flex justify-end gap-2 mt-4"> | ||
<Button variant="secondary" onClick={onClose}> | ||
Cancel | ||
</Button> | ||
<Button | ||
onClick={() => { | ||
onTransfer(selectedJutsuId, levels); | ||
onClose(); | ||
}} | ||
> | ||
Confirm Transfer | ||
</Button> | ||
</div> | ||
</div> | ||
)} | ||
</div> | ||
</DialogContent> | ||
</Dialog> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.