fix(#64): Address PR comments

This commit is contained in:
Josh Creek
2026-01-10 18:45:57 +00:00
parent f17b350e4e
commit 5657c2b2ab
6 changed files with 164 additions and 192 deletions
+21
View File
@@ -0,0 +1,21 @@
import { redirect } from '@sveltejs/kit';
import PokedexRepository from '$lib/repositories/PokedexRepository';
import type { PageServerLoad } from './$types';
export const load: PageServerLoad = async ({ locals }) => {
const { safeGetSession, supabase } = locals;
const { session, user } = await safeGetSession();
// Require authentication
if (!session || !user) {
throw redirect(303, '/signin');
}
// Fetch pokedexes for the authenticated user
const repo = new PokedexRepository(supabase, user.id);
const pokedexes = await repo.findAll();
return {
pokedexes
};
};
+2 -27
View File
@@ -1,16 +1,11 @@
<script lang="ts">
import { onDestroy, onMount } from 'svelte';
import { goto } from '$app/navigation';
import { user } from '$lib/stores/user';
import type { Pokedex } from '$lib/models/Pokedex';
import PokedexCard from '$lib/components/pokedex/PokedexCard.svelte';
import PokedexForm from '$lib/components/pokedex/PokedexForm.svelte';
let pokedexes: Pokedex[] = [];
const unsubscribe = user.subscribe((value) => {
console.log('[MyPokedexes] User store updated:', value ? 'User found' : 'User null');
});
onDestroy(unsubscribe);
export let data;
let { pokedexes } = data;
let showModal = false;
let editingPokedex: Pokedex | null = null;
let formData: Partial<Pokedex> = {
@@ -25,26 +20,6 @@
$: mode = editingPokedex ? ('edit' as const) : ('create' as const);
onMount(async () => {
// Wait a short time for the user store to be populated (in case of race condition)
// This gives the layout's getUser() time to complete
if (!$user) {
console.log('[MyPokedexes] onMount() - No user yet, waiting 100ms...');
await new Promise((resolve) => setTimeout(resolve, 100));
console.log(
'[MyPokedexes] onMount() - After wait, user store value:',
$user ? 'User found' : 'User null'
);
}
if (!$user) {
goto('/signin');
return;
}
await loadPokedexes();
});
async function loadPokedexes() {
const response = await fetch('/api/pokedexes', { credentials: 'include' });
if (response.ok) {