fix: chat accepts posts

This commit is contained in:
gosangam
2026-08-29 16:26:53 +05:30
parent 76cd106ef7
commit 3e6a1c6f39
5 changed files with 118 additions and 21 deletions
+12 -20
View File
@@ -39,7 +39,6 @@ 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";
@@ -65,8 +64,9 @@ 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);
// Opens the chat picker for this post. The post travels as a reference,
// not as text — the BFF renders the card and re-checks who may see it.
const [sharingToChat, setSharingToChat] = useState(false);
// 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.
@@ -148,21 +148,10 @@ export function PostActionsFooter({ post }: { post: Post }) {
// 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);
}
function onSendClick() {
// No URL to resolve: sharing in-app sends the post id, so this is
// instant where the native sheet has to await the shortener.
setSharingToChat(true);
}
async function onSendHold() {
@@ -302,8 +291,11 @@ export function PostActionsFooter({ post }: { post: Post }) {
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)} />
{sharingToChat && (
<ShareToChatDialog
entity={{ type: "post", id: post.id }}
onClose={() => setSharingToChat(false)}
/>
)}
</>
);