Something went wrong. Try again.
softfork of @juliet.paris parfait forked from juliet.paris/parfait
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178import 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<symbol>();
/** * 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<HTMLElement>("[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 ( <> <Show when={replying()}> {/* 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. */} <div ref={box} class="relative isolate z-[1] has-[[role=menu]]:z-40"> {/* The post's line down to your picture, and on past it to the next post if any. */} <ThroughLine inTree={inTree()} onward={rail()} /> <Composer id={id()} reply={{ root: root(), parent: parent() }} placeholder="Write your reply" onSent={() => { // 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()} /> </div> </Show> <Show when={replied()}> <p class="border-line text-faint text-meta animate-fade-in relative isolate flex items-center gap-1.5 px-4 py-2.5" classList={{ "border-b": !rail() && !inTree() && !notification(), "pl-[3.625rem]": !inTree(), "pl-[2.875rem]": inTree(), }} > <Show when={rail()}> <ThroughLine inTree={inTree()} onward /> </Show> <span class="iconify lucide--check size-3.5" /> Replied <span aria-hidden="true">·</span> <Show when={notification()} fallback={ <Link href={postPath(post())} class="hover:text-muted underline-offset-2 transition-colors hover:underline" > See it in the thread </Link> } > {(bell) => ( <button type="button" class="hover:text-muted underline-offset-2 transition-colors hover:underline" onClick={() => bell().open(postPath(post()))} > See it in the thread </button> )} </Show> </p> </Show> </> ); };
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 }) => ( <span class="border-line pointer-events-none absolute top-0 -z-10 border-l-2" classList={{ "left-[35px]": !props.inTree, "left-[29px]": props.inTree, "bottom-0": props.onward, "h-8": !props.onward, }} data-rail="" />);