<script>
	import { onMount } from 'svelte';
    import { load_post } from '$lib/js/apicall.js'
	$: isLoaded = false;
    $: hasLoadFailed = false;
    let data;

	onMount(async () => {
        const loaded_post = await load_post();
        if(loaded_post.status == 200)
        {
            data = loaded_post.data;
            isLoaded = true;
        }
        else
            hasLoadFailed = true;
	});
</script>

<div>
	<h1>Etheryo Blog</h1>
	{#if isLoaded}
		{#each data as d}
            <p>id: {d.id}</p>
        {/each}
    {:else if hasLoadFailed}
        <p>Loading failed :c</p>
	{:else}
		<p>Loading...</p>
	{/if}
</div>
