Files
archtika/web-app/src/routes/(authenticated)/+page.svelte

202 lines
5.4 KiB
Svelte
Raw Normal View History

<script lang="ts">
import { enhance } from "$app/forms";
import DateTime from "$lib/components/DateTime.svelte";
2024-08-01 18:09:35 +02:00
import { page } from "$app/stores";
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";
import LoadingSpinner from "$lib/components/LoadingSpinner.svelte";
2024-08-20 19:17:05 +02:00
const { form, data }: { form: ActionData; data: PageServerData } = $props();
let sending = $state(false);
</script>
<SuccessOrError success={form?.success} message={form?.message} />
2024-08-01 18:09:35 +02:00
{#if sending}
<LoadingSpinner />
{/if}
2024-08-24 21:43:15 +02:00
<section id="create-website">
<h2>
<a href="#create-website">Create website</a>
</h2>
2024-08-02 15:33:18 +02:00
<Modal id="create-website" text="Create website">
<h3>Create website</h3>
<form
method="POST"
action="?/createWebsite"
use:enhance={() => {
sending = true;
return async ({ update }) => {
await update();
window.location.hash = "!";
sending = false;
};
}}
>
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" maxlength="50" pattern="\S(.*\S)?" required />
2024-08-02 15:33:18 +02:00
</label>
<button type="submit">Submit</button>
</form>
</Modal>
</section>
2024-08-01 18:09:35 +02:00
{#if data.totalWebsiteCount > 0}
2024-08-24 21:43:15 +02:00
<section id="all-websites">
<h2>
<a href="#all-websites">All websites</a>
</h2>
2024-08-15 18:45:47 +02:00
<details>
<summary>Search & Filter</summary>
2024-08-15 18:45:47 +02:00
<form method="GET">
<label>
Search:
<input
type="text"
name="website_search_query"
value={$page.url.searchParams.get("website_search_query")}
/>
</label>
<label>
Filter:
<select name="website_filter">
<option value="all" selected={"all" === $page.url.searchParams.get("website_filter")}
>Show all</option
>
<option
value="creations"
selected={"creations" === $page.url.searchParams.get("website_filter")}
>Created by you</option
>
<option
value="shared"
selected={"shared" === $page.url.searchParams.get("website_filter")}
>Shared with you</option
>
2024-08-15 18:45:47 +02:00
</select>
</label>
<button type="submit">Submit</button>
</form>
</details>
2024-08-23 18:43:52 +02:00
<ul class="website-grid unpadded">
2024-08-03 13:49:41 +02:00
{#each data.websites as { id, content_type, title, created_at } (id)}
2024-08-15 18:45:47 +02:00
<li class="website-card">
<p>
<strong>
<a href="/website/{id}">{title}</a>
</strong>
</p>
2024-08-02 15:33:18 +02:00
<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={() => {
sending = true;
2024-08-02 15:33:18 +02:00
return async ({ update }) => {
await update({ reset: false });
window.location.hash = "!";
sending = false;
2024-08-02 15:33:18 +02:00
};
}}
>
<input type="hidden" name="id" value={id} />
<label>
Title
<input
type="text"
name="title"
value={title}
maxlength="50"
pattern="\S(.*\S)?"
required
/>
2024-08-02 15:33:18 +02:00
</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>
<form
method="POST"
action="?/deleteWebsite"
use:enhance={() => {
sending = true;
return async ({ update }) => {
await update();
window.location.hash = "!";
sending = false;
};
}}
>
2024-08-02 15:33:18 +02:00
<input type="hidden" name="id" value={id} />
<button type="submit">Delete website</button>
2024-08-02 15:33:18 +02:00
</form>
</Modal>
</div>
2024-08-15 18:45:47 +02:00
</li>
2024-08-02 15:33:18 +02:00
{/each}
2024-08-15 18:45:47 +02:00
</ul>
2024-08-01 18:09:35 +02:00
</section>
{/if}
2024-08-02 15:33:18 +02:00
<style>
.website-grid {
display: grid;
gap: var(--space-s);
2024-08-02 15:33:18 +02:00
grid-template-columns: repeat(auto-fit, minmax(min(100%, 35ch), 1fr));
2024-08-15 18:45:47 +02:00
margin-block-start: var(--space-xs);
2024-08-02 15:33:18 +02:00
}
.website-card {
border: var(--border-primary);
display: flex;
flex-direction: column;
gap: var(--space-s);
padding-inline: var(--space-s);
padding-block: var(--space-m);
2024-08-02 15:33:18 +02:00
}
.website-card__actions {
display: flex;
align-items: center;
gap: var(--space-2xs);
2024-08-02 15:33:18 +02:00
flex-wrap: wrap;
}
</style>