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 { 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-08-05 14:38:44 +02:00
|
|
|
import type { ActionData, PageServerData } from "./$types";
|
2024-09-07 14:28:23 +02:00
|
|
|
import LoadingSpinner from "$lib/components/LoadingSpinner.svelte";
|
2024-09-27 16:59:29 +02:00
|
|
|
import { enhanceForm } from "$lib/utils";
|
|
|
|
|
import { sending } from "$lib/runes.svelte";
|
2024-07-31 10:29:46 +02:00
|
|
|
|
2024-08-20 19:17:05 +02:00
|
|
|
const { form, data }: { form: ActionData; data: PageServerData } = $props();
|
2024-07-31 10:29:46 +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
|
|
|
|
2024-09-27 16:59:29 +02:00
|
|
|
{#if sending.value}
|
2024-09-07 14:28:23 +02:00
|
|
|
<LoadingSpinner />
|
|
|
|
|
{/if}
|
|
|
|
|
|
2024-08-24 21:43:15 +02:00
|
|
|
<section id="create-website">
|
|
|
|
|
<h2>
|
|
|
|
|
<a href="#create-website">Create website</a>
|
|
|
|
|
</h2>
|
2024-07-31 10:29:46 +02:00
|
|
|
|
2024-08-02 15:33:18 +02:00
|
|
|
<Modal id="create-website" text="Create website">
|
|
|
|
|
<h3>Create website</h3>
|
|
|
|
|
|
2024-09-27 16:59:29 +02:00
|
|
|
<form method="POST" action="?/createWebsite" use:enhance={enhanceForm({ closeModal: true })}>
|
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:
|
2024-08-05 16:03:07 +02:00
|
|
|
<input type="text" name="title" maxlength="50" pattern="\S(.*\S)?" required />
|
2024-08-02 15:33:18 +02:00
|
|
|
</label>
|
|
|
|
|
|
2024-10-25 19:23:38 +02:00
|
|
|
<button type="submit">Create website</button>
|
2024-08-02 15:33:18 +02:00
|
|
|
</form>
|
|
|
|
|
</Modal>
|
2024-07-31 10:29:46 +02:00
|
|
|
</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-07-31 10:29:46 +02:00
|
|
|
|
2024-08-15 18:45:47 +02:00
|
|
|
<details>
|
2024-09-06 16:08:34 +02:00
|
|
|
<summary>Search & Filter</summary>
|
2024-08-15 18:45:47 +02:00
|
|
|
<form method="GET">
|
|
|
|
|
<label>
|
|
|
|
|
Search:
|
2024-10-19 17:55:02 +02:00
|
|
|
<input type="text" name="query" value={$page.url.searchParams.get("query")} />
|
2024-08-15 18:45:47 +02:00
|
|
|
</label>
|
|
|
|
|
<label>
|
|
|
|
|
Filter:
|
2024-10-19 17:55:02 +02:00
|
|
|
<select name="filter">
|
|
|
|
|
<option value="all" selected={"all" === $page.url.searchParams.get("filter")}
|
2024-09-01 16:51:21 +02:00
|
|
|
>Show all</option
|
|
|
|
|
>
|
|
|
|
|
<option
|
|
|
|
|
value="creations"
|
2024-10-19 17:55:02 +02:00
|
|
|
selected={"creations" === $page.url.searchParams.get("filter")}>Created by you</option
|
2024-09-01 16:51:21 +02:00
|
|
|
>
|
2024-10-19 17:55:02 +02:00
|
|
|
<option value="shared" selected={"shared" === $page.url.searchParams.get("filter")}
|
2024-09-01 16:51:21 +02:00
|
|
|
>Shared with you</option
|
|
|
|
|
>
|
2024-08-15 18:45:47 +02:00
|
|
|
</select>
|
|
|
|
|
</label>
|
2024-10-25 19:23:38 +02:00
|
|
|
<button type="submit">Apply</button>
|
2024-08-15 18:45:47 +02:00
|
|
|
</form>
|
|
|
|
|
</details>
|
|
|
|
|
|
2024-08-23 18:43:52 +02:00
|
|
|
<ul class="website-grid unpadded">
|
2024-10-19 17:55:02 +02:00
|
|
|
{#each data.websites as { id, user_id, content_type, title, created_at, collab } (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"
|
2024-09-27 16:59:29 +02:00
|
|
|
use:enhance={enhanceForm({ reset: false, closeModal: true })}
|
2024-08-02 15:33:18 +02:00
|
|
|
>
|
|
|
|
|
<input type="hidden" name="id" value={id} />
|
|
|
|
|
<label>
|
2024-10-25 19:23:38 +02:00
|
|
|
Title:
|
2024-08-05 16:03:07 +02:00
|
|
|
<input
|
|
|
|
|
type="text"
|
|
|
|
|
name="title"
|
|
|
|
|
value={title}
|
|
|
|
|
maxlength="50"
|
|
|
|
|
pattern="\S(.*\S)?"
|
|
|
|
|
required
|
|
|
|
|
/>
|
2024-08-02 15:33:18 +02:00
|
|
|
</label>
|
|
|
|
|
|
2024-10-19 17:55:02 +02:00
|
|
|
<button
|
|
|
|
|
type="submit"
|
|
|
|
|
disabled={data.user.id !== user_id && collab[0].permission_level !== 30}
|
2024-10-25 19:23:38 +02:00
|
|
|
>Update website</button
|
2024-10-19 17:55:02 +02:00
|
|
|
>
|
2024-08-02 15:33:18 +02:00
|
|
|
</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"
|
2024-09-27 16:59:29 +02:00
|
|
|
use:enhance={enhanceForm({ closeModal: true })}
|
2024-08-02 16:36:21 +02:00
|
|
|
>
|
2024-08-02 15:33:18 +02:00
|
|
|
<input type="hidden" name="id" value={id} />
|
|
|
|
|
|
2024-10-19 17:55:02 +02:00
|
|
|
<button type="submit" disabled={data.user.id !== user_id}>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;
|
2024-08-15 16:26:32 +02:00
|
|
|
gap: var(--space-s);
|
2024-09-24 16:06:24 +02:00
|
|
|
grid-template-columns: repeat(auto-fit, minmax(min(100%, 35ch), 0.5fr));
|
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;
|
2024-08-15 16:26:32 +02:00
|
|
|
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;
|
2024-08-15 16:26:32 +02:00
|
|
|
gap: var(--space-2xs);
|
2024-08-02 15:33:18 +02:00
|
|
|
flex-wrap: wrap;
|
|
|
|
|
}
|
|
|
|
|
</style>
|