|
37 | 37 | } |
38 | 38 |
|
39 | 39 | const ownedCollections = computed<Record<number, number[]>>(() => { |
40 | | - if (!users || !users[0] || !users[0].data.items) |
41 | | - return { 1: [], 2: [], 3: [], 9: [], 10: [], 11: [] }; |
42 | | -
|
43 | 40 | const owned: Record<number, number[]> = { 1: [], 2: [], 3: [], 9: [], 10: [], 11: [] }; |
44 | | - for (const collection of users[0].data.items[1]) owned[1].push(collection.itemId); |
45 | | - for (const collection of users[0].data.items[2]) owned[2].push(collection.itemId); |
46 | | - for (const collection of users[0].data.items[3]) owned[3].push(collection.itemId); |
47 | | - if (users[0].data.items[9]) { |
48 | | - for (const collection of users[0].data.items[9]) owned[9].push(collection.itemId); |
49 | | - } |
50 | | - if (users[0].data.items[10]) { |
51 | | - for (const collection of users[0].data.items[10]) owned[10].push(collection.itemId); |
52 | | - } |
53 | | - if (users[0].data.items[11]) { |
54 | | - for (const collection of users[0].data.items[11]) owned[11].push(collection.itemId); |
55 | | - } |
| 41 | + const items = users?.[0]?.data?.items; |
| 42 | + const getItemsByKind = (kind: CollectionKind) => |
| 43 | + Array.isArray(items?.[kind]) ? items[kind] : []; |
| 44 | +
|
| 45 | + for (const collection of getItemsByKind(CollectionKind.Plate)) |
| 46 | + owned[CollectionKind.Plate].push(collection.itemId); |
| 47 | + for (const collection of getItemsByKind(CollectionKind.Title)) |
| 48 | + owned[CollectionKind.Title].push(collection.itemId); |
| 49 | + for (const collection of getItemsByKind(CollectionKind.Icon)) |
| 50 | + owned[CollectionKind.Icon].push(collection.itemId); |
| 51 | + for (const collection of getItemsByKind(CollectionKind.Character)) |
| 52 | + owned[CollectionKind.Character].push(collection.itemId); |
| 53 | + for (const collection of getItemsByKind(CollectionKind.Partner)) |
| 54 | + owned[CollectionKind.Partner].push(collection.itemId); |
| 55 | + for (const collection of getItemsByKind(CollectionKind.Frame)) |
| 56 | + owned[CollectionKind.Frame].push(collection.itemId); |
56 | 57 |
|
57 | 58 | return owned; |
58 | 59 | }); |
|
0 commit comments