import type { AppBskyFeedDefs, AppBskyFeedPost } from "@atcute/bluesky"; import { createEffect, createSignal, type JSX, on, onCleanup, Show } from "solid-js"; import { noteRepliedTo, wantReply } from "../lib/compose"; import { discardDraft, draftOf } from "../lib/drafts"; import { postPath } from "../lib/format"; import { navigate } from "../lib/tabs"; import { Composer } from "./composer"; import { Link } from "./link"; type PostView = AppBskyFeedDefs.PostView; /** * The one post with a reply being written under it, if any: opening another's puts this one * away, what's written kept for its post, as Escape does. Cancel throws it away. */ const [open, setOpen] = createSignal(); /** * Replying to a post right where it shows in a list (a feed, a thread's line or tree): its reply * field opens under it, and once sent, a line says so. Only once asked: a reply already under * way waits for Reply, which finds it as written, rather than opening on its own and pulling the * feed to it. What's written is kept for the post, as on its own page, unless it's cancelled. */ export const useInlineReply = ( props: () => { post: PostView; rail?: boolean; inTree?: boolean; /** * Under a notification: no rule between rows, as the account the bell is for, and the reply * seen in its thread the way the bell opens a post. */ notification?: { open: (path: string) => void }; }, ) => { const id = () => `reply:${props().post.uri}`; const row = Symbol(); const replying = () => open() === row; const close = () => { if (replying()) setOpen(undefined); }; onCleanup(close); // Put away, by Cancel or by another reply opening: nothing written, nothing to keep. createEffect( on(replying, (now, was) => { if (was && !now && !draftOf(id())?.text.trim()) discardDraft(id()); }), ); /** Just replied to from here: a line says so, with the way to the reply in its thread. */ const [replied, setReplied] = createSignal(false); let box: HTMLDivElement | undefined; /** Opening it, or, already open, back to typing in it. */ const start = () => { if (replying()) box?.querySelector("[contenteditable], textarea")?.focus(); else setOpen(row); setReplied(false); }; // Read as they're used, so they follow the row: a thread's line can come to run on past it. const post = () => props().post; const rail = () => props().rail; const inTree = () => props().inTree; const notification = () => props().notification; const parent = () => ({ uri: post().uri, cid: post().cid }); const root = () => (post().record as AppBskyFeedPost.Main).reply?.root ?? parent(); const view = (): JSX.Element => { return ( <> {/* Above the posts after it, so its menus (who it's posting as, its language) open over them rather than under; and while one's open, above the sidebar too, which a menu reaching left would otherwise slide under. */}
{/* The post's line down to your picture, and on past it to the next post if any. */} { // Counted on the post at once, wherever it shows. noteRepliedTo(post()); close(); setReplied(true); }} // Escape puts it away, what's written kept for the post; Cancel throws it away, // asking first when there's something in it. onCancel={close} onDiscard={close} // Another of your accounts: the post's page, seen as that one, where the reply // carries on as written. onAccount={(did) => { wantReply(post().uri); close(); navigate(postPath(post()), { tab: "new", account: did }); }} // In a thread's line or tree, nothing between it and the next post but the line; // in a tree, a small picture, as the tree's own. noLine={rail() || inTree() || !!notification()} small={inTree()} oneAccount={!!notification()} />

Replied See it in the thread } > {(bell) => ( )}

); }; return { /** A reply being written under it. */ replying, /** Something under it, written or sent: its own line closes the two off together. */ under: () => replying() || replied(), start, view, }; }; /** * A thread's line carried down into what's under a post, down the middle of the pictures: to the * reply's picture, or `onward` past it to the next post. In a tree, drawn and placed as the * tree's own lines. Behind what's there, so a picture covers it; what it's in is isolated, so it * stays in front of the page. */ const ThroughLine = (props: { inTree?: boolean; onward?: boolean }) => ( );