1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<script>
import { Link, router } from "@inertiajs/svelte";
import Icon from "../../components/Icon.svelte";
let { posts = [] } = $props();
const remove = (id) => confirm("Delete this post?") && router.delete(`/posts/${id}`);
</script>
<svelte:head><title>Posts</title></svelte:head>
<div class="wrap page">
<div class="page-head">
<div>
<span class="eyebrow">Posts</span>
<h1>Your posts</h1>
</div>
<Link href="/posts/create" class="btn btn-primary"><Icon name="plus" />New post</Link>
</div>
<div class="card">
{#if posts.length === 0}
<div class="empty">
<Icon name="doc" />
<p>No posts yet.</p>
<Link href="/posts/create" class="btn btn-primary btn-sm">Write your first post</Link>
</div>
{:else}
<ul class="rows">
{#each posts as post (post.id)}
<li>
<div class="main"><strong>{post.title}</strong><p>{post.body}</p></div>
<div class="actions">
<Link href="/posts/{post.id}/edit" class="btn btn-sm" aria-label="Edit {post.title}">Edit</Link>
<button type="button" class="btn btn-sm btn-danger" aria-label="Delete {post.title}" onclick={() => remove(post.id)}>Delete</button>
</div>
</li>
{/each}
</ul>
{/if}
</div>
</div>