Skip to content

Commit

Permalink
Removed streaming for blogs load
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlin2k committed Oct 28, 2023
1 parent afa3f43 commit f48f385
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 28 deletions.
16 changes: 9 additions & 7 deletions src/routes/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import { redirect, error } from '@sveltejs/kit';
import * as api from '$lib/api';

/** @type {import('./$types').PageServerLoad} */
export const load: PageServerLoad = ({ locals }) => {
const res: Promise<any> = api.get('blogs', locals.token).then((res) => res.json());
export const load: PageServerLoad = async ({ locals }) => {
const res = await api.get('blogs', locals.token);

return {
streamed : {
blogs: res
}
};
if (!res.ok) {
throw error(res.status, 'Failed to load blogs');
}

const body = await res.json();

return { blogs: body.data };
};

/** @type {import('./$types').Actions} */
Expand Down
8 changes: 1 addition & 7 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@

<div class="p-4">
<div class="container m-auto">
{#await data.streamed.blogs}
Loading...
{:then value}
<BlogCardGrid blogs={value.data} />
{:catch error}
Error :(
{/await}
<BlogCardGrid blogs={data.blogs} />
</div>
</div>
16 changes: 9 additions & 7 deletions src/routes/blogs/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import { redirect, error } from '@sveltejs/kit';
import * as api from '$lib/api';

/** @type {import('./$types').PageServerLoad} */
export const load: PageServerLoad = ({ locals }) => {
const res: Promise<any> = api.get('blogs', locals.token).then((res) => res.json());
export const load: PageServerLoad = async ({ locals }) => {
const res = await api.get('blogs', locals.token);

return {
streamed : {
blogs: res
}
};
if (!res.ok) {
throw error(res.status, 'Failed to load blogs');
}

const body = await res.json();

return { blogs: body.data };
};

/** @type {import('./$types').Actions} */
Expand Down
8 changes: 1 addition & 7 deletions src/routes/blogs/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@

<div class="p-4">
<div class="container m-auto">
{#await data.streamed.blogs}
Loading...
{:then value}
<BlogCardGrid blogs={value.data} />
{:catch error}
Error :(
{/await}
<BlogCardGrid blogs={data.blogs} />
</div>
</div>

0 comments on commit f48f385

Please sign in to comment.