import React, { useState, useCallback } from 'react'; import AltifierImageCard from './AltifierImageCard'; import BlueskyPostEmbed from './BlueskyPostEmbed'; export default function AltifierPostCard({ post, sessionDid, onApply, geminiEnabled }) { const [approved, setApproved] = useState({}); const [rejected, setRejected] = useState(new Set()); const [isApplying, setIsApplying] = useState(false); const [showConfirm, setShowConfirm] = useState(false); const [applyError, setApplyError] = useState(null); const missingImages = post.images.filter((img) => !img.hasAlt); const handleApproveImage = useCallback((imageIndex, altText) => { setApproved((prev) => ({ ...prev, [imageIndex]: altText })); setRejected((prev) => { const next = new Set(prev); next.delete(imageIndex); return next; }); }, []); const handleRejectImage = useCallback((imageIndex) => { setRejected((prev) => new Set(prev).add(imageIndex)); setApproved((prev) => { const next = { ...prev }; delete next[imageIndex]; return next; }); }, []); const approvedCount = Object.keys(approved).length; const allReviewed = missingImages.length === 0 || (approvedCount + rejected.size >= missingImages.length); // P7 — Build the old → new diff shown before applying. const diffEntries = Object.entries(approved).map(([idx, newText]) => { const i = parseInt(idx, 10); const img = post.images.find((m) => m.index === i) || { index: i, kind: 'image', currentAlt: '', }; const oldAlt = img.currentAlt ? `"${img.currentAlt}"` : '(empty)'; const label = img.kind === 'video' ? 'Video' : `Image ${img.index + 1}`; return { label, oldAlt, newText }; }); const handleApplyClick = () => { setShowConfirm(true); setApplyError(null); }; const handleConfirmApply = async () => { setIsApplying(true); setShowConfirm(false); setApplyError(null); try { await onApply(post, approved); } catch (err) { setApplyError(err.message || 'Failed to apply alt text'); } finally { setIsApplying(false); } }; const imagesToReview = missingImages.length > 0 ? missingImages : post.images; return (

{post.text || '(no text)'}

{new Date(post.createdAt).toLocaleDateString()} {post.isReply && ( Reply )}
{post.uri}
{imagesToReview.map((img) => ( ))}
{missingImages.length > 0 && (
{approvedCount} of {missingImages.length} image{missingImages.length !== 1 ? 's' : ''} approved {rejected.size > 0 && `, ${rejected.size} skipped`} {allReviewed && approvedCount > 0 && ' — ready to apply'}
{approvedCount > 0 && ( )}
)} {applyError && (

{applyError}

)} {showConfirm && (
setShowConfirm(false)}>
e.stopPropagation()}>

Confirm Alt Text Update

Alt text will be applied by deleting this post and recreating it with the new alt text. The original post's likes, reposts, quotes, and replies will be lost permanently. (AT Protocol posts are immutable; Bluesky ignores in-place edits.)

    {diffEntries.map((d) => (
  • {d.label}: {d.oldAlt} {' → '} "{d.newText}"
  • ))}
)}
); }