Skip to content

Commit

Permalink
Add achievements to dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
darthmaim committed Dec 20, 2024
1 parent e28fd87 commit f5d23de
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
14 changes: 10 additions & 4 deletions apps/web/app/[language]/dashboard/dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ import { encodeColumns, type Column } from './helper';
import { Notice } from '@gw2treasures/ui/components/Notice/Notice';
import { State, EmptyState } from './state';
import { TableWrapper } from '@gw2treasures/ui/components/Table/TableWrapper';
import { AchievementLink } from '@/components/Achievement/AchievementLink';
import { AccountAchievementProgressCell } from '@/components/Achievement/AccountAchievementProgress';

const requiredScopes = [Scope.GW2_Account, Scope.GW2_Characters, Scope.GW2_Inventories, Scope.GW2_Unlocks, Scope.GW2_Tradingpost, Scope.GW2_Wallet];
const requiredScopes = [Scope.GW2_Account, Scope.GW2_Characters, Scope.GW2_Inventories, Scope.GW2_Unlocks, Scope.GW2_Tradingpost, Scope.GW2_Wallet, Scope.GW2_Progression];

export interface DashboardProps {
initialColumns?: Column[]
Expand Down Expand Up @@ -55,11 +57,13 @@ export const Dashboard: FC<DashboardProps> = ({ initialColumns = [] }) => {
<tr>
<th align="left">Account</th>
{columns.map((column) => (
<th key={`${column.type}-${column.id}`} align="right">
<th key={`${column.type}-${column.id}`} align={column.type !== 'achievement' ? 'right' : 'left'}>
{(column.type === 'item' && column.item) ? (
<ItemLink item={column.item}/>
) : (column.type === 'currency' && column.currency) ? (
<CurrencyLink currency={column.currency}/>
) : (column.type === 'achievement' && column.achievement) ? (
<AchievementLink achievement={column.achievement}/>
) : (
<>[{column.type}: {column.id}]</>
)}
Expand Down Expand Up @@ -126,9 +130,11 @@ const AccountRow: FC<AccountRow> = ({ account, columns }) => {
<td><Gw2AccountName account={account}/></td>
{columns.map((column) => column.type === 'item' ? (
<AccountItemCell key={`${column.type}-${column.id}`} account={account} id={column.id}/>
) : (
) : column.type === 'currency' ? (
<AccountCurrencyCell key={`${column.type}-${column.id}`} account={account} id={column.id}/>
))}
) : column.type === 'achievement' ? (
<AccountAchievementProgressCell key={`${column.type}-${column.id}`} accountId={account.id} achievement={column.achievement!}/>
) : <td/>)}
</tr>
);
};
Expand Down
5 changes: 4 additions & 1 deletion apps/web/app/[language]/dashboard/helper.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import type { WithIcon } from '@/lib/with';
import type { Currency, Item } from '@gw2treasures/database';
import type { Achievement, Currency, Item } from '@gw2treasures/database';
import type { LocalizedEntity } from '@/lib/localizedName';
import { isDefined } from '@gw2treasures/helper/is';

const columnTypeMap = {
i: 'item',
c: 'currency',
a: 'achievement',
} as const;

export function encodeColumns(columns: Column[]): string {
Expand Down Expand Up @@ -47,4 +48,6 @@ export type Column = {
type: 'item', item?: WithIcon<Pick<Item, 'id' | 'rarity' | keyof LocalizedEntity>>
} | {
type: 'currency', currency?: WithIcon<Pick<Currency, 'id' | keyof LocalizedEntity>>
} | {
type: 'achievement', achievement?: WithIcon<Pick<Achievement, 'id' | keyof LocalizedEntity | 'flags' | 'prerequisitesIds'>>
});
17 changes: 16 additions & 1 deletion apps/web/app/[language]/dashboard/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ export default async function DashboardPage({ searchParams }: PageProps) {
const columnsByType = groupBy(initialColumns, 'type');

// load data
const [items, currencies] = await Promise.all([
const [items, currencies, achievements] = await Promise.all([
groupById(await loadItems(columnsByType.get('item')?.map(({ id }) => id))),
groupById(await loadCurrencies(columnsByType.get('currency')?.map(({ id }) => id))),
groupById(await loadAchievements(columnsByType.get('achievement')?.map(({ id }) => id))),
]);

// append data to initial columns
Expand All @@ -25,6 +26,9 @@ export default async function DashboardPage({ searchParams }: PageProps) {
case 'currency':
column.currency = currencies.get(column.id);
break;
case 'achievement':
column.achievement = achievements.get(column.id);
break;
}
}

Expand Down Expand Up @@ -55,6 +59,17 @@ function loadCurrencies(ids: number[] | undefined) {
});
}

function loadAchievements(ids: number[] | undefined) {
if(!ids || ids.length === 0) {
return [];
}

return db.achievement.findMany({
where: { id: { in: ids }},
select: { ...linkPropertiesWithoutRarity, flags: true, prerequisitesIds: true }
});
}

export const metadata = {
title: 'Dashboard'
};
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import type { AchievementFlags } from '@gw2api/types/data/achievement';
const requiredScopes = [Scope.GW2_Progression];

export interface RowProps {
achievement: Achievement;
achievement: Pick<Achievement, 'id' | 'flags' | 'prerequisitesIds'>;
bitId?: number;
}
export interface AccountAchievementProgressCellProps {
achievement: Achievement;
achievement: Pick<Achievement, 'id' | 'flags' | 'prerequisitesIds'>;
bitId?: number;
accountId: string;
}
Expand Down

0 comments on commit f5d23de

Please sign in to comment.