튜토리얼 추가

This commit is contained in:
skkim committed 2026-04-07 14:54:43 +09:00
1 parent d7cb0167ec
commit 5407812889
12 files changed
+1083 -4

No files matched your search

+4 -1
View File
@@ -12,11 +12,13 @@ interface SidebarItemProps {
isCollapsed: boolean;
isDisabled?: boolean;
onClick?: () => void;
id?: string;
}
const SidebarItem: React.FC<SidebarItemProps> = ({ icon, label, isActive, isCollapsed, isDisabled, onClick }) => {
const SidebarItem: React.FC<SidebarItemProps> = ({ icon, label, isActive, isCollapsed, isDisabled, onClick, id }) => {
return (
<div
id={id}
onClick={isDisabled ? undefined : onClick}
className={`sidebar-item ${isActive ? 'active' : ''} ${isCollapsed ? 'collapsed' : ''} ${isDisabled ? 'disabled' : ''}`}
title={isCollapsed ? label : ""}
@@ -138,6 +140,7 @@ const Sidebar: React.FC<SidebarProps> = ({ activeItem, onNavigate, onHome, userI
{menuItems.map(item => (
<SidebarItem
key={item.id}
id={item.id === '내 정보' ? 'sidebar-my-info' : undefined}
icon={item.icon}
label={item.label}
isCollapsed={isCollapsed}
+23
View File
@@ -4,6 +4,9 @@ import { useTranslation } from 'react-i18next';
import { getSocialAccounts, uploadToSocial, waitForUploadComplete, TokenExpiredError, handleSocialReconnect, getAutoSeoYoutube } from '../utils/api';
import { SocialAccount, VideoListItem, SocialUploadStatusResponse } from '../types/api';
import UploadProgressModal, { UploadStatus } from './UploadProgressModal';
import { useTutorial } from './Tutorial/useTutorial';
import { TUTORIAL_KEYS } from './Tutorial/tutorialSteps';
import TutorialOverlay from './Tutorial/TutorialOverlay';
interface SocialPostingModalProps {
isOpen: boolean;
@@ -116,6 +119,7 @@ const SocialPostingModal: React.FC<SocialPostingModalProps> = ({
video
}) => {
const { t } = useTranslation();
const tutorial = useTutorial();
const [socialAccounts, setSocialAccounts] = useState<SocialAccount[]>([]);
const [selectedChannel, setSelectedChannel] = useState<string>('');
const [title, setTitle] = useState('');
@@ -171,6 +175,16 @@ const SocialPostingModal: React.FC<SocialPostingModalProps> = ({
return () => { document.body.style.overflow = ''; };
}, [isOpen]);
// 모달 최초 오픈 시 튜토리얼 트리거
useEffect(() => {
if (isOpen && !tutorial.hasSeen(TUTORIAL_KEYS.UPLOAD_MODAL)) {
const timer = setTimeout(() => {
tutorial.startTutorial(TUTORIAL_KEYS.UPLOAD_MODAL);
}, 400);
return () => clearTimeout(timer);
}
}, [isOpen]);
// 소셜 계정 로드
useEffect(() => {
if (isOpen) {
@@ -761,6 +775,15 @@ const SocialPostingModal: React.FC<SocialPostingModalProps> = ({
</div>
</div>
{uploadProgressModalElement}
{tutorial.isActive && (
<TutorialOverlay
hints={tutorial.hints}
currentIndex={tutorial.currentHintIndex}
onNext={tutorial.nextHint}
onPrev={tutorial.prevHint}
onSkip={tutorial.skipTutorial}
/>
)}
</>
);
};
+217
View File
@@ -0,0 +1,217 @@
import React, { useEffect, useState, useCallback } from 'react';
import { useTranslation } from 'react-i18next';
import { TutorialHint } from './tutorialSteps';
interface Rect {
top: number;
left: number;
width: number;
height: number;
}
interface TooltipPos {
top: number;
left: number;
}
interface TutorialOverlayProps {
hints: TutorialHint[];
currentIndex: number;
onNext: () => void;
onPrev: () => void;
onSkip: () => void;
}
const PADDING = 8;
function getTargetRect(selector: string): Rect | null {
const el = document.querySelector(selector);
if (!el) return null;
const r = el.getBoundingClientRect();
return { top: r.top, left: r.left, width: r.width, height: r.height };
}
function calcTooltipPos(rect: Rect, position: TutorialHint['position']): TooltipPos {
const tooltipW = 300;
const tooltipH = 140;
switch (position) {
case 'bottom':
return {
top: rect.top + rect.height + PADDING,
left: Math.min(
Math.max(rect.left + rect.width / 2 - tooltipW / 2, 8),
window.innerWidth - tooltipW - 8
),
};
case 'top':
return {
top: rect.top - tooltipH - PADDING,
left: Math.min(
Math.max(rect.left + rect.width / 2 - tooltipW / 2, 8),
window.innerWidth - tooltipW - 8
),
};
case 'right':
return {
top: Math.max(rect.top + rect.height / 2 - tooltipH / 2, 8),
left: rect.left + rect.width + PADDING,
};
case 'left':
return {
top: Math.max(rect.top + rect.height / 2 - tooltipH / 2, 8),
left: rect.left - tooltipW - PADDING,
};
}
}
const TutorialOverlay: React.FC<TutorialOverlayProps> = ({
hints,
currentIndex,
onNext,
onPrev,
onSkip,
}) => {
const { t } = useTranslation();
const [targetRect, setTargetRect] = useState<Rect | null>(null);
const hint = hints[currentIndex];
const isLast = currentIndex === hints.length - 1;
const updateRect = useCallback(() => {
if (!hint) return;
setTargetRect(getTargetRect(hint.targetSelector));
}, [hint]);
useEffect(() => {
updateRect();
window.addEventListener('resize', updateRect);
return () => window.removeEventListener('resize', updateRect);
}, [updateRect]);
// 대상 요소 z-index 끌어올리기 + 스크롤 + 클릭 시 onNext 연결
useEffect(() => {
if (!hint) return;
const el = document.querySelector<HTMLElement>(hint.targetSelector);
if (!el) return;
// 스크롤해서 요소가 화면 중앙에 오도록
el.scrollIntoView({ behavior: 'smooth', block: 'center' });
// scrollIntoView 완료 후 rect 재계산
const timer = setTimeout(updateRect, 400);
const prevZ = el.style.zIndex;
const prevPos = el.style.position;
const prevCursor = el.style.cursor;
el.style.zIndex = '10001';
el.style.position = el.style.position || 'relative';
// clickToAdvance가 명시적으로 false가 아닌 경우에만 클릭 리스너 연결
const shouldClickAdvance = hint.clickToAdvance !== false;
if (shouldClickAdvance) {
el.style.cursor = 'pointer';
el.addEventListener('click', onNext);
}
return () => {
clearTimeout(timer);
el.style.zIndex = prevZ;
el.style.position = prevPos;
el.style.cursor = prevCursor;
if (shouldClickAdvance) {
el.removeEventListener('click', onNext);
}
};
}, [hint, updateRect, onNext]);
if (!hint) return null;
// 대상 요소가 없으면 화면 중앙에 툴팁 표시 (오버레이는 보이지 않음)
const tooltipPos: TooltipPos = targetRect
? calcTooltipPos(targetRect, hint.position)
: {
top: window.innerHeight / 2 - 70,
left: window.innerWidth / 2 - 150,
};
// spotlight SVG 경로: 화면 전체 - 대상 요소 구멍
// 대상 요소가 없으면 오버레이 없음
const spotlight = targetRect
? `M0,0 H${window.innerWidth} V${window.innerHeight} H0 Z
M${targetRect.left - PADDING},${targetRect.top - PADDING}
H${targetRect.left + targetRect.width + PADDING}
V${targetRect.top + targetRect.height + PADDING}
H${targetRect.left - PADDING} Z`
: null;
return (
<div className="tutorial-overlay-root">
{/* 어두운 배경 + 스포트라이트 — 배경 클릭 시 아무 동작 없음 */}
{spotlight && (
<svg className="tutorial-overlay-svg">
<path
d={spotlight}
fillRule="evenodd"
fill="rgba(0,0,0,0.72)"
/>
</svg>
)}
{/* 툴팁 — 항상 표시 */}
<div
className="tutorial-tooltip"
style={{ top: tooltipPos.top, left: tooltipPos.left }}
onClick={e => e.stopPropagation()}
>
<p className="tutorial-tooltip-title">{t(hint.titleKey)}</p>
<p className="tutorial-tooltip-desc">{t(hint.descriptionKey)}</p>
<div className="tutorial-tooltip-footer">
<span className="tutorial-tooltip-counter">
{currentIndex + 1} / {hints.length}
</span>
<div className="tutorial-tooltip-actions">
<button className="tutorial-btn-skip" onClick={onSkip}>
{t('tutorial.skip')}
</button>
{currentIndex > 0 && (
<button className="tutorial-btn-prev" onClick={onPrev}>
{t('tutorial.prev')}
</button>
)}
<button className="tutorial-btn-next" onClick={onNext}>
{isLast ? t('tutorial.finish') : t('tutorial.next')}
</button>
</div>
</div>
</div>
</div>
);
};
export default TutorialOverlay;
interface TutorialRestartPopupProps {
onConfirm: () => void;
onCancel: () => void;
}
export const TutorialRestartPopup: React.FC<TutorialRestartPopupProps> = ({ onConfirm, onCancel }) => {
const { t } = useTranslation();
return (
<div className="tutorial-restart-backdrop">
<div className="tutorial-restart-popup" onClick={e => e.stopPropagation()}>
<p className="tutorial-restart-title">{t('tutorial.restart.title')}</p>
<p className="tutorial-restart-desc">{t('tutorial.restart.desc')}</p>
<div className="tutorial-restart-actions">
<button className="tutorial-restart-cancel" onClick={onCancel}>
{t('tutorial.restart.cancel')}
</button>
<button className="tutorial-restart-confirm" onClick={onConfirm}>
{t('tutorial.restart.confirm')}
</button>
</div>
</div>
</div>
);
};
+247
View File
@@ -0,0 +1,247 @@
export interface TutorialHint {
targetSelector: string;
titleKey: string;
descriptionKey: string;
position: 'top' | 'bottom' | 'left' | 'right';
clickToAdvance?: boolean; // true면 요소 클릭 시 튜토리얼 진행, false면 툴팁 버튼으로만 진행
}
export interface TutorialStepDef {
key: string;
hints: TutorialHint[];
}
export const TUTORIAL_KEYS = {
LANDING: 'landing',
ANALYSIS: 'analysis',
ASSET: 'asset',
SOUND: 'sound',
COMPLETION: 'completion',
MY_INFO: 'myInfo',
ADO2_CONTENTS: 'ado2Contents',
UPLOAD_MODAL: 'uploadModal',
DASHBOARD: 'dashboard',
FEEDBACK: 'feedback',
} as const;
export const tutorialSteps: TutorialStepDef[] = [
{
key: TUTORIAL_KEYS.LANDING,
hints: [
{
targetSelector: '.hero-dropdown-container',
titleKey: 'tutorial.landing.dropdown.title',
descriptionKey: 'tutorial.landing.dropdown.desc',
position: 'bottom',
},
{
targetSelector: '.hero-input-container',
titleKey: 'tutorial.landing.field.title',
descriptionKey: 'tutorial.landing.field.desc',
position: 'bottom',
},
{
targetSelector: '.hero-button',
titleKey: 'tutorial.landing.button.title',
descriptionKey: 'tutorial.landing.button.desc',
position: 'top',
},
],
},
{
key: TUTORIAL_KEYS.ANALYSIS,
hints: [
{
targetSelector: '.bi2-identity-card',
titleKey: 'tutorial.analysis.identity.title',
descriptionKey: 'tutorial.analysis.identity.desc',
position: 'bottom',
clickToAdvance: false,
},
{
targetSelector: '.bi2-selling-card',
titleKey: 'tutorial.analysis.selling.title',
descriptionKey: 'tutorial.analysis.selling.desc',
position: 'bottom',
clickToAdvance: false,
},
{
targetSelector: '.bi2-persona-grid',
titleKey: 'tutorial.analysis.persona.title',
descriptionKey: 'tutorial.analysis.persona.desc',
position: 'bottom',
clickToAdvance: false,
},
{
targetSelector: '.bi2-keyword-tags',
titleKey: 'tutorial.analysis.keywords.title',
descriptionKey: 'tutorial.analysis.keywords.desc',
position: 'bottom',
clickToAdvance: false,
},
{
targetSelector: '.bi2-generate-btn',
titleKey: 'tutorial.analysis.generate.title',
descriptionKey: 'tutorial.analysis.generate.desc',
position: 'top',
clickToAdvance: true,
},
],
},
{
key: TUTORIAL_KEYS.ASSET,
hints: [
{
targetSelector: '.asset-upload-zone',
titleKey: 'tutorial.asset.upload.title',
descriptionKey: 'tutorial.asset.upload.desc',
position: 'left',
},
{
targetSelector: '.asset-ratio-section',
titleKey: 'tutorial.asset.ratio.title',
descriptionKey: 'tutorial.asset.ratio.desc',
position: 'left',
},
{
targetSelector: '.asset-next-button',
titleKey: 'tutorial.asset.next.title',
descriptionKey: 'tutorial.asset.next.desc',
position: 'top',
},
],
},
{
key: TUTORIAL_KEYS.SOUND,
hints: [
{
targetSelector: '.genre-grid',
titleKey: 'tutorial.sound.genre.title',
descriptionKey: 'tutorial.sound.genre.desc',
position: 'right',
clickToAdvance: false,
},
{
targetSelector: '.language-selector-wrapper',
titleKey: 'tutorial.sound.language.title',
descriptionKey: 'tutorial.sound.language.desc',
position: 'right',
clickToAdvance: false,
},
{
targetSelector: '.btn-generate-sound',
titleKey: 'tutorial.sound.generate.title',
descriptionKey: 'tutorial.sound.generate.desc',
position: 'top',
clickToAdvance: true,
},
{
targetSelector: '.btn-video-generate',
titleKey: 'tutorial.sound.video.title',
descriptionKey: 'tutorial.sound.video.desc',
position: 'top',
clickToAdvance: true,
},
],
},
{
key: TUTORIAL_KEYS.MY_INFO,
hints: [
{
targetSelector: '.youtube-connect-section',
titleKey: 'tutorial.myInfo.connect.title',
descriptionKey: 'tutorial.myInfo.connect.desc',
position: 'bottom',
},
{
targetSelector: '.youtube-connect-button',
titleKey: 'tutorial.myInfo.button.title',
descriptionKey: 'tutorial.myInfo.button.desc',
position: 'top',
},
],
},
{
key: TUTORIAL_KEYS.ADO2_CONTENTS,
hints: [
{
targetSelector: '.ado2-contents-list',
titleKey: 'tutorial.ado2.list.title',
descriptionKey: 'tutorial.ado2.list.desc',
position: 'bottom',
},
{
targetSelector: '.ado2-upload-button',
titleKey: 'tutorial.ado2.upload.title',
descriptionKey: 'tutorial.ado2.upload.desc',
position: 'top',
},
],
},
{
key: TUTORIAL_KEYS.COMPLETION,
hints: [
{
targetSelector: '#sidebar-my-info',
titleKey: 'tutorial.completion.myInfo.title',
descriptionKey: 'tutorial.completion.myInfo.desc',
position: 'right',
clickToAdvance: true,
},
],
},
{
key: TUTORIAL_KEYS.UPLOAD_MODAL,
hints: [
{
targetSelector: '.social-posting-field',
titleKey: 'tutorial.upload.title.title',
descriptionKey: 'tutorial.upload.title.desc',
position: 'left',
clickToAdvance: false,
},
{
targetSelector: '.social-posting-radio-group',
titleKey: 'tutorial.upload.schedule.title',
descriptionKey: 'tutorial.upload.schedule.desc',
position: 'left',
clickToAdvance: false,
},
{
targetSelector: '.social-posting-btn:not(.cancel)',
titleKey: 'tutorial.upload.submit.title',
descriptionKey: 'tutorial.upload.submit.desc',
position: 'top',
clickToAdvance: true,
},
],
},
{
key: TUTORIAL_KEYS.DASHBOARD,
hints: [
{
targetSelector: '.dashboard-metrics-row',
titleKey: 'tutorial.dashboard.metrics.title',
descriptionKey: 'tutorial.dashboard.metrics.desc',
position: 'bottom',
},
{
targetSelector: '.dashboard-chart-section',
titleKey: 'tutorial.dashboard.chart.title',
descriptionKey: 'tutorial.dashboard.chart.desc',
position: 'top',
},
],
},
{
key: TUTORIAL_KEYS.FEEDBACK,
hints: [
{
targetSelector: '.sidebar-inquiry-btn',
titleKey: 'tutorial.feedback.title',
descriptionKey: 'tutorial.feedback.desc',
position: 'right',
},
],
},
];
+115
View File
@@ -0,0 +1,115 @@
import { useState, useCallback } from 'react';
import { tutorialSteps, TutorialHint } from './tutorialSteps';
const SEEN_KEY = 'castad_tutorial_seen';
function getSeenKeys(): string[] {
try {
return JSON.parse(localStorage.getItem(SEEN_KEY) || '[]');
} catch {
return [];
}
}
function markSeen(key: string) {
const seen = getSeenKeys();
if (!seen.includes(key)) {
localStorage.setItem(SEEN_KEY, JSON.stringify([...seen, key]));
}
}
interface UseTutorialReturn {
isActive: boolean;
isRestartPopupVisible: boolean;
currentHintIndex: number;
hints: TutorialHint[];
tutorialKey: string | null;
startTutorial: (key: string) => void;
nextHint: () => void;
prevHint: () => void;
skipTutorial: () => void;
showRestartPopup: (key: string) => void;
confirmRestart: () => void;
cancelRestart: () => void;
hasSeen: (key: string) => boolean;
}
export function useTutorial(): UseTutorialReturn {
const [isActive, setIsActive] = useState(false);
const [isRestartPopupVisible, setIsRestartPopupVisible] = useState(false);
const [pendingRestartKey, setPendingRestartKey] = useState<string | null>(null);
const [currentHintIndex, setCurrentHintIndex] = useState(0);
const [hints, setHints] = useState<TutorialHint[]>([]);
const [tutorialKey, setTutorialKey] = useState<string | null>(null);
const startTutorial = useCallback((key: string) => {
const step = tutorialSteps.find(s => s.key === key);
if (!step || step.hints.length === 0) return;
setHints(step.hints);
setTutorialKey(key);
setCurrentHintIndex(0);
setIsActive(true);
}, []);
const nextHint = useCallback(() => {
setCurrentHintIndex(prev => {
if (prev < hints.length - 1) return prev + 1;
// 마지막 힌트 완료 → seen 기록
setIsActive(false);
if (tutorialKey) markSeen(tutorialKey);
return 0;
});
}, [hints.length, tutorialKey]);
const prevHint = useCallback(() => {
setCurrentHintIndex(prev => Math.max(0, prev - 1));
}, []);
// 건너뛰기: 오버레이만 닫고 seen 기록 안 함 → 다음 방문 시 다시 표시
const skipTutorial = useCallback(() => {
setIsActive(false);
setCurrentHintIndex(0);
}, []);
// 튜토리얼 다시 보기: 팝업 표시만
const showRestartPopup = useCallback((key: string) => {
setPendingRestartKey(key);
setIsRestartPopupVisible(true);
}, []);
// 팝업에서 확인 → seen 초기화 후 튜토리얼 시작
const confirmRestart = useCallback(() => {
setIsRestartPopupVisible(false);
if (pendingRestartKey) {
localStorage.removeItem(SEEN_KEY);
startTutorial(pendingRestartKey);
}
setPendingRestartKey(null);
}, [pendingRestartKey, startTutorial]);
// 팝업에서 취소
const cancelRestart = useCallback(() => {
setIsRestartPopupVisible(false);
setPendingRestartKey(null);
}, []);
const hasSeen = useCallback((key: string) => {
return getSeenKeys().includes(key);
}, []);
return {
isActive,
isRestartPopupVisible,
currentHintIndex,
hints,
tutorialKey,
startTutorial,
nextHint,
prevHint,
skipTutorial,
showRestartPopup,
confirmRestart,
cancelRestart,
hasSeen,
};
}