feat: 영상 공유·포스터 썸네일·좋아요 상태를 서버 연동으로 전환

This commit is contained in:
skkim committed 2026-08-18 11:02:29 +09:00
1 parent 9c0c3de35f
commit 3566c1f7bc
10 files changed
+146 -69

No files matched your search

+27 -9
View File
@@ -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<ContentCardSocialActionsProps> = ({
videoId,
storeName,
region,
posterUrl,
commentCount,
initialLikeCount,
initialIsLiked = false,
@@ -33,7 +36,11 @@ const ContentCardSocialActions: React.FC<ContentCardSocialActionsProps> = ({
const shareMenuRef = useRef<HTMLDivElement>(null);
const likeDebounceRef = useRef<ReturnType<typeof setTimeout> | 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<ContentCardSocialActionsProps> = ({
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<ContentCardSocialActionsProps> = ({
}, 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가 실제 크기 기준으로 다시 보정한다