fix: prefill item names in lootbox pool entries when editing
All checks were successful
Deploy to Production / test (push) Successful in 36s

Resolve ITEM-type pool entry names from the API when loading an
existing lootbox for editing, so the ItemSearchPicker displays
the selected item instead of showing an empty default.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
syntaxbullet
2026-03-26 15:38:11 +01:00
parent 01bb73f6a2
commit 58d07a02fd

View File

@@ -1177,9 +1177,46 @@ export function ItemStudio({
setError(null);
get<FullItem>(`/api/items/${editItemId}`)
.then((item) => {
.then(async (item) => {
if (cancelled) return;
const newDraft = draftFromItem(item);
// Resolve item names for ITEM-type loot pool entries
const itemIdsToResolve = new Set<number>();
for (const eff of newDraft.effects) {
if (eff.kind === "LOOTBOX") {
for (const entry of eff.pool) {
if (entry.type === "ITEM" && entry.itemId) {
itemIdsToResolve.add(Number(entry.itemId));
}
}
}
}
if (itemIdsToResolve.size > 0) {
const resolved = await Promise.all(
[...itemIdsToResolve].map((id) =>
get<{ id: number; name: string; rarity: string }>(`/api/items/${id}`).catch(() => null)
)
);
const itemMap = new Map(
resolved.filter(Boolean).map((i) => [i!.id, i!])
);
for (const eff of newDraft.effects) {
if (eff.kind === "LOOTBOX") {
for (const entry of eff.pool) {
const info = itemMap.get(Number(entry.itemId));
if (info) {
entry.selectedItemName = info.name;
entry.selectedItemRarity = info.rarity;
}
}
}
}
}
if (cancelled) return;
const newIconUrl = item.iconUrl ?? "";
const newImageUrl = item.imageUrl ?? "";
setDraft(newDraft);