fix: chat accepts quotes now

This commit is contained in:
gosangam
2026-08-29 11:58:33 +05:30
parent 028a8d7e1c
commit 76cd106ef7
11 changed files with 559 additions and 41 deletions
+41 -5
View File
@@ -39,6 +39,9 @@ import {
type Comment,
type Post,
} from "@/lib/social";
import { buildPostShareText } from "@/lib/post-share-text";
import { useLongPress } from "@/lib/use-long-press";
import { ShareToChatDialog } from "@/components/chat/share-to-chat-dialog";
import { useAuth } from "@/components/auth/auth-provider";
import { useAuthGate } from "@/components/auth/auth-gate";
import { useMediaQuery } from "@/components/selection-toolbar/shared";
@@ -62,6 +65,8 @@ export function PostActionsFooter({ post }: { post: Post }) {
// on mobile native-share; sheet mount on desktop) so the Send icon
// can render a spinner while the user waits.
const [sharePending, setSharePending] = useState(false);
// The post as chat-ready text. Non-null opens the picker.
const [chatBody, setChatBody] = useState<string | null>(null);
// Optimistic local mirror of post.viewer_has_reshared so the swap
// happens the instant the user taps Reshare. Reconciles to the
// server's value via rollback if the API call fails.
@@ -140,7 +145,27 @@ export function PostActionsFooter({ post }: { post: Post }) {
// parallel, then navigator.share) and the desktop/no-native-share
// path (mount the custom SharePostSheet). Provider's openShareSheet
// is always-resolves, so a single try/finally toggles the spinner.
// Tap → send to a chat. Hold → the platform's own share sheet, for
// everything outside the app. The link text is identical either way; only
// the destination differs.
async function onSendClick() {
if (sharePending) return;
setSharePending(true);
try {
const share = await buildPostShareText(post, post.author_handle ?? "");
if (!share) {
// No handle means no post URL — fall back to the sheet, which
// resolves the handle itself and has its own failure path.
await openShareSheet(post);
return;
}
setChatBody(share.text);
} finally {
setSharePending(false);
}
}
async function onSendHold() {
if (sharePending) return;
setSharePending(true);
try {
@@ -150,6 +175,12 @@ export function PostActionsFooter({ post }: { post: Post }) {
}
}
const sendGestures = useLongPress({
onClick: onSendClick,
onLongPress: onSendHold,
disabled: sharePending,
});
return (
<>
<div className="flex items-center justify-between px-2">
@@ -197,8 +228,8 @@ export function PostActionsFooter({ post }: { post: Post }) {
{showSend ? (
<ActionButton
label={sharePending ? "Preparing share link…" : "Send"}
onClick={onSendClick}
disabled={sharePending}
{...sendGestures}
icon={
sharePending ? (
<Loader2
@@ -270,29 +301,34 @@ export function PostActionsFooter({ post }: { post: Post }) {
{/* SharePostSheet is mounted globally by SharePostProvider, so
no per-card instance lives here. The provider's
openShareSheet swaps the active post under the hood. */}
{chatBody !== null && (
<ShareToChatDialog body={chatBody} onClose={() => setChatBody(null)} />
)}
</>
);
}
function ActionButton({
label,
onClick,
icon,
disabled = false,
...buttonProps
}: {
label: string;
onClick: () => void;
icon: React.ReactNode;
/** Greys out the button and blocks clicks. Used by the Send button
* while the short URL is being resolved on the mobile native-share
* path so users can't fire navigator.share before the URL is
* ready. */
disabled?: boolean;
}) {
/** onClick, plus the pointer handlers the Send button needs to tell a
* tap from a hold. */
} & React.ComponentProps<"button">) {
return (
<button
{...buttonProps}
type="button"
onClick={onClick}
disabled={disabled}
aria-label={label}
title={label}