feat: use new db site, cache requests to avoid repeated unneeded fetch calls

This commit is contained in:
2026-06-18 23:20:12 -03:00
parent 9f5b8cd1fa
commit 6a064d295e
8 changed files with 64 additions and 35 deletions
+6 -7
View File
@@ -7,6 +7,7 @@ import shared from '../../styles/shared.module.css';
import styles from '../../styles/Items.module.css';
import { Item, Offering } from './types';
import { fetchItems, fetchOfferings } from '../../lib/db';
import ItemGrid from './ItemGrid';
import OfferingGrid from './OfferingGrid';
@@ -23,13 +24,11 @@ export default function ItemsPage() {
const [randMax, setRandMax] = useState(200);
useEffect(() => {
Promise.all([
fetch('/data/items.json').then(r => r.json()).catch(() => []),
fetch('/data/offerings.json').then(r => r.json()).catch(() => []),
]).then(([i, o]) => {
setItems(i);
setOfferings(o);
});
Promise.all([fetchItems(), fetchOfferings()])
.then(([i, o]) => {
setItems(i);
setOfferings(o);
});
}, []);
const handleClearAll = () => {
+4 -2
View File
@@ -1,3 +1,5 @@
import { DB_BASE_URL } from '../../lib/db';
export type Item = {
id: string;
name: string;
@@ -31,12 +33,12 @@ export const getItemType = (id: string): ItemType => {
export const getItemIconUrl = (iconFilePath: string) => {
const file = (iconFilePath.split('/').pop() ?? '').split('.')[0];
return `/icons/item-icons/${file}.png`;
return `${DB_BASE_URL}/icons/item-icons/${file}.png`;
};
export const getOfferingIconUrl = (iconFilePath: string) => {
const file = (iconFilePath.split('/').pop() ?? '').split('.')[0];
return `/icons/offering-icons/${file}.png`;
return `${DB_BASE_URL}/icons/offering-icons/${file}.png`;
};
export const randInRange = (min: number, max: number) => {