fix: prefill item names in lootbox pool entries when editing
All checks were successful
Deploy to Production / test (push) Successful in 36s
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:
@@ -1177,9 +1177,46 @@ export function ItemStudio({
|
|||||||
setError(null);
|
setError(null);
|
||||||
|
|
||||||
get<FullItem>(`/api/items/${editItemId}`)
|
get<FullItem>(`/api/items/${editItemId}`)
|
||||||
.then((item) => {
|
.then(async (item) => {
|
||||||
if (cancelled) return;
|
if (cancelled) return;
|
||||||
const newDraft = draftFromItem(item);
|
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 newIconUrl = item.iconUrl ?? "";
|
||||||
const newImageUrl = item.imageUrl ?? "";
|
const newImageUrl = item.imageUrl ?? "";
|
||||||
setDraft(newDraft);
|
setDraft(newDraft);
|
||||||
|
|||||||
Reference in New Issue
Block a user