movi la logica de traer los posts al componente

This commit is contained in:
2025-11-14 16:35:14 -03:00
parent 50187910b4
commit 543f253db5
2 changed files with 21 additions and 19 deletions

View File

@@ -2,12 +2,29 @@
import Card from '@/components/ui/card/card.svelte';
import type { Post } from '../types';
import { Content } from '@/components/ui/card';
import { apiBase } from '@/stores/url';
interface Props {
posts: Post[];
}
$effect(async()=>{
await getPosts();
});
let posts: Post[] = $state([]);
async function getPosts() {
const { subscribe } = apiBase;
let baseUrl: string = '';
subscribe((value) => {
baseUrl = value;
})();
const req = await fetch(`${baseUrl}/api/posts/timeline?pageSize=3`);
if (req.ok){
posts = await req.json();
}
}
let { posts = [] }: Props = $props();
</script>
<div class="flex min-h-fit w-full items-center justify-center p-6 md:p-10">

View File

@@ -1,16 +1 @@
import { apiBase } from '@/stores/url';
export const ssr = true;
export async function load({}) {
const { subscribe } = apiBase;
let baseUrl: string = '';
subscribe((value) => {
baseUrl = value;
})();
const req = await fetch(`${baseUrl}/Posts`);
if (req.ok) return { posts: req };
else return { posts: [] };
}