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