From 07e724cb19a506366ab4c6b7bbf182f03b2d08aa Mon Sep 17 00:00:00 2001 From: oppiliappan Date: Fri, 24 Jul 2026 15:10:19 +0100 Subject: [PATCH] web/routes: refactor string form into its own component Signed-off-by: oppiliappan --- .../lib/components/strings/StringForm.svelte | 134 ++++++++++++++++++ web/src/routes/strings/new/+page.svelte | 123 +++------------- 2 files changed, 155 insertions(+), 102 deletions(-) create mode 100644 web/src/lib/components/strings/StringForm.svelte 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 @@ + + + + +
+
+
+
+ + +
+ + +
+ +
+
+ {lineCount} line{lineCount !== 1 ? "s" : ""} + · + {byteCount} byte{byteCount !== 1 ? "s" : ""} +
+ +
+ {#if mode === "edit"} + + {/if} + +
+
+ + {#if error} +
+ +
+ {/if} +
+
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.

-
-
-
-
- - -
- - -
- -
-
- {lineCount} line{lineCount !== 1 ? "s" : ""} - · - {byteCount} byte{byteCount !== 1 ? "s" : ""} -
- - -
- - {#if error} -
- -
- {/if} -
+
+
-- 2.51.2