Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use fallback item whenever an item is required and cannot be found #152

Merged
merged 1 commit into from
Jun 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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