| // src/components/article/ArticleActions.tsx | |
| "use client"; | |
| import { useState, useEffect, useCallback, useRef } from "react"; | |
| import { useNavigate } from "react-router-dom"; | |
| import { useAuth } from "@/context/AuthContext"; | |
| import { | |
| Heart, Share2, Link2, Edit3, Trash2, Bookmark, BookmarkCheck, Loader2, | |
| Flag, MessageCircle, Copy, ExternalLink, Download, ThumbsUp, ThumbsDown, | |
| Check, MoreVertical, | |
| } from "lucide-react"; | |
| import { toast } from "react-toastify"; | |
| // Custom social media icons | |
| const XIcon = () => ( | |
| <svg viewBox="0 0 24 24" fill="currentColor" className="w-4 h-4"> | |
| <path d="M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z" /> | |
| </svg> | |
| ); | |
| const LinkedInIcon = () => ( | |
| <svg viewBox="0 0 24 24" fill="currentColor" className="w-4 h-4"> | |
| <path d="M24 12.073c0-6.627-5.373-12-12-12s-12 5.373-12 12c0 5.99 4.388 10.954 10.125 11.854v-8.385H7.078v-3.47h3.047V9.43c0-3.007 1.792-4.669 4.533-4.669 1.312 0 2.686.235 2.686.235v2.953H15.83c-1.491 0-1.956.925-1.956 1.874v2.25h3.328l-.532 3.47h-2.796v8.385C19.612 23.027 24 18.062 24 12.073z" /> | |
| </svg> | |
| ); | |
| const EmailIcon = () => ( | |
| <svg viewBox="0 0 24 24" fill="currentColor" className="w-4 h-4"> | |
| <path d="M20 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 4l-8 5-8-5V6l8 5 8-5v2z" /> | |
| </svg> | |
| ); | |
| interface ArticleActionsProps { | |
| articleId: number; | |
| authorUsername?: string; | |
| likesCount?: number; | |
| bookmarksCount?: number; | |
| commentsCount?: number; | |
| sharesCount?: number; | |
| initialLiked?: boolean; | |
| initialBookmarked?: boolean; | |
| liked?: boolean; | |
| bookmarked?: boolean; | |
| onLike?: () => Promise<void> | void; | |
| onBookmark?: () => Promise<void> | void; | |
| onShare?: () => Promise<void> | void; | |
| onReport?: () => Promise<void> | void; | |
| onComment?: () => void; | |
| onDelete?: () => Promise<void> | void; | |
| onEdit?: () => void; | |
| onCopyLink?: () => void; | |
| isAuthor?: boolean; | |
| variant?: "horizontal" | "vertical" | "floating" | "minimal"; | |
| showCounts?: boolean; | |
| showSocialShare?: boolean; | |
| showKeyboardShortcuts?: boolean; | |
| className?: string; | |
| } | |
| export function ArticleActions({ | |
| articleId, | |
| authorUsername, | |
| likesCount = 0, | |
| bookmarksCount = 0, | |
| commentsCount = 0, | |
| sharesCount = 0, | |
| initialLiked = false, | |
| initialBookmarked = false, | |
| liked: legacyLiked, | |
| bookmarked: legacyBookmarked, | |
| onLike, | |
| onBookmark, | |
| onShare, | |
| onReport, | |
| onComment, | |
| onDelete, | |
| onEdit, | |
| onCopyLink, | |
| isAuthor: propIsAuthor, | |
| variant = "horizontal", | |
| showCounts = true, | |
| showSocialShare = true, | |
| showKeyboardShortcuts = true, | |
| className = "" | |
| }: ArticleActionsProps) { | |
| const { user } = useAuth(); | |
| const navigate = useNavigate(); | |
| // State | |
| const [liked, setLiked] = useState(legacyLiked ?? initialLiked); | |
| const [bookmarked, setBookmarked] = useState(legacyBookmarked ?? initialBookmarked); | |
| const [localLikes, setLocalLikes] = useState(likesCount); | |
| const [localBookmarks, setLocalBookmarks] = useState(bookmarksCount); | |
| const [copyFeedback, setCopyFeedback] = useState(false); | |
| const [likeLoading, setLikeLoading] = useState(false); | |
| const [bookmarkLoading, setBookmarkLoading] = useState(false); | |
| const [deleteLoading, setDeleteLoading] = useState(false); | |
| const [showShareMenu, setShowShareMenu] = useState(false); | |
| const [showMoreMenu, setShowMoreMenu] = useState(false); | |
| const shareUrl = typeof window !== "undefined" ? window.location.href : ""; | |
| const shareTitle = typeof document !== "undefined" ? document.title : ""; | |
| const isAuthor = propIsAuthor !== undefined ? propIsAuthor : (user?.username === authorUsername || user?.role === "admin"); | |
| const shareMenuRef = useRef<HTMLDivElement>(null); | |
| const moreMenuRef = useRef<HTMLDivElement>(null); | |
| // Close menus when clicking outside | |
| useEffect(() => { | |
| const handleClickOutside = (event: MouseEvent) => { | |
| if (shareMenuRef.current && !shareMenuRef.current.contains(event.target as Node)) { | |
| setShowShareMenu(false); | |
| } | |
| if (moreMenuRef.current && !moreMenuRef.current.contains(event.target as Node)) { | |
| setShowMoreMenu(false); | |
| } | |
| }; | |
| document.addEventListener("mousedown", handleClickOutside); | |
| return () => document.removeEventListener("mousedown", handleClickOutside); | |
| }, []); | |
| // Handlers | |
| const handleLike = async () => { | |
| if (likeLoading || !user) { | |
| if (!user) toast.info("Sign in to like articles"); | |
| return; | |
| } | |
| setLikeLoading(true); | |
| try { | |
| setLiked(!liked); | |
| setLocalLikes(prev => liked ? prev - 1 : prev + 1); | |
| if (onLike) await onLike(); | |
| toast.success(liked ? "Removed like" : "Liked!"); | |
| } catch (err) { | |
| setLiked(liked); | |
| setLocalLikes(localLikes); | |
| toast.error("Failed to update like status"); | |
| } finally { | |
| setLikeLoading(false); | |
| } | |
| }; | |
| const handleBookmark = async () => { | |
| if (bookmarkLoading || !user) { | |
| if (!user) toast.info("Sign in to bookmark articles"); | |
| return; | |
| } | |
| if (!onBookmark) return; | |
| setBookmarkLoading(true); | |
| try { | |
| setBookmarked(!bookmarked); | |
| setLocalBookmarks(prev => bookmarked ? prev - 1 : prev + 1); | |
| await onBookmark(); | |
| toast.success(bookmarked ? "Removed bookmark" : "Bookmarked!"); | |
| } catch (err) { | |
| setBookmarked(bookmarked); | |
| setLocalBookmarks(localBookmarks); | |
| toast.error("Failed to update bookmark"); | |
| } finally { | |
| setBookmarkLoading(false); | |
| } | |
| }; | |
| const handleCopyLink = () => { | |
| const url = window.location.href; | |
| navigator.clipboard.writeText(url); | |
| setCopyFeedback(true); | |
| toast.success("Link copied to clipboard!"); | |
| if (onCopyLink) onCopyLink(); | |
| setTimeout(() => setCopyFeedback(false), 2000); | |
| }; | |
| const handleShareNative = async () => { | |
| if (onShare) { | |
| await onShare(); | |
| } else { | |
| try { | |
| await navigator.share({ | |
| title: shareTitle, | |
| url: shareUrl, | |
| }); | |
| toast.success("Shared successfully!"); | |
| } catch { | |
| handleCopyLink(); | |
| } | |
| } | |
| }; | |
| const handleDelete = async () => { | |
| if (!window.confirm("Are you sure you want to delete this article? This action cannot be undone.")) return; | |
| setDeleteLoading(true); | |
| try { | |
| if (onDelete) await onDelete(); | |
| toast.success("Article deleted"); | |
| navigate("/articles"); | |
| } catch (err) { | |
| toast.error("Failed to delete article"); | |
| } finally { | |
| setDeleteLoading(false); | |
| } | |
| }; | |
| const handleEdit = () => { | |
| if (onEdit) { | |
| onEdit(); | |
| } else { | |
| navigate(`/edit-article/${articleId}`); | |
| } | |
| }; | |
| // Keyboard shortcuts | |
| useEffect(() => { | |
| const handleKeyDown = (e: KeyboardEvent) => { | |
| if (e.target instanceof HTMLInputElement || e.target instanceof HTMLTextAreaElement) return; | |
| const key = e.key.toLowerCase(); | |
| if (key === 'l') { | |
| e.preventDefault(); | |
| handleLike(); | |
| } else if (key === 'b' && onBookmark) { | |
| e.preventDefault(); | |
| handleBookmark(); | |
| } else if (key === 's') { | |
| e.preventDefault(); | |
| handleCopyLink(); | |
| } else if (key === 'e' && isAuthor) { | |
| e.preventDefault(); | |
| handleEdit(); | |
| } else if (key === 'd' && isAuthor) { | |
| e.preventDefault(); | |
| handleDelete(); | |
| } | |
| }; | |
| window.addEventListener('keydown', handleKeyDown); | |
| return () => window.removeEventListener('keydown', handleKeyDown); | |
| }, [handleLike, handleBookmark, handleCopyLink, handleEdit, handleDelete, isAuthor, onBookmark]); | |
| const buttonClass = "inline-flex items-center gap-2 px-4 py-2.5 rounded-full text-sm font-medium transition-all duration-200 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary disabled:opacity-50 disabled:cursor-not-allowed"; | |
| const secondaryClass = "bg-gray-50 dark:bg-gray-700/50 text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-700 ring-1 ring-gray-200 dark:ring-gray-600"; | |
| const primaryClass = "bg-primary text-white hover:bg-primary-dark shadow-sm"; | |
| const socialShareLinks = [ | |
| { name: "X (X)", icon: XIcon, url: `https://twitter.com/intent/tweet?text=${encodeURIComponent(shareTitle)}&url=${encodeURIComponent(shareUrl)}`, color: "hover:bg-[#1DA1F2]" }, | |
| { name: "LinkedIn", icon: LinkedInIcon, url: `https://www.linkedin.com/sharing/share-offsite/?url=${encodeURIComponent(shareUrl)}`, color: "hover:bg-[#0077B5]" }, | |
| { name: "Email", icon: EmailIcon, url: `mailto:?subject=${encodeURIComponent(shareTitle)}&body=${encodeURIComponent(shareUrl)}`, color: "hover:bg-[#EA4335]" }, | |
| ]; | |
| // Minimal variant | |
| if (variant === "minimal") { | |
| return ( | |
| <div className={`flex items-center gap-3 ${className}`}> | |
| <button onClick={handleLike} className="flex items-center gap-1 text-gray-500 hover:text-pink-500 transition"> | |
| <Heart className={`h-4 w-4 ${liked ? "fill-pink-500 text-pink-500" : ""}`} /> | |
| <span className="text-sm">{localLikes}</span> | |
| </button> | |
| <button onClick={onComment} className="flex items-center gap-1 text-gray-500 hover:text-green-500 transition"> | |
| <MessageCircle className="h-4 w-4" /> | |
| <span className="text-sm">{commentsCount}</span> | |
| </button> | |
| <button onClick={handleCopyLink} className="text-gray-500 hover:text-blue-500 transition"> | |
| {copyFeedback ? <Check className="h-4 w-4 text-green-500" /> : <Share2 className="h-4 w-4" />} | |
| </button> | |
| </div> | |
| ); | |
| } | |
| // Vertical variant | |
| if (variant === "vertical") { | |
| return ( | |
| <div className={`flex flex-col gap-3 ${className}`}> | |
| {/* Like Button */} | |
| <button | |
| onClick={handleLike} | |
| disabled={likeLoading} | |
| className={`flex flex-col items-center gap-1 p-3 rounded-xl transition ${ | |
| liked ? "text-pink-500" : "text-gray-500 hover:text-pink-500 hover:bg-pink-50 dark:hover:bg-pink-900/20" | |
| }`} | |
| > | |
| {likeLoading ? <Loader2 className="h-5 w-5 animate-spin" /> : <Heart className={`h-5 w-5 ${liked ? "fill-current" : ""}`} />} | |
| {showCounts && <span className="text-xs font-medium">{localLikes}</span>} | |
| <span className="text-xs">Like</span> | |
| </button> | |
| {/* Comment Button */} | |
| {onComment && ( | |
| <button | |
| onClick={onComment} | |
| className="flex flex-col items-center gap-1 p-3 rounded-xl text-gray-500 hover:text-green-500 hover:bg-green-50 dark:hover:bg-green-900/20 transition" | |
| > | |
| <MessageCircle className="h-5 w-5" /> | |
| {showCounts && <span className="text-xs font-medium">{commentsCount}</span>} | |
| <span className="text-xs">Comment</span> | |
| </button> | |
| )} | |
| {/* Bookmark Button */} | |
| {onBookmark && ( | |
| <button | |
| onClick={handleBookmark} | |
| disabled={bookmarkLoading} | |
| className={`flex flex-col items-center gap-1 p-3 rounded-xl transition ${ | |
| bookmarked ? "text-yellow-500" : "text-gray-500 hover:text-yellow-500 hover:bg-yellow-50 dark:hover:bg-yellow-900/20" | |
| }`} | |
| > | |
| {bookmarkLoading ? <Loader2 className="h-5 w-5 animate-spin" /> : <Bookmark className={`h-5 w-5 ${bookmarked ? "fill-current" : ""}`} />} | |
| {showCounts && <span className="text-xs font-medium">{localBookmarks}</span>} | |
| <span className="text-xs">Save</span> | |
| </button> | |
| )} | |
| {/* Share Button */} | |
| <div className="relative" ref={shareMenuRef}> | |
| <button | |
| onClick={() => setShowShareMenu(!showShareMenu)} | |
| className="flex flex-col items-center gap-1 p-3 rounded-xl text-gray-500 hover:text-blue-500 hover:bg-blue-50 dark:hover:bg-blue-900/20 transition" | |
| > | |
| <Share2 className="h-5 w-5" /> | |
| {showCounts && <span className="text-xs font-medium">{sharesCount}</span>} | |
| <span className="text-xs">Share</span> | |
| </button> | |
| {showShareMenu && ( | |
| <div className="absolute left-full ml-2 top-0 bg-white dark:bg-gray-800 rounded-xl shadow-lg border border-gray-200 dark:border-gray-700 p-2 z-10 min-w-[160px]"> | |
| {socialShareLinks.map((link) => ( | |
| <a | |
| key={link.name} | |
| href={link.url} | |
| target="_blank" | |
| rel="noopener noreferrer" | |
| className={`flex items-center gap-2 px-3 py-2 text-sm rounded-lg transition ${link.color} hover:text-white`} | |
| > | |
| <link.icon /> | |
| {link.name} | |
| </a> | |
| ))} | |
| <button | |
| onClick={handleCopyLink} | |
| className="flex items-center gap-2 px-3 py-2 text-sm rounded-lg w-full text-left hover:bg-gray-100 dark:hover:bg-gray-700 transition" | |
| > | |
| <Copy className="h-4 w-4" /> | |
| Copy Link | |
| </button> | |
| </div> | |
| )} | |
| </div> | |
| {/* More Menu (Edit/Delete/Report) */} | |
| {(isAuthor || onReport) && ( | |
| <div className="relative" ref={moreMenuRef}> | |
| <button | |
| onClick={() => setShowMoreMenu(!showMoreMenu)} | |
| className="flex flex-col items-center gap-1 p-3 rounded-xl text-gray-500 hover:text-gray-700 dark:hover:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800 transition" | |
| > | |
| <MoreVertical className="h-5 w-5" /> | |
| <span className="text-xs">More</span> | |
| </button> | |
| {showMoreMenu && ( | |
| <div className="absolute left-full ml-2 top-0 bg-white dark:bg-gray-800 rounded-xl shadow-lg border border-gray-200 dark:border-gray-700 p-2 z-10 min-w-[160px]"> | |
| {isAuthor && ( | |
| <> | |
| <button | |
| onClick={handleEdit} | |
| className="flex items-center gap-2 px-3 py-2 text-sm rounded-lg w-full text-left hover:bg-gray-100 dark:hover:bg-gray-700 transition" | |
| > | |
| <Edit3 className="h-4 w-4" /> | |
| Edit Article | |
| </button> | |
| <button | |
| onClick={handleDelete} | |
| disabled={deleteLoading} | |
| className="flex items-center gap-2 px-3 py-2 text-sm rounded-lg w-full text-left text-red-600 hover:bg-red-50 dark:hover:bg-red-900/20 transition" | |
| > | |
| {deleteLoading ? <Loader2 className="h-4 w-4 animate-spin" /> : <Trash2 className="h-4 w-4" />} | |
| Delete Article | |
| </button> | |
| </> | |
| )} | |
| {onReport && ( | |
| <button | |
| onClick={() => { onReport(); setShowMoreMenu(false); }} | |
| className="flex items-center gap-2 px-3 py-2 text-sm rounded-lg w-full text-left text-red-600 hover:bg-red-50 dark:hover:bg-red-900/20 transition" | |
| > | |
| <Flag className="h-4 w-4" /> | |
| Report Abuse | |
| </button> | |
| )} | |
| </div> | |
| )} | |
| </div> | |
| )} | |
| </div> | |
| ); | |
| } | |
| // Floating variant (fixed position) | |
| if (variant === "floating") { | |
| return ( | |
| <div className={`fixed right-6 top-1/2 -translate-y-1/2 z-40 flex flex-col gap-3 bg-white dark:bg-gray-800 rounded-2xl shadow-xl p-2 border border-gray-200 dark:border-gray-700 ${className}`}> | |
| <button | |
| onClick={handleLike} | |
| className={`p-2 rounded-xl transition ${liked ? "text-pink-500 bg-pink-50 dark:bg-pink-900/20" : "text-gray-500 hover:text-pink-500 hover:bg-pink-50 dark:hover:bg-pink-900/20"}`} | |
| title="Like (L)" | |
| > | |
| <Heart className={`h-5 w-5 ${liked ? "fill-current" : ""}`} /> | |
| </button> | |
| <button | |
| onClick={onComment} | |
| className="p-2 rounded-xl text-gray-500 hover:text-green-500 hover:bg-green-50 dark:hover:bg-green-900/20 transition" | |
| title="Comment" | |
| > | |
| <MessageCircle className="h-5 w-5" /> | |
| </button> | |
| <button | |
| onClick={handleCopyLink} | |
| className="p-2 rounded-xl text-gray-500 hover:text-blue-500 hover:bg-blue-50 dark:hover:bg-blue-900/20 transition" | |
| title="Share (S)" | |
| > | |
| {copyFeedback ? <Check className="h-5 w-5 text-green-500" /> : <Share2 className="h-5 w-5" />} | |
| </button> | |
| {onBookmark && ( | |
| <button | |
| onClick={handleBookmark} | |
| className={`p-2 rounded-xl transition ${bookmarked ? "text-yellow-500 bg-yellow-50 dark:bg-yellow-900/20" : "text-gray-500 hover:text-yellow-500 hover:bg-yellow-50 dark:hover:bg-yellow-900/20"}`} | |
| title="Bookmark (B)" | |
| > | |
| <Bookmark className={`h-5 w-5 ${bookmarked ? "fill-current" : ""}`} /> | |
| </button> | |
| )} | |
| </div> | |
| ); | |
| } | |
| // Horizontal variant (default) | |
| return ( | |
| <div className={`bg-white dark:bg-gray-800 rounded-2xl shadow-lg overflow-hidden border border-gray-100 dark:border-gray-700 ${className}`}> | |
| <div className="p-4 sm:p-6"> | |
| {!user && ( | |
| <div className="mb-4 rounded-2xl border border-sky-200 bg-sky-50 px-4 py-3 text-sm text-sky-900 dark:border-sky-900/40 dark:bg-sky-950/30 dark:text-sky-100"> | |
| Sign in to like, bookmark, or manage this article. Reading and sharing stay open. | |
| </div> | |
| )} | |
| <div className="flex flex-wrap items-center gap-2 sm:gap-3"> | |
| {/* Like Button */} | |
| <button | |
| onClick={handleLike} | |
| disabled={likeLoading || !user} | |
| className={`${buttonClass} ${liked ? "bg-red-50 dark:bg-red-900/20 text-red-600 dark:text-red-400 ring-1 ring-red-200 dark:ring-red-800" : secondaryClass}`} | |
| aria-label={liked ? "Unlike" : "Like"} | |
| title="Like (L)" | |
| > | |
| {likeLoading ? <Loader2 className="w-4 h-4 animate-spin" /> : <Heart className={`w-4 h-4 transition ${liked ? "fill-current text-red-500" : ""}`} />} | |
| <span>{liked ? "Liked" : "Like"}</span> | |
| {showCounts && <span className={`ml-1 px-1.5 py-0.5 rounded-full text-xs ${liked ? "bg-red-100 dark:bg-red-800" : "bg-gray-200 dark:bg-gray-600"}`}>{localLikes}</span>} | |
| </button> | |
| {/* Comment Button */} | |
| {onComment && ( | |
| <button | |
| onClick={onComment} | |
| className={`${buttonClass} ${secondaryClass}`} | |
| aria-label="Comments" | |
| title="Comments" | |
| > | |
| <MessageCircle className="w-4 h-4" /> | |
| Comment | |
| {showCounts && <span className="ml-1 px-1.5 py-0.5 rounded-full text-xs bg-gray-200 dark:bg-gray-600">{commentsCount}</span>} | |
| </button> | |
| )} | |
| {/* Bookmark Button */} | |
| {onBookmark && ( | |
| <button | |
| onClick={handleBookmark} | |
| disabled={bookmarkLoading || !user} | |
| className={`${buttonClass} ${bookmarked ? "bg-blue-50 dark:bg-blue-900/20 text-blue-600 dark:text-blue-400 ring-1 ring-blue-200 dark:ring-blue-800" : secondaryClass}`} | |
| aria-label={bookmarked ? "Remove bookmark" : "Bookmark"} | |
| title="Bookmark (B)" | |
| > | |
| {bookmarkLoading ? <Loader2 className="w-4 h-4 animate-spin" /> : bookmarked ? <BookmarkCheck className="w-4 h-4 fill-current" /> : <Bookmark className="w-4 h-4" />} | |
| {bookmarked ? "Saved" : "Bookmark"} | |
| {showCounts && <span className={`ml-1 px-1.5 py-0.5 rounded-full text-xs ${bookmarked ? "bg-blue-100 dark:bg-blue-800" : "bg-gray-200 dark:bg-gray-600"}`}>{localBookmarks}</span>} | |
| </button> | |
| )} | |
| {/* Share Button with Dropdown */} | |
| {showSocialShare && ( | |
| <div className="relative" ref={shareMenuRef}> | |
| <button | |
| onClick={() => setShowShareMenu(!showShareMenu)} | |
| className={`${buttonClass} ${secondaryClass}`} | |
| aria-label="Share article" | |
| title="Share (S)" | |
| > | |
| {copyFeedback ? <Link2 className="w-4 h-4 text-green-500" /> : <Share2 className="w-4 h-4" />} | |
| {copyFeedback ? "Copied!" : "Share"} | |
| </button> | |
| {showShareMenu && ( | |
| <div className="absolute top-full left-0 mt-2 bg-white dark:bg-gray-800 rounded-xl shadow-lg border border-gray-200 dark:border-gray-700 p-2 z-10 min-w-[180px]"> | |
| <button | |
| onClick={handleShareNative} | |
| className="flex items-center gap-2 px-3 py-2 text-sm rounded-lg w-full text-left hover:bg-gray-100 dark:hover:bg-gray-700 transition" | |
| > | |
| <Share2 className="h-4 w-4" /> | |
| Share via... | |
| </button> | |
| <div className="h-px bg-gray-200 dark:bg-gray-700 my-1" /> | |
| {socialShareLinks.map((link) => ( | |
| <a | |
| key={link.name} | |
| href={link.url} | |
| target="_blank" | |
| rel="noopener noreferrer" | |
| className={`flex items-center gap-2 px-3 py-2 text-sm rounded-lg transition ${link.color} hover:text-white`} | |
| > | |
| <link.icon /> | |
| {link.name} | |
| </a> | |
| ))} | |
| <div className="h-px bg-gray-200 dark:bg-gray-700 my-1" /> | |
| <button | |
| onClick={handleCopyLink} | |
| className="flex items-center gap-2 px-3 py-2 text-sm rounded-lg w-full text-left hover:bg-gray-100 dark:hover:bg-gray-700 transition" | |
| > | |
| <Copy className="h-4 w-4" /> | |
| Copy Link | |
| </button> | |
| </div> | |
| )} | |
| </div> | |
| )} | |
| {/* Edit / Delete (owner & admin) */} | |
| {isAuthor && ( | |
| <> | |
| <button | |
| onClick={handleEdit} | |
| className={`${buttonClass} ${primaryClass}`} | |
| aria-label="Edit article" | |
| title="Edit (E)" | |
| > | |
| <Edit3 className="w-4 h-4" /> | |
| Edit | |
| </button> | |
| <button | |
| onClick={handleDelete} | |
| disabled={deleteLoading} | |
| className={`${buttonClass} bg-red-50 dark:bg-red-900/20 text-red-600 dark:text-red-400 ring-1 ring-red-200 dark:ring-red-800 hover:bg-red-100 dark:hover:bg-red-900/40`} | |
| aria-label="Delete article" | |
| title="Delete (D)" | |
| > | |
| {deleteLoading ? <Loader2 className="w-4 h-4 animate-spin" /> : <Trash2 className="w-4 h-4" />} | |
| Delete | |
| </button> | |
| </> | |
| )} | |
| {/* Report Button */} | |
| {onReport && !isAuthor && ( | |
| <button | |
| onClick={() => onReport()} | |
| className={`${buttonClass} ${secondaryClass}`} | |
| aria-label="Report article" | |
| title="Report" | |
| > | |
| <Flag className="w-4 h-4" /> | |
| Report | |
| </button> | |
| )} | |
| </div> | |
| {showKeyboardShortcuts && ( | |
| <div className="mt-3 text-xs text-gray-400 text-center sm:text-left"> | |
| 💡 Keyboard shortcuts: L (like), B (bookmark), S (share link), {isAuthor && "E (edit), D (delete)"} | |
| </div> | |
| )} | |
| </div> | |
| </div> | |
| ); | |
| } | |
Xet Storage Details
- Size:
- 23.8 kB
- Xet hash:
- 3d2e0de81915b1357db1fd5d06b02d012b4a9dc87e9bb082a0de1ce1259d3af7
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.