mirror of
https://github.com/emailerfacu-spec/minix-front.git
synced 2026-04-17 15:47:31 -03:00
movi la logica de traer los posts al componente
This commit is contained in:
@@ -2,12 +2,29 @@
|
|||||||
import Card from '@/components/ui/card/card.svelte';
|
import Card from '@/components/ui/card/card.svelte';
|
||||||
import type { Post } from '../types';
|
import type { Post } from '../types';
|
||||||
import { Content } from '@/components/ui/card';
|
import { Content } from '@/components/ui/card';
|
||||||
|
import { apiBase } from '@/stores/url';
|
||||||
|
|
||||||
interface Props {
|
$effect(async()=>{
|
||||||
posts: Post[];
|
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>
|
</script>
|
||||||
|
|
||||||
<div class="flex min-h-fit w-full items-center justify-center p-6 md:p-10">
|
<div class="flex min-h-fit w-full items-center justify-center p-6 md:p-10">
|
||||||
|
|||||||
@@ -1,16 +1 @@
|
|||||||
import { apiBase } from '@/stores/url';
|
|
||||||
|
|
||||||
export const ssr = true;
|
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: [] };
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user