diff --git a/web/src/lib/components/strings/StringForm.svelte b/web/src/lib/components/strings/StringForm.svelte
new file mode 100644
index 00000000..6888b308
--- /dev/null
+++ b/web/src/lib/components/strings/StringForm.svelte
@@ -0,0 +1,134 @@
+
+
+
+
+
diff --git a/web/src/routes/strings/new/+page.svelte b/web/src/routes/strings/new/+page.svelte
index d543a8b0..09fe05b4 100644
--- a/web/src/routes/strings/new/+page.svelte
+++ b/web/src/routes/strings/new/+page.svelte
@@ -6,52 +6,31 @@
import { getAuth } from "$lib/auth.svelte";
import { createClient } from "$lib/auth/agent";
import { rkeyFromUri } from "$lib/api/uri";
- import Button from "$lib/components/ui/Button.svelte";
- import Spinner from "$lib/components/ui/Spinner.svelte";
- import ErrorAlert from "$lib/components/ui/Error.svelte";
- import ArrowUp from "$icon/arrow-up";
+ import StringForm, { type StringFormData } from "$lib/components/strings/StringForm.svelte";
const auth = getAuth();
const user = $derived(auth.currentUser);
- let filename = $state("");
- let description = $state("");
- let content = $state("");
- let isPublishing = $state(false);
- let error = $state(null);
-
- const lineCount = $derived(content === "" ? 0 : content.split("\n").length);
- const byteCount = $derived(new TextEncoder().encode(content).length);
-
- const handleSubmit = async (e: SubmitEvent) => {
- e.preventDefault();
+ const handleSubmit = async ({ filename, description, content }: StringFormData) => {
if (!auth.agent) return;
- isPublishing = true;
- error = null;
- try {
- const rpc = createClient(auth.agent);
- const result = await ok(
- rpc.call(createRecordSchema, {
- input: {
- repo: auth.agent.sub,
- collection: "sh.tangled.string" as Nsid,
- record: {
- $type: "sh.tangled.string",
- filename,
- description,
- contents: content,
- createdAt: new Date().toISOString()
- }
+ const rpc = createClient(auth.agent);
+ const result = await ok(
+ rpc.call(createRecordSchema, {
+ input: {
+ repo: auth.agent.sub,
+ collection: "sh.tangled.string" as Nsid,
+ record: {
+ $type: "sh.tangled.string",
+ filename,
+ description,
+ contents: content,
+ createdAt: new Date().toISOString()
}
- })
- );
- const rkey = rkeyFromUri(result.uri);
- await goto(`/strings/${user?.handle}/${rkey}`);
- } catch (err) {
- error = err instanceof Error ? err.message : "Failed to publish string";
- } finally {
- isPublishing = false;
- }
+ }
+ })
+ );
+ const rkey = rkeyFromUri(result.uri);
+ await goto(`/strings/${user?.handle}/${rkey}`);
};
@@ -65,67 +44,7 @@
Store and share code snippets with ease.
-
-
+
+