From 58e82dd2daed2316e33903257c49ae50929fbe52 Mon Sep 17 00:00:00 2001 From: Juliet Date: Sat, 18 Oct 2025 22:49:49 +0200 Subject: [PATCH] create record new form --- src/components/account.tsx | 3 +- src/components/create.tsx | 116 ++++++++++++++++++++++--------------- 2 files changed, 71 insertions(+), 48 deletions(-) diff --git a/src/components/account.tsx b/src/components/account.tsx index 692a191..1fed9ee 100644 --- a/src/components/account.tsx +++ b/src/components/account.tsx @@ -14,9 +14,10 @@ import { resolveDidDoc } from "../utils/api.js"; import { agent, Login, retrieveSession, Sessions, setAgent } from "./login.jsx"; import { Modal } from "./modal.jsx"; +export const [sessions, setSessions] = createStore(); + export const AccountManager = () => { const [openManager, setOpenManager] = createSignal(false); - const [sessions, setSessions] = createStore(); const [avatars, setAvatars] = createStore>(); onMount(async () => { diff --git a/src/components/create.tsx b/src/components/create.tsx index 142d589..f7de7ca 100644 --- a/src/components/create.tsx +++ b/src/components/create.tsx @@ -1,10 +1,13 @@ import { Client } from "@atcute/client"; +import { Did } from "@atcute/lexicons"; +import { getSession, OAuthUserAgent } from "@atcute/oauth-browser-client"; import { remove } from "@mary/exif-rm"; import { useNavigate, useParams } from "@solidjs/router"; -import { createSignal, onCleanup, onMount, Show } from "solid-js"; +import { createSignal, For, onCleanup, onMount, Show } from "solid-js"; import { Editor, editorView } from "../components/editor.jsx"; import { agent } from "../components/login.jsx"; import { setNotif } from "../layout.jsx"; +import { sessions } from "./account.jsx"; import { Button } from "./button.jsx"; import { Modal } from "./modal.jsx"; import { TextInput } from "./text-input.jsx"; @@ -18,6 +21,7 @@ export const RecordEditor = (props: { create: boolean; record?: any; refetch?: a const [openDialog, setOpenDialog] = createSignal(false); const [notice, setNotice] = createSignal(""); const [openUpload, setOpenUpload] = createSignal(false); + const [validate, setValidate] = createSignal(undefined); let blobInput!: HTMLInputElement; let formRef!: HTMLFormElement; @@ -38,11 +42,28 @@ export const RecordEditor = (props: { create: boolean; record?: any; refetch?: a }; }; + const getValidateIcon = () => { + return ( + validate() === true ? "lucide--circle-check" + : validate() === false ? "lucide--circle-x" + : "lucide--circle" + ); + }; + + const getValidateLabel = () => { + return ( + validate() === true ? "True" + : validate() === false ? "False" + : "Unset" + ); + }; + const createRecord = async (formData: FormData) => { - const rpc = new Client({ handler: agent()! }); + const repo = formData.get("repo")?.toString(); + if (!repo) return; + const rpc = new Client({ handler: new OAuthUserAgent(await getSession(repo as Did)) }); const collection = formData.get("collection"); const rkey = formData.get("rkey"); - const validate = formData.get("validate")?.toString(); let record: any; try { record = JSON.parse(editorView.state.doc.toString()); @@ -52,14 +73,11 @@ export const RecordEditor = (props: { create: boolean; record?: any; refetch?: a } const res = await rpc.post("com.atproto.repo.createRecord", { input: { - repo: agent()!.sub, + repo: repo as Did, collection: collection ? collection.toString() : record.$type, rkey: rkey?.toString().length ? rkey?.toString() : undefined, record: record, - validate: - validate === "true" ? true - : validate === "false" ? false - : undefined, + validate: validate(), }, }); if (!res.ok) { @@ -71,12 +89,8 @@ export const RecordEditor = (props: { create: boolean; record?: any; refetch?: a navigate(`/${res.data.uri}`); }; - const editRecord = async (formData: FormData, recreate?: boolean) => { + const editRecord = async (recreate?: boolean) => { const record = editorView.state.doc.toString(); - const validate = - formData.get("validate")?.toString() === "true" ? true - : formData.get("validate")?.toString() === "false" ? false - : undefined; if (!record) return; const rpc = new Client({ handler: agent()! }); try { @@ -85,7 +99,7 @@ export const RecordEditor = (props: { create: boolean; record?: any; refetch?: a const res = await rpc.post("com.atproto.repo.applyWrites", { input: { repo: agent()!.sub, - validate: validate, + validate: validate(), writes: [ { collection: params.collection as `${string}.${string}.${string}`, @@ -112,7 +126,7 @@ export const RecordEditor = (props: { create: boolean; record?: any; refetch?: a collection: params.collection as `${string}.${string}.${string}`, rkey: params.rkey, record: editedRecord, - validate: validate, + validate: validate(), }, }); if (!res.ok) { @@ -326,43 +340,55 @@ export const RecordEditor = (props: { create: boolean; record?: any; refetch?: a
- -
- +
+ + at:// + + / -
-
- + / -
- -
- - + + + + Validate +
- +