2024-07-31 10:29:46 +02:00
|
|
|
<script lang="ts">
|
|
|
|
|
import { enhance } from "$app/forms";
|
|
|
|
|
import DateTime from "$lib/components/DateTime.svelte";
|
2024-08-01 18:09:35 +02:00
|
|
|
import { sortOptions } from "$lib/utils.js";
|
|
|
|
|
import { page } from "$app/stores";
|
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-07-31 10:29:46 +02:00
|
|
|
|
|
|
|
|
const { form, data } = $props();
|
|
|
|
|
</script>
|
|
|
|
|
|
2024-08-02 16:36:21 +02:00
|
|
|
<SuccessOrError success={form?.success} message={form?.message} />
|
2024-08-01 18:09:35 +02:00
|
|
|
|
2024-07-31 10:29:46 +02:00
|
|
|
<section>
|
|
|
|
|
<h2>Create website</h2>
|
|
|
|
|
|
2024-08-02 15:33:18 +02:00
|
|
|
<Modal id="create-website" text="Create website">
|
|
|
|
|
<h3>Create website</h3>
|
|
|
|
|
|
2024-08-02 16:36:21 +02:00
|
|
|
<form
|
|
|
|
|
method="POST"
|
|
|
|
|
action="?/createWebsite"
|
|
|
|
|
use:enhance={() => {
|
|
|
|
|
return async ({ update }) => {
|
|
|
|
|
await update();
|
|
|
|
|
window.location.hash = "!";
|
|
|
|
|
};
|
|
|
|
|
}}
|
|
|
|
|
>
|
2024-08-02 15:33:18 +02:00
|
|
|
<label>
|
|
|
|
|
Type:
|
|
|
|
|
<select name="content-type">
|
|
|
|
|
<option value="Blog">Blog</option>
|
|
|
|
|
<option value="Docs">Docs</option>
|
|
|
|
|
</select>
|
|
|
|
|
</label>
|
|
|
|
|
<label>
|
|
|
|
|
Title:
|
|
|
|
|
<input type="text" name="title" />
|
|
|
|
|
</label>
|
|
|
|
|
|
|
|
|
|
<button type="submit">Submit</button>
|
|
|
|
|
</form>
|
|
|
|
|
</Modal>
|
2024-07-31 10:29:46 +02:00
|
|
|
</section>
|
|
|
|
|
|
2024-08-01 18:09:35 +02:00
|
|
|
{#if data.totalWebsiteCount > 0}
|
|
|
|
|
<section>
|
|
|
|
|
<h2>All websites</h2>
|
2024-07-31 10:29:46 +02:00
|
|
|
|
2024-08-01 18:09:35 +02:00
|
|
|
<form method="GET">
|
|
|
|
|
<label>
|
|
|
|
|
Search:
|
|
|
|
|
<input
|
|
|
|
|
type="text"
|
|
|
|
|
name="website_search_query"
|
|
|
|
|
value={$page.url.searchParams.get("website_search_query")}
|
|
|
|
|
/>
|
|
|
|
|
</label>
|
|
|
|
|
<label>
|
|
|
|
|
Sort:
|
|
|
|
|
<select name="website_sort">
|
|
|
|
|
{#each sortOptions as { value, text }}
|
|
|
|
|
<option {value} selected={value === $page.url.searchParams.get("website_sort")}
|
|
|
|
|
>{text}</option
|
|
|
|
|
>
|
|
|
|
|
{/each}
|
|
|
|
|
</select>
|
|
|
|
|
</label>
|
|
|
|
|
<label>
|
|
|
|
|
Filter:
|
|
|
|
|
<select name="website_filter">
|
|
|
|
|
<option value="all">Show all</option>
|
|
|
|
|
<option value="creations">Created by you</option>
|
|
|
|
|
<option value="shared">Shared with you</option>
|
|
|
|
|
</select>
|
|
|
|
|
</label>
|
|
|
|
|
<button type="submit">Submit</button>
|
|
|
|
|
</form>
|
2024-07-31 10:29:46 +02:00
|
|
|
|
2024-08-02 15:33:18 +02:00
|
|
|
<div class="website-grid">
|
2024-08-03 13:49:41 +02:00
|
|
|
{#each data.websites as { id, content_type, title, created_at } (id)}
|
2024-08-02 15:33:18 +02:00
|
|
|
<article class="website-card">
|
|
|
|
|
<h3>
|
|
|
|
|
<a href="/website/{id}">{title}</a>
|
|
|
|
|
</h3>
|
|
|
|
|
<ul>
|
|
|
|
|
<li>
|
|
|
|
|
<strong>Type:</strong>
|
|
|
|
|
{content_type}
|
|
|
|
|
</li>
|
|
|
|
|
<li>
|
|
|
|
|
<strong>Created at:</strong>
|
|
|
|
|
<DateTime date={created_at} />
|
|
|
|
|
</li>
|
|
|
|
|
</ul>
|
|
|
|
|
<div class="website-card__actions">
|
|
|
|
|
<Modal id="update-website-{id}" text="Update">
|
|
|
|
|
<h4>Update website</h4>
|
|
|
|
|
|
|
|
|
|
<form
|
|
|
|
|
method="POST"
|
|
|
|
|
action="?/updateWebsite"
|
|
|
|
|
use:enhance={() => {
|
|
|
|
|
return async ({ update }) => {
|
|
|
|
|
await update({ reset: false });
|
2024-08-02 16:36:21 +02:00
|
|
|
window.location.hash = "!";
|
2024-08-02 15:33:18 +02:00
|
|
|
};
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<input type="hidden" name="id" value={id} />
|
|
|
|
|
<label>
|
|
|
|
|
Title
|
|
|
|
|
<input type="text" name="title" value={title} />
|
|
|
|
|
</label>
|
|
|
|
|
|
|
|
|
|
<button type="submit">Submit</button>
|
|
|
|
|
</form>
|
|
|
|
|
</Modal>
|
|
|
|
|
<Modal id="delete-website-{id}" text="Delete">
|
|
|
|
|
<h4>Delete website</h4>
|
|
|
|
|
|
|
|
|
|
<p>
|
|
|
|
|
<strong>Caution!</strong>
|
|
|
|
|
Deleting this website will irretrievably erase all data.
|
|
|
|
|
</p>
|
2024-08-02 16:36:21 +02:00
|
|
|
<form
|
|
|
|
|
method="POST"
|
|
|
|
|
action="?/deleteWebsite"
|
|
|
|
|
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 website</button>
|
2024-08-02 15:33:18 +02:00
|
|
|
</form>
|
|
|
|
|
</Modal>
|
|
|
|
|
</div>
|
|
|
|
|
</article>
|
|
|
|
|
{/each}
|
|
|
|
|
</div>
|
2024-08-01 18:09:35 +02:00
|
|
|
</section>
|
|
|
|
|
{/if}
|
2024-08-02 15:33:18 +02:00
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|
.website-grid {
|
|
|
|
|
display: grid;
|
|
|
|
|
gap: 1rem;
|
|
|
|
|
grid-template-columns: repeat(auto-fit, minmax(min(100%, 35ch), 1fr));
|
|
|
|
|
margin-block-start: 1rem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.website-card {
|
|
|
|
|
border: var(--border-primary);
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
gap: 1rem;
|
|
|
|
|
padding-inline: 1rem;
|
|
|
|
|
padding-block: 2rem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.website-card__actions {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
gap: 0.5rem;
|
|
|
|
|
flex-wrap: wrap;
|
|
|
|
|
}
|
|
|
|
|
</style>
|