diff --git a/src/components/ContentCardSocialActions.tsx b/src/components/ContentCardSocialActions.tsx index b67690a..adfd36e 100644 --- a/src/components/ContentCardSocialActions.tsx +++ b/src/components/ContentCardSocialActions.tsx @@ -1,12 +1,14 @@ import React, { useEffect, useLayoutEffect, useRef, useState } from 'react'; import { createPortal } from 'react-dom'; import { useTranslation } from 'react-i18next'; -import { toggleVideoLike } from '../utils/api'; +import { API_URL, toggleVideoLike } from '../utils/api'; +import { buildVideoShareUrl, tryNativeShare } from '../utils/nativeShare'; interface ContentCardSocialActionsProps { videoId: number; storeName: string; region?: string; + posterUrl?: string | null; commentCount: number; initialLikeCount: number; initialIsLiked?: boolean; @@ -16,6 +18,7 @@ const ContentCardSocialActions: React.FC = ({ videoId, storeName, region, + posterUrl, commentCount, initialLikeCount, initialIsLiked = false, @@ -33,7 +36,11 @@ const ContentCardSocialActions: React.FC = ({ const shareMenuRef = useRef(null); const likeDebounceRef = useRef | null>(null); - const shareUrl = `${window.location.origin}/video/${videoId}`; + const videoPageUrl = `${window.location.origin}/video/${videoId}`; + const shareUrl = buildVideoShareUrl(API_URL, videoId); + const shareTitle = storeName || t('videoDetail.kakaoDefaultTitle'); + const shareDescription = t('videoDetail.kakaoDescription', { region: region ?? '' }); + const shareImageUrl = posterUrl || `${window.location.origin}/assets/images/hero-background.png`; useEffect(() => { if (!shareMenuOpen) return; @@ -96,15 +103,15 @@ const ContentCardSocialActions: React.FC = ({ kakao.Share.sendDefault({ objectType: 'feed', content: { - title: storeName || t('videoDetail.kakaoDefaultTitle'), - description: t('videoDetail.kakaoDescription', { region: region ?? '' }), - imageUrl: 'https://ado2.o2osolution.ai/favicon_48.svg', - link: { mobileWebUrl: shareUrl, webUrl: shareUrl }, + title: shareTitle, + description: shareDescription, + imageUrl: shareImageUrl, + link: { mobileWebUrl: videoPageUrl, webUrl: videoPageUrl }, }, - buttons: [{ title: t('videoDetail.kakaoButtonTitle'), link: { mobileWebUrl: shareUrl, webUrl: shareUrl } }], + buttons: [{ title: t('videoDetail.kakaoButtonTitle'), link: { mobileWebUrl: videoPageUrl, webUrl: videoPageUrl } }], }); } else if (navigator.share) { - navigator.share({ url: shareUrl }).catch(() => {}); + navigator.share({ title: shareTitle, text: shareDescription, url: shareUrl }).catch(() => {}); } else { handleCopyLink(); } @@ -144,8 +151,19 @@ const ContentCardSocialActions: React.FC = ({ }, 500); }; - const handleShareBtnClick = (e: React.MouseEvent) => { + const handleShareBtnClick = async (e: React.MouseEvent) => { e.stopPropagation(); + + const handled = await tryNativeShare({ + title: shareTitle, + text: shareDescription, + url: shareUrl, + }); + if (handled) { + setShareMenuOpen(false); + return; + } + const rect = shareBtnRef.current?.getBoundingClientRect(); if (rect) { // 초기 추정 위치(측정 전 첫 렌더용) — useLayoutEffect가 실제 크기 기준으로 다시 보정한다 diff --git a/src/components/VideoDetailContent.tsx b/src/components/VideoDetailContent.tsx index da836fa..1494b56 100644 --- a/src/components/VideoDetailContent.tsx +++ b/src/components/VideoDetailContent.tsx @@ -7,8 +7,11 @@ import { deleteComment, toggleVideoLike, isLoggedIn, + getUserMe, + API_URL, } from '../utils/api'; -import { VideoDetailItem, CommentItem } from '../types/api'; +import { VideoDetailItem, CommentItem, UserMeResponse } from '../types/api'; +import { buildVideoShareUrl, tryNativeShare } from '../utils/nativeShare'; import LoginPromptModal from './LoginPromptModal'; interface VideoDetailContentProps { @@ -42,16 +45,7 @@ const VideoDetailContent: React.FC = ({ videoId, isModa const [commentSubmitting, setCommentSubmitting] = useState(false); const commentTextareaRef = useRef(null); - const [commentNickname, setCommentNickname] = useState(''); - const [commentAvatarSeedIdx, setCommentAvatarSeedIdx] = useState(0); - - // 고정 seed 목록: 브라우저가 캐싱하여 중복 요청 없음 - const AVATAR_SEEDS = ['42', '77', '123', '256', '512', '888', '1024', '2048', '3141', '9999']; - const commentAvatarSeed = AVATAR_SEEDS[commentAvatarSeedIdx % AVATAR_SEEDS.length]; - - const handleChangeAvatar = useCallback(() => { - setCommentAvatarSeedIdx(prev => (prev + 1) % AVATAR_SEEDS.length); - }, []); + const [currentUser, setCurrentUser] = useState(null); const fetchComments = useCallback(async (page: number, append = false) => { setCommentsLoading(true); @@ -92,6 +86,13 @@ const VideoDetailContent: React.FC = ({ videoId, isModa fetchComments(1); }, [videoId, fetchComments]); + useEffect(() => { + if (!authed) return; + getUserMe().then(setCurrentUser).catch((err) => { + console.error('Failed to fetch current user:', err); + }); + }, [authed]); + const formatDate = (dateString: string) => { const date = new Date(dateString); return t('videoDetail.dateFormat', { year: date.getFullYear(), month: date.getMonth() + 1, day: date.getDate() }); @@ -102,7 +103,11 @@ const VideoDetailContent: React.FC = ({ videoId, isModa return `${date.getFullYear()}.${String(date.getMonth() + 1).padStart(2, '0')}.${String(date.getDate()).padStart(2, '0')}`; }; - const shareUrl = `${window.location.origin}/video/${videoId}`; + const videoPageUrl = `${window.location.origin}/video/${videoId}`; + const shareUrl = buildVideoShareUrl(API_URL, videoId); + const shareTitle = video?.store_name ?? t('videoDetail.kakaoDefaultTitle'); + const shareDescription = t('videoDetail.kakaoDescription', { region: video?.region ?? '' }); + const shareImageUrl = video?.poster_url || `${window.location.origin}/assets/images/hero-background.png`; const handleCopyLink = async () => { try { @@ -120,15 +125,15 @@ const VideoDetailContent: React.FC = ({ videoId, isModa kakao.Share.sendDefault({ objectType: 'feed', content: { - title: video?.store_name ?? t('videoDetail.kakaoDefaultTitle'), - description: t('videoDetail.kakaoDescription', { region: video?.region ?? '' }), - imageUrl: 'https://ado2.o2osolution.ai/favicon_48.svg', - link: { mobileWebUrl: shareUrl, webUrl: shareUrl }, + title: shareTitle, + description: shareDescription, + imageUrl: shareImageUrl, + link: { mobileWebUrl: videoPageUrl, webUrl: videoPageUrl }, }, - buttons: [{ title: t('videoDetail.kakaoButtonTitle'), link: { mobileWebUrl: shareUrl, webUrl: shareUrl } }], + buttons: [{ title: t('videoDetail.kakaoButtonTitle'), link: { mobileWebUrl: videoPageUrl, webUrl: videoPageUrl } }], }); } else if (navigator.share) { - navigator.share({ url: shareUrl }).catch(() => {}); + navigator.share({ title: shareTitle, text: shareDescription, url: shareUrl }).catch(() => {}); } else { handleCopyLink(); } @@ -147,6 +152,20 @@ const VideoDetailContent: React.FC = ({ videoId, isModa const shareMenuRef = React.useRef(null); + const handleShareButtonClick = async () => { + const handled = await tryNativeShare({ + title: shareTitle, + text: shareDescription, + url: shareUrl, + }); + if (handled) { + setShareMenuOpen(false); + return; + } + + setShareMenuOpen((open) => !open); + }; + useEffect(() => { if (!shareMenuOpen) return; const handleClickOutside = (e: MouseEvent) => { @@ -197,13 +216,11 @@ const VideoDetailContent: React.FC = ({ videoId, isModa if (!commentInput.trim() || commentSubmitting) return; setCommentSubmitting(true); try { - await postVideoComment(videoId, commentInput.trim(), commentNickname); + await postVideoComment(videoId, commentInput.trim()); setCommentInput(''); if (commentTextareaRef.current) { commentTextareaRef.current.style.height = 'auto'; } - setCommentNickname(''); - setCommentAvatarSeedIdx(prev => (prev + 1) % AVATAR_SEEDS.length); await fetchComments(1); } catch (err) { console.error('Failed to post comment:', err); @@ -287,7 +304,7 @@ const VideoDetailContent: React.FC = ({ videoId, isModa
- {/* 댓글 작성자 프로필 선택 */} - {authed && ( + {/* 댓글 작성자 프로필 (카카오 로그인 정보) */} + {authed && currentUser && (
- {t('videoDetail.changeAvatarTitle')} - setCommentNickname(e.target.value)} - maxLength={20} - /> + {currentUser.profile_image_url && ( + {currentUser.nickname} + )} + {currentUser.nickname}
)} @@ -398,11 +407,13 @@ const VideoDetailContent: React.FC = ({ videoId, isModa
    {comments.map((c) => (
  • - avatar + {c.profile_image_url && ( + {c.nickname + )}
    {c.nickname || t('videoDetail.anonymous')} @@ -427,11 +438,13 @@ const VideoDetailContent: React.FC = ({ videoId, isModa
      {c.replies.map((r) => (
    • - avatar + {r.profile_image_url && ( + {r.nickname + )}
      {r.nickname || t('videoDetail.anonymous')} diff --git a/src/locales/en.json b/src/locales/en.json index b649a24..bf52e42 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -630,8 +630,6 @@ "shareTwitter": "X (Twitter)", "copyUrl": "Copy URL", "commentsTitle": "Comments", - "changeAvatarTitle": "Click to change avatar", - "nicknamePlaceholder": "Author name", "commentPlaceholder": "Write a comment...", "commentLoginRequired": "Please log in to write a comment", "commentSubmitting": "Submitting", diff --git a/src/locales/ko.json b/src/locales/ko.json index 25270d1..d83cfbd 100644 --- a/src/locales/ko.json +++ b/src/locales/ko.json @@ -629,8 +629,6 @@ "shareTwitter": "X (트위터)", "copyUrl": "URL 복사", "commentsTitle": "댓글", - "changeAvatarTitle": "클릭하여 아바타 변경", - "nicknamePlaceholder": "작성자 이름", "commentPlaceholder": "댓글을 입력하세요...", "commentLoginRequired": "로그인 후 댓글을 작성할 수 있습니다", "commentSubmitting": "작성 중", diff --git a/src/pages/Dashboard/ADO2ContentsPage.tsx b/src/pages/Dashboard/ADO2ContentsPage.tsx index 002e9a5..249f912 100644 --- a/src/pages/Dashboard/ADO2ContentsPage.tsx +++ b/src/pages/Dashboard/ADO2ContentsPage.tsx @@ -151,7 +151,15 @@ const ADO2ContentsPage: React.FC = () => { onKeyDown={(e) => e.key === 'Enter' && handleCardClick(video.video_id)} >
      - {video.thumbnail_url ? ( + {video.poster_url ? ( + {video.store_name} + ) : video.thumbnail_url ? ( {video.store_name} = () => { videoId={video.video_id} storeName={video.store_name} region={video.region} + posterUrl={video.poster_url} commentCount={video.comment_count ?? 0} initialLikeCount={video.like_count ?? 0} initialIsLiked={video.is_liked_by_me} diff --git a/src/pages/Dashboard/CompletionContent.tsx b/src/pages/Dashboard/CompletionContent.tsx index ab95013..245dec4 100755 --- a/src/pages/Dashboard/CompletionContent.tsx +++ b/src/pages/Dashboard/CompletionContent.tsx @@ -563,6 +563,7 @@ const CompletionContent: React.FC = ({ created_at: new Date().toISOString(), like_count: 0, comment_count: 0, + is_liked_by_me: false, } : null} /> diff --git a/src/pages/Dashboard/MyContentsPage.tsx b/src/pages/Dashboard/MyContentsPage.tsx index b479c41..3212aae 100644 --- a/src/pages/Dashboard/MyContentsPage.tsx +++ b/src/pages/Dashboard/MyContentsPage.tsx @@ -248,7 +248,15 @@ const MyContentsPage: React.FC = ({ onNavigate }) => { style={{ cursor: 'pointer' }} onClick={() => setSelectedVideoId(video.video_id)} > - {video.result_movie_url ? ( + {video.poster_url ? ( + {video.store_name} + ) : video.result_movie_url ? ( = ({ onNavigate }) => { videoId={video.video_id} storeName={video.store_name} region={video.region} + posterUrl={video.poster_url} commentCount={video.comment_count ?? 0} initialLikeCount={video.like_count ?? 0} initialIsLiked={video.is_liked_by_me} diff --git a/src/types/api.ts b/src/types/api.ts index 253befc..e75525c 100644 --- a/src/types/api.ts +++ b/src/types/api.ts @@ -276,17 +276,19 @@ export interface VideoListItem { region: string; task_id: string; result_movie_url: string; + poster_url?: string | null; thumbnail_url?: string; created_at: string; like_count: number; comment_count: number; - is_liked_by_me?: boolean; + is_liked_by_me: boolean; } // 비디오 상세 아이템 export interface VideoDetailItem { video_id: number; result_movie_url: string; + poster_url?: string | null; store_name: string; region: string; created_at: string; @@ -309,6 +311,7 @@ export interface VideosListResponse { export interface CommentReply { id: number; nickname: string; + profile_image_url: string | null; content: string | null; is_deleted: boolean; is_mine: boolean; @@ -319,6 +322,7 @@ export interface CommentReply { export interface CommentItem { id: number; nickname: string; + profile_image_url: string | null; content: string | null; is_deleted: boolean; is_mine: boolean; diff --git a/src/utils/api.ts b/src/utils/api.ts index 80bdb3a..4fbd0e3 100644 --- a/src/utils/api.ts +++ b/src/utils/api.ts @@ -609,12 +609,12 @@ export async function getVideoComments(videoId: string, page: number = 1, pageSi return response.json(); } -// 댓글 작성 -export async function postVideoComment(videoId: string, content: string, nickname?: string, parentId?: number): Promise { +// 댓글 작성 (작성자 닉네임/프로필은 서버가 로그인된 카카오 정보로 채움) +export async function postVideoComment(videoId: string, content: string, parentId?: number): Promise { const response = await authenticatedFetch(`${API_URL}/comment/video/${videoId}`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ content, nickname: nickname || '익명', parent_id: parentId ?? null }), + body: JSON.stringify({ content, parent_id: parentId ?? null }), }); if (!response.ok) { diff --git a/src/utils/nativeShare.ts b/src/utils/nativeShare.ts new file mode 100644 index 0000000..7946064 --- /dev/null +++ b/src/utils/nativeShare.ts @@ -0,0 +1,27 @@ +/** + * 기기의 네이티브 공유 시트를 열고 요청을 처리했는지 반환합니다. + * + * 사용자가 공유 시트를 닫은 경우도 정상적으로 처리된 것으로 간주해 + * 별도의 공유 메뉴가 뒤이어 열리지 않도록 합니다. + */ +export async function tryNativeShare(data: ShareData): Promise { + if (typeof navigator.share !== 'function') { + return false; + } + + try { + await navigator.share(data); + return true; + } catch (error) { + if (error instanceof Error && error.name === 'AbortError') { + return true; + } + + return false; + } +} + +/** API 서버가 제공하는 영상별 Open Graph 공유 페이지 URL을 만듭니다. */ +export function buildVideoShareUrl(apiBaseUrl: string, videoId: number | string): string { + return `${apiBaseUrl.replace(/\/$/, '')}/video/share/${encodeURIComponent(String(videoId))}`; +}