feat: share post to other apps
This commit is contained in:
@@ -17,6 +17,7 @@ import { createPortal } from "react-dom";
|
||||
import { useRouter } from "next/navigation";
|
||||
import Image from "next/image";
|
||||
import { X, ImagePlus, Trash2, Send } from "lucide-react";
|
||||
import { toast } from "sonner";
|
||||
import {
|
||||
Drawer,
|
||||
DrawerContent,
|
||||
@@ -26,6 +27,7 @@ import {
|
||||
import { posts, SocialError } from "@/lib/social";
|
||||
import { buildHighlightUrl } from "@/lib/text-highlight";
|
||||
import { getSourceReference } from "@/lib/source-reference";
|
||||
import { useSharePost } from "@/components/social/share-post-provider";
|
||||
|
||||
const MAX_IMAGES = 5;
|
||||
const PRESS_IMAGE_TYPES = "image/png,image/jpeg,image/webp,image/gif";
|
||||
@@ -44,6 +46,7 @@ export function ComposePost({
|
||||
onPosted?: () => void;
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const { openShareSheet } = useSharePost();
|
||||
const fileInput = useRef<HTMLInputElement>(null);
|
||||
const [images, setImages] = useState<{ url: string; uploading: boolean }[]>(
|
||||
[],
|
||||
@@ -108,7 +111,7 @@ export function ComposePost({
|
||||
: typeof document !== "undefined"
|
||||
? document.title
|
||||
: "";
|
||||
await posts.create({
|
||||
const newPost = await posts.create({
|
||||
caption: selectedText,
|
||||
source_url: sourceURL,
|
||||
source_title: sourceTitle,
|
||||
@@ -119,6 +122,19 @@ export function ComposePost({
|
||||
onPosted?.();
|
||||
onClose();
|
||||
router.refresh();
|
||||
// Success feedback + offer to externally share. The BFF's Create
|
||||
// response doesn't include author info (no JOIN with users), but
|
||||
// SharePostSheet falls back to the authed user's handle when
|
||||
// post.author_handle is missing — perfect for a freshly-created
|
||||
// post since the creator IS the auth user.
|
||||
toast.success("Posted to your feed", {
|
||||
description: "Want to share it to other apps?",
|
||||
action: {
|
||||
label: "Share",
|
||||
onClick: () => openShareSheet(newPost),
|
||||
},
|
||||
duration: 5000,
|
||||
});
|
||||
} catch (err) {
|
||||
if (err instanceof SocialError && err.status === 401) {
|
||||
setError("Please log in to post.");
|
||||
|
||||
Reference in New Issue
Block a user