Init commit from initial prompt

This commit is contained in:
2025-08-17 12:21:15 +01:00
commit caee8e27f2
21 changed files with 3114 additions and 0 deletions

30
src/lib/api.ts Normal file
View File

@@ -0,0 +1,30 @@
import axios from 'axios';
import type { CardsResponse } from '@/types/pokemon';
const BASE = 'https://api.pokemontcg.io/v2';
export type FetchCardsParams = {
q?: string;
page?: number;
pageSize?: number;
};
export async function fetchMagikarpCards(params: FetchCardsParams = {}): Promise<CardsResponse> {
const { q, page = 1, pageSize = 50 } = params;
// Keep query minimal to avoid parser errors on API side
const parts = [
'name:magikarp',
];
if (q) parts.push(q);
const url = `${BASE}/cards`;
const headers: Record<string, string> = {};
const apiKey = process.env.POKEMON_TCG_API_KEY || process.env.NEXT_PUBLIC_POKEMON_TCG_API_KEY;
if (apiKey) headers['X-Api-Key'] = apiKey;
const { data } = await axios.get<CardsResponse>(url, {
params: { q: parts.join(' '), page, pageSize },
headers,
});
return data;
}

22
src/lib/checklist.ts Normal file
View File

@@ -0,0 +1,22 @@
export const CHECKLIST_KEY = 'magikarp-checklist-v1';
export function loadChecklist(): Set<string> {
if (typeof window === 'undefined') return new Set();
try {
const raw = localStorage.getItem(CHECKLIST_KEY);
if (!raw) return new Set();
const arr = JSON.parse(raw) as string[];
return new Set(arr);
} catch {
return new Set();
}
}
export function saveChecklist(set: Set<string>) {
if (typeof window === 'undefined') return;
try {
localStorage.setItem(CHECKLIST_KEY, JSON.stringify(Array.from(set)));
} catch {
// ignore
}
}