Files
csgowtf/src/routes/matches/+page.ts
vikingowl 05e6182bcf fix: Fix Svelte 5 reactivity issues in matches page and update API handling
- Fix toast notification imports: change from showToast to toast.success/error
- Remove hover preloading from app.html and Tabs component
- Fix match rounds API handling with safe parsing for incomplete data
- Fix pagination timestamp calculation (API returns Unix timestamp, not ISO string)
- Refactor matches page state management to fix reactivity issues:
  - Replace separate state variables with single matchesState object
  - Completely replace state object on updates to trigger reactivity
  - Fix infinite loop in intersection observer effect
  - Add keyed each blocks for proper list rendering
- Remove client-side filtering (temporarily) to isolate reactivity issues
- Add error state handling with nextPageTime in matches loader

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-12 23:11:50 +01:00

53 lines
1.3 KiB
TypeScript

import type { PageLoad } from './$types';
import { api } from '$lib/api';
/**
* Matches listing page data loader
*/
export const load: PageLoad = async ({ url }) => {
// Get query parameters
const map = url.searchParams.get('map') || undefined;
const playerId = url.searchParams.get('player_id') || undefined;
const limit = Number(url.searchParams.get('limit')) || 20; // Request 20 matches for initial load
try {
// Load matches with filters
const matchesData = await api.matches.getMatches({
limit,
map,
player_id: playerId
});
return {
matches: matchesData.matches,
hasMore: matchesData.has_more,
nextPageTime: matchesData.next_page_time,
filters: {
map,
playerId
},
meta: {
title: 'Browse Matches - CS2.WTF',
description: 'Browse and search through CS2 matchmaking games with detailed filters.'
}
};
} catch (error) {
console.error(
'Failed to load matches:',
error instanceof Error ? error.message : String(error)
);
// Return empty state on error
return {
matches: [],
hasMore: false,
nextPageTime: undefined,
filters: { map, playerId },
meta: {
title: 'Browse Matches - CS2.WTF',
description: 'Browse and search through CS2 matchmaking games with detailed filters.'
}
};
}
};