This repository has no description
1<script lang="ts">
2 import { goto } from "$app/navigation";
3 import { ok } from "@atcute/client";
4 import { mainSchema as createRecordSchema } from "@atcute/atproto/types/repo/createRecord";
5 import type { Nsid } from "@atcute/lexicons/syntax";
6 import { getAuth } from "$lib/auth.svelte";
7 import { createClient } from "$lib/auth/agent";
8 import { rkeyFromUri } from "$lib/api/uri";
9 import StringForm, { type StringFormData } from "$lib/components/strings/StringForm.svelte";
10
11 const auth = getAuth();
12 const user = $derived(auth.currentUser);
13
14 const handleSubmit = async ({ filename, description, content }: StringFormData) => {
15 if (!auth.agent) return;
16 const rpc = createClient(auth.agent);
17 const result = await ok(
18 rpc.call(createRecordSchema, {
19 input: {
20 repo: auth.agent.sub,
21 collection: "sh.tangled.string" as Nsid,
22 record: {
23 $type: "sh.tangled.string",
24 filename,
25 description,
26 contents: content,
27 createdAt: new Date().toISOString()
28 }
29 }
30 })
31 );
32 const rkey = rkeyFromUri(result.uri);
33 await goto(`/strings/${user?.handle}/${rkey}`);
34 };
35</script>
36
37<svelte:head>
38 <title>New string · Tangled</title>
39</svelte:head>
40
41<div class="mx-auto w-full max-w-screen-lg px-4 py-12">
42 <div class="px-2 py-2">
43 <h1 class="text-xl font-bold text-foreground-default">Create a new string</h1>
44 <p class="text-sm text-foreground-subtle">Store and share code snippets with ease.</p>
45 </div>
46
47 <div class="mt-4">
48 <StringForm mode="create" onsubmit={handleSubmit} />
49 </div>
50</div>