generated from nhcarrigan/template
fix: add show/hide locked toggle to adventurer panel
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
import type { Adventurer } from "@elysium/types";
|
import type { Adventurer } from "@elysium/types";
|
||||||
|
import { useState } from "react";
|
||||||
import { useGame } from "../../context/GameContext.js";
|
import { useGame } from "../../context/GameContext.js";
|
||||||
|
import { LockToggle } from "../ui/LockToggle.js";
|
||||||
|
|
||||||
const CLASS_ICONS: Record<string, string> = {
|
const CLASS_ICONS: Record<string, string> = {
|
||||||
warrior: "🗡️",
|
warrior: "🗡️",
|
||||||
@@ -48,22 +50,31 @@ const AdventurerCard = ({ adventurer, currentGold }: AdventurerCardProps): React
|
|||||||
|
|
||||||
export const AdventurerPanel = (): React.JSX.Element => {
|
export const AdventurerPanel = (): React.JSX.Element => {
|
||||||
const { state } = useGame();
|
const { state } = useGame();
|
||||||
|
const [showLocked, setShowLocked] = useState(true);
|
||||||
|
|
||||||
if (!state) return <section className="panel"><p>Loading...</p></section>;
|
if (!state) return <section className="panel"><p>Loading...</p></section>;
|
||||||
|
|
||||||
|
const locked = state.adventurers.filter((a) => !a.unlocked);
|
||||||
|
const visible = showLocked ? state.adventurers : state.adventurers.filter((a) => a.unlocked);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section className="panel adventurer-panel">
|
<section className="panel adventurer-panel">
|
||||||
<h2>Adventurers</h2>
|
<div className="panel-header">
|
||||||
|
<h2>Adventurers</h2>
|
||||||
|
<LockToggle
|
||||||
|
lockedCount={locked.length}
|
||||||
|
showLocked={showLocked}
|
||||||
|
onToggle={() => { setShowLocked((v) => !v); }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
<div className="adventurer-list">
|
<div className="adventurer-list">
|
||||||
{state.adventurers
|
{visible.map((adventurer) => (
|
||||||
.filter((a) => a.unlocked)
|
<AdventurerCard
|
||||||
.map((adventurer) => (
|
key={adventurer.id}
|
||||||
<AdventurerCard
|
adventurer={adventurer}
|
||||||
key={adventurer.id}
|
currentGold={state.resources.gold}
|
||||||
adventurer={adventurer}
|
/>
|
||||||
currentGold={state.resources.gold}
|
))}
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user