Skip to content

Commit

Permalink
Use fallback item whenever an item is required and cannot be found (#152
Browse files Browse the repository at this point in the history
)
  • Loading branch information
karashiiro authored Jun 30, 2024
1 parent 3a187c2 commit bb04296
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
18 changes: 18 additions & 0 deletions data/game/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,24 @@ export function getItem(id: number, lang: Language): Item | undefined {
return (items[lang] ?? items['en'])[id];
}

export function getFallbackItem(id: number): Item {
return {
id: id,
name: 'Failed to retrieve',
description: '',
iconId: 20000,
levelItem: 1,
levelEquip: 1,
rarity: 1,
itemKind: 7,
stackSize: 9999,
canBeHq: false,
itemSearchCategory: 58,
itemUiCategory: 59,
classJobCategory: 0,
};
}

export function getMateria(id: number, lang: Language): Materia | undefined {
return (materia[lang] ?? materia['en'])[id];
}
4 changes: 2 additions & 2 deletions pages/account/alerts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import React, { useState } from 'react';
import { useSWRConfig } from 'swr';
import AccountLayout from '../../components/AccountLayout/AccountLayout';
import GameIcon from '../../components/GameIcon/GameIcon';
import { getItem, getItemKind, getItemSearchCategory } from '../../data/game';
import { getFallbackItem, getItem, getItemKind, getItemSearchCategory } from '../../data/game';
import useAlerts from '../../hooks/useAlerts';
import useSettings from '../../hooks/useSettings';
import useWorlds from '../../hooks/useWorlds';
Expand Down Expand Up @@ -224,7 +224,7 @@ const Alerts: NextPage = () => {
</h1>
<div className="account-panel">
{[...alertGroups.entries()].map(([itemId, alertGroup]) => {
const item = getItem(itemId, lang)!;
const item = getItem(itemId, lang) ?? getFallbackItem(itemId);
return (
<div key={itemId}>
<div className={styles.alertPanel}>
Expand Down
6 changes: 4 additions & 2 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { UserList } from '../types/universalis/user';
import HomeUserList from '../components/Home/HomeUserList/HomeUserList';
import { useState } from 'react';
import { Trans } from '@lingui/macro';
import { getItem } from '../data/game';
import { getFallbackItem, getItem } from '../data/game';
import useSettings from '../hooks/useSettings';
import { getServers } from '../service/servers';
import { TaxRates } from '../types/universalis/TaxRates';
Expand Down Expand Up @@ -185,7 +185,9 @@ const Home: NextPage = () => {
<h4>
<Trans>Recent Updates</Trans>
</h4>
<RecentUpdatesPanel items={(recent ?? []).map((itemId) => getItem(itemId, lang)!)} />
<RecentUpdatesPanel
items={(recent ?? []).map((itemId) => getItem(itemId, lang) ?? getFallbackItem(itemId))}
/>
<TaxRatesPanel data={taxes ?? zeroTaxRates()} world={world} />
<WorldUploadCountsPanel data={worldUploads ?? []} world={world} />
<UploadCountPanel
Expand Down
4 changes: 2 additions & 2 deletions pages/market/[itemId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,9 @@ const Market: NextPage<MarketProps> = ({
// but for this part of the UI we're not bound to that decision.
const [dynamicServer, setDynamicServer] = useState<Server | null>(null);

const item = getItem(itemId, lang)!;
const item = getItem(itemId, lang);

const title = `${item.name ?? ''} - Universalis`;
const title = `${item?.name ?? ''} - Universalis`;
const description =
'Final Fantasy XIV Online: Market Board aggregator. Find Prices, track Item History and create Price Alerts. Anywhere, anytime.';

Expand Down

0 comments on commit bb04296

Please sign in to comment.