mirror of
https://github.com/jcreek/LivingDexTracker.git
synced 2026-07-15 20:13:45 +00:00
fix(#64): Address PR comments
This commit is contained in:
@@ -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
|
||||
};
|
||||
};
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user