diff --git a/src/lib/api.ts b/src/lib/api.ts index 76e9b82..88fcf66 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -70,11 +70,14 @@ function getRecentBounds(category: string) { const today = new Date(); let start = new Date(today); if (category === 'day') { - // include today + // For day, use yesterday since today's data isn't available yet + start = new Date(today.getTime() - 24 * 60 * 60 * 1000); } else if (category === 'week') { - start = new Date(today.getTime() - 7 * 24 * 60 * 60 * 1000); + // For week, use last 8 days (7 + 1 extra day) + start = new Date(today.getTime() - 8 * 24 * 60 * 60 * 1000); } else if (category === 'month') { - start = new Date(today.getTime() - 30 * 24 * 60 * 60 * 1000); + // For month, use last 31 days (30 + 1 extra day) + start = new Date(today.getTime() - 31 * 24 * 60 * 60 * 1000); } return { start }; } diff --git a/src/lib/components/LoadingSpinner.svelte b/src/lib/components/LoadingSpinner.svelte new file mode 100644 index 0000000..5a337df --- /dev/null +++ b/src/lib/components/LoadingSpinner.svelte @@ -0,0 +1,15 @@ + + +
+
+ {#if text} + {text} + {/if} +
diff --git a/src/routes/+page.server.ts b/src/routes/+page.server.ts index c7d347d..404c5a6 100644 --- a/src/routes/+page.server.ts +++ b/src/routes/+page.server.ts @@ -2,22 +2,13 @@ import { getPackageCount, getPopularPackages } from '$lib/api.js'; import type { PageServerLoad } from './$types'; export const load: PageServerLoad = async () => { - try { - // Count distinct packages that have any saved data in DB (recent/month as proxy) - const [packageCount, popular] = await Promise.all([ - getPackageCount(), - getPopularPackages(10, 30) - ]); - return { - packageCount, - popular - }; - } catch (error) { - console.error('Error loading page data:', error); - return { - packageCount: 0, - popular: [] - }; - } + // Return promises directly for streaming - SvelteKit will handle the streaming + const packageCountP = getPackageCount(); + const popularP = getPopularPackages(10, 30); + + return { + packageCount: packageCountP, + popular: popularP + }; }; diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 3643266..5bf5f0b 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -1,5 +1,6 @@ @@ -10,7 +11,7 @@
-

Search Packages

+

Search Packages

@@ -20,7 +21,7 @@ name="q" bind:value={searchTerm} placeholder="Enter package name..." - class="flex-1 px-4 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent" + class="flex-1 px-4 py-2 border border-gray-700 bg-gray-900 text-gray-100 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent" required />