Extract form as a separate component

This commit is contained in:
Nikita Karamov 2023-03-27 19:32:53 +02:00
parent 84be267e16
commit 56db514d15
No known key found for this signature in database
GPG Key ID: 41D6F71EE78E77CD
2 changed files with 39 additions and 25 deletions

34
src/components/form.astro Normal file
View File

@ -0,0 +1,34 @@
---
/*!
* © 2023 Nikita Karamov
* Licensed under AGPL v3 or later
*/
import InstanceSelect from "@components/instance-select.astro";
const { prefilledText, prefilledInstance } = Astro.props;
---
<form
id="js-s2f-form"
action="/api/share"
method="POST"
>
<label>
Post text
<textarea
name="text"
id="text"
rows="7"
placeholder="What's on your mind?"
required
>{prefilledText}</textarea
>
</label>
<InstanceSelect {prefilledInstance} />
<input
type="submit"
value="Publish"
/>
</form>

View File

@ -4,7 +4,7 @@
* Licensed under AGPL v3 or later
*/
import Layout from "@layouts/layout.astro";
import InstanceSelect from "@components/instance-select.astro";
import Form from "@components/form.astro";
import { Content as PrivacyNotice } from "@pages/_privacy.md";
import { Content as Licence } from "@pages/_licence.md";
@ -23,30 +23,10 @@ const prefilledInstance = searchParameters.get("instance");
/>
</header>
<main>
<form
id="js-s2f-form"
action="/api/share"
method="POST"
>
<label>
Post text
<textarea
name="text"
id="text"
rows="7"
placeholder="What's on your mind?"
required
>{prefilledText}</textarea
>
</label>
<InstanceSelect prefilledInstance={prefilledInstance} />
<input
type="submit"
value="Publish"
/>
</form>
<Form
{prefilledText}
{prefilledInstance}
/>
</main>
<aside>
<p>