Files
archtika/web-app/src/routes/(authenticated)/website/[websiteId]/articles/+page.svelte

161 lines
4.6 KiB
Svelte
Raw Normal View History

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";
import SuccessOrError from "$lib/components/SuccessOrError.svelte";
import type { ActionData, PageServerData } from "./$types";
2024-08-01 18:09:35 +02:00
2024-08-20 19:17:05 +02:00
const { data, form }: { data: PageServerData; form: ActionData } = $props();
2024-08-01 18:09:35 +02:00
</script>
<SuccessOrError success={form?.success} message={form?.message} />
2024-08-01 18:09:35 +02:00
<WebsiteEditor
id={data.website.id}
2024-08-27 16:39:29 +02:00
contentType={data.website.content_type}
2024-08-01 18:09:35 +02:00
title={data.website.title}
previewContent={data.home.main_content}
>
2024-08-24 21:43:15 +02:00
<section id="create-article">
<h2>
<a href="#create-article">Create article</a>
</h2>
2024-08-01 18:09:35 +02:00
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
<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:
<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}
2024-08-24 21:43:15 +02:00
<section id="all-articles">
<h2>
<a href="#all-articles">All articles</a>
</h2>
2024-08-01 18:09:35 +02:00
2024-08-15 18:45:47 +02:00
<details>
2024-08-29 12:05:02 +02:00
<summary>Search & Filter</summary>
2024-08-15 18:45:47 +02:00
<form method="GET">
<label>
Search:
<input
type="text"
name="article_search_query"
value={$page.url.searchParams.get("article_search_query")}
/>
</label>
<label>
Filter:
<select name="article_filter">
<option value="all">Show all</option>
<option value="creations">Created by you</option>
<option value="shared">Created by others</option>
</select>
</label>
<button type="submit">Submit</button>
</form>
</details>
2024-08-23 18:43:52 +02:00
<ul class="unpadded">
2024-08-28 19:39:22 +02:00
{#each data.articles as { id, title, docs_category } (id)}
2024-08-15 18:45:47 +02:00
<li class="article-card">
<p>
<strong>{title}</strong>
2024-08-28 19:39:22 +02:00
{#if docs_category?.category_name}
<br />
<small>
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 16 16"
fill="currentColor"
width="16"
height="16"
style="vertical-align: middle"
>
<path
fill-rule="evenodd"
d="M4.5 2A2.5 2.5 0 0 0 2 4.5v2.879a2.5 2.5 0 0 0 .732 1.767l4.5 4.5a2.5 2.5 0 0 0 3.536 0l2.878-2.878a2.5 2.5 0 0 0 0-3.536l-4.5-4.5A2.5 2.5 0 0 0 7.38 2H4.5ZM5 6a1 1 0 1 0 0-2 1 1 0 0 0 0 2Z"
clip-rule="evenodd"
></path>
</svg>
{docs_category.category_name}
</small>
{/if}
2024-08-15 18:45:47 +02:00
</p>
<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>
<form
method="POST"
action="?/deleteArticle"
use:enhance={() => {
return async ({ update }) => {
await update();
window.location.hash = "!";
};
}}
>
<input type="hidden" name="id" value={id} />
<button type="submit">Delete article</button>
</form>
</Modal>
</div>
</li>
{/each}
</ul>
2024-08-01 18:09:35 +02:00
</section>
{/if}
</WebsiteEditor>
2024-08-02 15:33:18 +02:00
<style>
.article-card {
display: flex;
align-items: center;
column-gap: var(--space-s);
row-gap: var(--space-2xs);
2024-08-02 15:33:18 +02:00
flex-wrap: wrap;
justify-content: space-between;
2024-08-15 18:45:47 +02:00
margin-block-start: var(--space-xs);
2024-08-02 15:33:18 +02:00
}
.article-card + .article-card {
2024-08-15 18:45:47 +02:00
padding-block-start: var(--space-xs);
border-block-start: var(--border-primary);
}
2024-08-02 15:33:18 +02:00
.article-card__actions {
display: flex;
gap: var(--space-s);
2024-08-02 15:33:18 +02:00
align-items: center;
}
</style>