Skip to content

Commit

Permalink
Merge pull request #1963 from GW2Treasures/feature/homestead-nodes-ga…
Browse files Browse the repository at this point in the history
…thered-items

Add gathered items to homestead nodes
  • Loading branch information
darthmaim authored Jan 30, 2025
2 parents 9bf0d09 + d711a48 commit c983cd4
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions apps/web/app/[language]/homestead/nodes/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import type { Metadata } from 'next';
import { getAlternateUrls } from '@/lib/url';
import { Gw2Accounts } from '@/components/Gw2Api/Gw2Accounts';
import { Scope } from '@gw2me/client';
import { isDefined } from '@gw2treasures/helper/is';
import { FlexRow } from '@gw2treasures/ui/components/Layout/FlexRow';

const getItems = cache(
async (ids: number[]) => {
Expand All @@ -37,19 +39,20 @@ const getItems = cache(
);

export default async function HomesteadNodesPage() {
// get item ids that unlock some node
const nodeUnlockItemIds = homeNodes.reduce<number[]>(
(ids, node) => [...ids, ...node.unlock_items],
// collect all the item ids
const itemIds = homeNodes.reduce<number[]>(
(ids, node) => [...ids, ...node.unlock_items, ...(node.gathered_items ?? [])],
[]
);

// get items from db that unlock some node
const unlockItems = await getItems(nodeUnlockItemIds);
const items = await getItems(itemIds);

// add the item to each node
const nodes = homeNodes.map((node) => ({
...node,
item: unlockItems[node.unlock_items[0]]
item: items[node.unlock_items[0]],
gatheredItems: node.gathered_items?.map((id) => items[id]).filter(isDefined)
}));

// create data-table
Expand All @@ -66,6 +69,7 @@ export default async function HomesteadNodesPage() {
<HomeNode.Table>
<HomeNode.Column id="id" title={<Trans id="itemTable.column.id"/>} sortBy="id" small hidden>{({ id }) => id}</HomeNode.Column>
<HomeNode.Column id="node" title="Node" sortBy="name">{({ item, name }) => item ? <ItemLink item={item}/> : name}</HomeNode.Column>
<HomeNode.Column id="gathered" title="Gathered Items">{({ gatheredItems }) => <FlexRow>{gatheredItems?.map((item) => <ItemLink key={item.id} item={item}/>)}</FlexRow>}</HomeNode.Column>
<HomeNode.Column id="buyPrice" title={<Trans id="itemTable.column.buyPrice"/>} sortBy={({ item }) => item.buyPrice} align="right">{({ item }) => itemTableColumn.buyPrice(item, {})}</HomeNode.Column>
<HomeNode.Column id="buyPriceTrend" title={<Trans id="itemTable.column.buyPriceTrend"/>} align="right">{({ item }) => itemTableColumn.buyPriceTrend(item, {})}</HomeNode.Column>
<HomeNode.Column id="buyQuantity" title={<Trans id="itemTable.column.buyQuantity"/>} sortBy={({ item }) => item.buyQuantity} align="right" hidden>{({ item }) => itemTableColumn.buyQuantity(item, {})}</HomeNode.Column>
Expand Down

0 comments on commit c983cd4

Please sign in to comment.