pleroma-like client for Bluesky pl.hexmani.ac
bluesky pleroma social-media
at main 2.0 kB view raw
1import { Component, createSignal } from "solid-js"; 2import { agent } from "./login"; 3import { Client } from "@atcute/client"; 4import * as TID from "@atcute/tid"; 5 6const PostForm: Component = () => { 7 const [notice, setNotice] = createSignal(""); 8 const [text, setText] = createSignal(""); 9 10 async function handleSubmit() { 11 const rpc = new Client({ handler: agent }); 12 const rawText = text(); 13 14 document.querySelector(".submitInfo")?.removeAttribute("hidden"); 15 16 try { 17 const res = await rpc.post("com.atproto.repo.createRecord", { 18 input: { 19 collection: "app.bsky.feed.post", 20 record: { 21 $type: "app.bsky.feed.post", 22 text: rawText, 23 langs: ["en"], 24 createdAt: new Date().toISOString(), 25 }, 26 repo: agent.sub, 27 rkey: TID.now(), 28 }, 29 }); 30 31 if (!res.ok) { 32 throw new Error(`${res.data.error}/${res.data.message}`); 33 } 34 35 console.log(res); 36 setNotice("Post successful"); 37 setTimeout(() => { 38 setNotice(""); 39 document.querySelector(".submitInfo")?.setAttribute("hidden", ""); 40 }, 3000); 41 } catch (e: unknown) { 42 if (e instanceof Error) { 43 setNotice(`Failed to post: ${e.message}`); 44 } else { 45 setNotice(`Failed to post`); 46 } 47 } 48 } 49 50 return ( 51 <> 52 <form 53 autocomplete="off" 54 onclick={(e) => e.preventDefault()} 55 class="post-form" 56 > 57 <textarea 58 id="post-textbox" 59 name="post-textbox" 60 rows="1" 61 cols="1" 62 placeholder="The car's on fire, and there's no driver at the wheel..." 63 onchange={(e) => setText(e.target.value)} 64 ></textarea> 65 <button type="submit" onclick={handleSubmit}> 66 Post 67 </button> 68 </form> 69 <p class="submitInfo" hidden> 70 {notice()} 71 </p> 72 </> 73 ); 74}; 75 76export default PostForm;