-
-
Notifications
You must be signed in to change notification settings - Fork 2k
/
Copy path_ArticleMeta.svelte
39 lines (32 loc) · 970 Bytes
/
_ArticleMeta.svelte
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 { goto } from '$app/navigation';
import * as api from '$lib/api.js';
export let article;
export let user;
$: canModify = user && article.author.username === user.username;
async function remove() {
await api.del(`articles/${article.slug}`, user && user.token);
goto('/');
}
</script>
<div class="article-meta">
<a href='/profile/@{article.author.username}'>
<img src={article.author.image} alt={article.author.username} />
</a>
<div class="info">
<a href='/profile/@{article.author.username}' class="author"> {article.author.username}</a>
<span class="date">
{new Date(article.createdAt).toDateString()}
</span>
</div>
{#if canModify}
<span>
<a href='/editor/{article.slug}' class="btn btn-outline-secondary btn-sm">
<i class="ion-edit"/> Edit Article
</a>
<button class="btn btn-outline-danger btn-sm" on:click='{remove}'>
<i class="ion-trash-a"/> Delete Article
</button>
</span>
{/if}
</div>