feat(ssulbox): 상세·공유 화면과 좋아요·댓글·업로드 연동

This commit is contained in:
skkim committed 2026-08-11 14:57:34 +09:00
1 parent 7b1e691715
commit 741539a023
12 files changed
+836 -293

No files matched your search

+22 -3
View File
@@ -1,10 +1,17 @@
import React, { useEffect, useLayoutEffect, useRef, useState } from 'react';
import { createPortal } from 'react-dom';
import { useTranslation } from 'react-i18next';
import { toggleVideoLike } from '../utils/api';
import { toggleVideoLike, isLoggedIn } from '../utils/api';
import { ContentType } from '../types/api';
import LoginPromptModal from './LoginPromptModal';
interface ContentCardSocialActionsProps {
videoId: number;
/**
* 콘텐츠 종류. video.id 와 ssul_content.id 가 겹치므로 좋아요 API 와
* 공유 URL(/video/{id} vs /ssul/{id}) 분기에 반드시 필요하다.
*/
contentType?: ContentType;
storeName: string;
region?: string;
commentCount: number;
@@ -14,6 +21,7 @@ interface ContentCardSocialActionsProps {
const ContentCardSocialActions: React.FC<ContentCardSocialActionsProps> = ({
videoId,
contentType = 'video',
storeName,
region,
commentCount,
@@ -24,6 +32,7 @@ const ContentCardSocialActions: React.FC<ContentCardSocialActionsProps> = ({
const [likeCount, setLikeCount] = useState(initialLikeCount);
const [isLiked, setIsLiked] = useState(initialIsLiked);
const [showLoginModal, setShowLoginModal] = useState(false);
const [copied, setCopied] = useState(false);
const [shareMenuOpen, setShareMenuOpen] = useState(false);
const [menuPos, setMenuPos] = useState<{ top: number; left: number } | null>(null);
@@ -33,7 +42,8 @@ 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}`;
// 종류별 공개 페이지가 다르다 — 합치면 id 가 겹치는 다른 콘텐츠가 열린다
const shareUrl = `${window.location.origin}/${contentType === 'ssul' ? 'ssul' : 'video'}/${videoId}`;
useEffect(() => {
if (!shareMenuOpen) return;
@@ -124,6 +134,11 @@ const ContentCardSocialActions: React.FC<ContentCardSocialActionsProps> = ({
const handleLikeClick = (e: React.MouseEvent) => {
e.stopPropagation();
if (!isLoggedIn()) {
setShowLoginModal(true);
return;
}
const prevLiked = isLiked;
const prevCount = likeCount;
@@ -133,7 +148,7 @@ const ContentCardSocialActions: React.FC<ContentCardSocialActionsProps> = ({
if (likeDebounceRef.current) clearTimeout(likeDebounceRef.current);
likeDebounceRef.current = setTimeout(async () => {
try {
const res = await toggleVideoLike(String(videoId));
const res = await toggleVideoLike(String(videoId), contentType);
setIsLiked(res.is_liked);
setLikeCount(res.like_count);
} catch (err) {
@@ -221,6 +236,10 @@ const ContentCardSocialActions: React.FC<ContentCardSocialActionsProps> = ({
</div>,
document.body
)}
{showLoginModal && (
<LoginPromptModal onClose={() => setShowLoginModal(false)} />
)}
</div>
);
};