Migrating to page server data.

This commit is contained in:
Bradley Shellnut 2022-08-25 22:06:39 -07:00
parent 8bc15e74a4
commit b172ac02f4
3 changed files with 11 additions and 6 deletions

View file

@ -1,3 +1,4 @@
import { error } from '@sveltejs/kit';
import type { PageServerLoad } from './$types'
import { boardGameApi } from '../../_api';
@ -16,7 +17,7 @@ export const load: PageServerLoad = async ({ params }: GamePageParams) => {
const response = await boardGameApi('get', `search`, queryParams);
if (response.status === 404) {
return {
games: []
game: []
};
}
@ -24,11 +25,12 @@ export const load: PageServerLoad = async ({ params }: GamePageParams) => {
const gameResponse = await response.json();
// console.log('gameResponse', gameResponse);
// const games = gameResponse?.games;
console.log('game', gameResponse?.games[0]);
console.log('game response', gameResponse?.games[0]);
return {
game: gameResponse?.games[0]
};
}
throw new Error("@migration task: Migrate this return statement (https://github.com/sveltejs/kit/discussions/5774#discussioncomment-3292699)");
throw error(response.status);
// throw new Error("@migration task: Migrate this return statement (https://github.com/sveltejs/kit/discussions/5774#discussioncomment-3292699)");
};

View file

@ -14,10 +14,12 @@
import { collectionStore } from '$lib/stores/collectionStore';
import type { GameType, SavedGameType } from '$lib/types';
import { addToCollection, removeFromCollection } from '$lib/util/manipulateCollection';
import type { PageData } from './$types';
$: existsInCollection = $collectionStore.find((item: SavedGameType) => item.id === game.id);
export let game: GameType;
export const data;
export let data: PageData;
export let game: GameType = data.game;
console.log('page game', game);
let seeMore: boolean = false;
console.log(game?.description?.indexOf('</p>'));
let firstParagraphEnd = 0;

View file

@ -15,8 +15,9 @@
pending_delete: boolean;
};
export let data;
// export let data;
export let todos: Todo[];
console.log('todos', todos);
</script>
<svelte:head>