2024-08-01 18:09:35 +02:00
|
|
|
<script lang="ts">
|
|
|
|
|
import WebsiteEditor from "$lib/components/WebsiteEditor.svelte";
|
|
|
|
|
import { sortOptions } from "$lib/utils.js";
|
|
|
|
|
import { page } from "$app/stores";
|
|
|
|
|
import { enhance } from "$app/forms";
|
2024-08-02 15:33:18 +02:00
|
|
|
import Modal from "$lib/components/Modal.svelte";
|
2024-08-02 16:36:21 +02:00
|
|
|
import SuccessOrError from "$lib/components/SuccessOrError.svelte";
|
2024-08-05 14:38:44 +02:00
|
|
|
import type { ActionData, PageServerData } from "./$types";
|
2024-08-01 18:09:35 +02:00
|
|
|
|
2024-08-05 14:38:44 +02:00
|
|
|
const { data, form } = $props<{ data: PageServerData; form: ActionData }>();
|
2024-08-01 18:09:35 +02:00
|
|
|
</script>
|
|
|
|
|
|
2024-08-02 16:36:21 +02:00
|
|
|
<SuccessOrError success={form?.success} message={form?.message} />
|
2024-08-01 18:09:35 +02:00
|
|
|
|
|
|
|
|
<WebsiteEditor
|
|
|
|
|
id={data.website.id}
|
|
|
|
|
title={data.website.title}
|
|
|
|
|
previewContent={data.home.main_content}
|
|
|
|
|
>
|
|
|
|
|
<section>
|
|
|
|
|
<h2>Create article</h2>
|
|
|
|
|
|
2024-08-02 15:33:18 +02:00
|
|
|
<Modal id="create-article" text="Create article">
|
|
|
|
|
<h3>Create article</h3>
|
2024-08-01 18:09:35 +02:00
|
|
|
|
2024-08-02 16:36:21 +02:00
|
|
|
<form
|
|
|
|
|
method="POST"
|
|
|
|
|
action="?/createArticle"
|
|
|
|
|
use:enhance={() => {
|
|
|
|
|
return async ({ update }) => {
|
|
|
|
|
await update();
|
|
|
|
|
window.location.hash = "!";
|
|
|
|
|
};
|
|
|
|
|
}}
|
|
|
|
|
>
|
2024-08-02 15:33:18 +02:00
|
|
|
<label>
|
|
|
|
|
Title:
|
2024-08-05 16:03:07 +02:00
|
|
|
<input type="text" name="title" pattern="\S(.*\S)?" maxlength="100" required />
|
2024-08-02 15:33:18 +02:00
|
|
|
</label>
|
|
|
|
|
|
|
|
|
|
<button type="submit">Submit</button>
|
|
|
|
|
</form>
|
|
|
|
|
</Modal>
|
2024-08-01 18:09:35 +02:00
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
{#if data.totalArticleCount > 0}
|
|
|
|
|
<section>
|
|
|
|
|
<h2>All articles</h2>
|
|
|
|
|
|
|
|
|
|
<form method="GET">
|
|
|
|
|
<label>
|
|
|
|
|
Search:
|
|
|
|
|
<input
|
|
|
|
|
type="text"
|
|
|
|
|
name="article_search_query"
|
|
|
|
|
value={$page.url.searchParams.get("article_search_query")}
|
|
|
|
|
/>
|
|
|
|
|
</label>
|
|
|
|
|
<label>
|
|
|
|
|
Sort:
|
|
|
|
|
<select name="article_sort">
|
|
|
|
|
{#each sortOptions as { value, text }}
|
|
|
|
|
<option {value} selected={value === $page.url.searchParams.get("article_sort")}
|
|
|
|
|
>{text}</option
|
|
|
|
|
>
|
|
|
|
|
{/each}
|
|
|
|
|
</select>
|
|
|
|
|
</label>
|
|
|
|
|
<button type="submit">Submit</button>
|
|
|
|
|
</form>
|
|
|
|
|
|
2024-08-03 13:49:41 +02:00
|
|
|
{#each data.articles as { id, title } (id)}
|
2024-08-02 15:33:18 +02:00
|
|
|
<article class="article-card">
|
2024-08-01 18:09:35 +02:00
|
|
|
<h3>{title}</h3>
|
2024-08-02 15:33:18 +02:00
|
|
|
|
|
|
|
|
<div class="article-card__actions">
|
|
|
|
|
<a href="/website/{data.website.id}/articles/{id}">Edit</a>
|
|
|
|
|
<Modal id="delete-article-{id}" text="Delete">
|
|
|
|
|
<h4>Delete article</h4>
|
|
|
|
|
|
|
|
|
|
<p>
|
|
|
|
|
<strong>Caution!</strong>
|
|
|
|
|
Deleting this article will irretrievably erase all data.
|
|
|
|
|
</p>
|
|
|
|
|
|
2024-08-02 16:36:21 +02:00
|
|
|
<form
|
|
|
|
|
method="POST"
|
|
|
|
|
action="?/deleteArticle"
|
|
|
|
|
use:enhance={() => {
|
|
|
|
|
return async ({ update }) => {
|
|
|
|
|
await update();
|
|
|
|
|
window.location.hash = "!";
|
|
|
|
|
};
|
|
|
|
|
}}
|
|
|
|
|
>
|
2024-08-02 15:33:18 +02:00
|
|
|
<input type="hidden" name="id" value={id} />
|
|
|
|
|
|
2024-08-03 18:07:27 +02:00
|
|
|
<button type="submit">Delete article</button>
|
2024-08-02 15:33:18 +02:00
|
|
|
</form>
|
|
|
|
|
</Modal>
|
|
|
|
|
</div>
|
2024-08-01 18:09:35 +02:00
|
|
|
</article>
|
|
|
|
|
{/each}
|
|
|
|
|
</section>
|
|
|
|
|
{/if}
|
|
|
|
|
</WebsiteEditor>
|
2024-08-02 15:33:18 +02:00
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|
.article-card {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
column-gap: 2rem;
|
|
|
|
|
row-gap: 0.5rem;
|
|
|
|
|
flex-wrap: wrap;
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.article-card:nth-of-type(1) {
|
|
|
|
|
margin-block-start: 1rem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.article-card__actions {
|
|
|
|
|
display: flex;
|
|
|
|
|
gap: 1rem;
|
|
|
|
|
align-items: center;
|
|
|
|
|
}
|
|
|
|
|
</style>
|