튜토리얼 수정

This commit is contained in:
skkim committed 2026-04-13 16:17:27 +09:00
1 parent f0d9106860
commit 8734d3388d
12 files changed
+541 -174

No files matched your search

+7 -1
View File
@@ -140,7 +140,13 @@ const Sidebar: React.FC<SidebarProps> = ({ activeItem, onNavigate, onHome, userI
{menuItems.map(item => (
<SidebarItem
key={item.id}
id={item.id === '내 정보' ? 'sidebar-my-info' : undefined}
id={
item.id === '내 정보'
? 'sidebar-my-info'
: item.id === 'ADO2 콘텐츠'
? 'sidebar-ado2-contents'
: undefined
}
icon={item.icon}
label={item.label}
isCollapsed={isCollapsed}
+35 -6
View File
@@ -139,6 +139,7 @@ const SocialPostingModal: React.FC<SocialPostingModalProps> = ({
const [videoMeta, setVideoMeta] = useState<{ width: number; height: number; duration: number } | null>(null);
const channelDropdownRef = useRef<HTMLDivElement>(null);
const privacyDropdownRef = useRef<HTMLDivElement>(null);
const hasBeenOpenedRef = useRef(false);
// Upload progress modal state
const [showUploadProgress, setShowUploadProgress] = useState(false);
@@ -175,15 +176,31 @@ const SocialPostingModal: React.FC<SocialPostingModalProps> = ({
return () => { document.body.style.overflow = ''; };
}, [isOpen]);
// 모달 최초 오픈 시 튜토리얼 트리거
// 모달 오픈/닫힘 시 튜토리얼 트리거
useEffect(() => {
if (isOpen && !tutorial.hasSeen(TUTORIAL_KEYS.UPLOAD_MODAL)) {
if (isOpen) {
hasBeenOpenedRef.current = true;
if (!tutorial.hasSeen(TUTORIAL_KEYS.UPLOAD_MODAL)) {
const timer = setTimeout(() => {
tutorial.startTutorial(TUTORIAL_KEYS.UPLOAD_MODAL);
}, 400);
return () => clearTimeout(timer);
}
} else if (hasBeenOpenedRef.current && !tutorial.hasSeen(TUTORIAL_KEYS.FEEDBACK)) {
hasBeenOpenedRef.current = false;
tutorial.startTutorial(TUTORIAL_KEYS.FEEDBACK);
}
}, [isOpen]);
// SEO 생성 완료 시 UPLOAD_FORM 튜토리얼 트리거
useEffect(() => {
if (!isLoadingAutoDescription && isOpen && !tutorial.hasSeen(TUTORIAL_KEYS.UPLOAD_FORM)) {
const timer = setTimeout(() => {
tutorial.startTutorial(TUTORIAL_KEYS.UPLOAD_MODAL);
tutorial.startTutorial(TUTORIAL_KEYS.UPLOAD_FORM);
}, 400);
return () => clearTimeout(timer);
}
}, [isOpen]);
}, [isLoadingAutoDescription]);
// 소셜 계정 로드
useEffect(() => {
@@ -413,8 +430,20 @@ const SocialPostingModal: React.FC<SocialPostingModalProps> = ({
);
if (!isOpen || !video) {
// Still render upload progress modal even when main modal is closed
return showUploadProgress ? uploadProgressModalElement : null;
return (
<>
{showUploadProgress && uploadProgressModalElement}
{tutorial.isActive && (
<TutorialOverlay
hints={tutorial.hints}
currentIndex={tutorial.currentHintIndex}
onNext={tutorial.nextHint}
onPrev={tutorial.prevHint}
onSkip={tutorial.skipTutorial}
/>
)}
</>
);
}
return (
+140 -81
View File
@@ -31,6 +31,28 @@ function getTargetRect(selector: string): Rect | null {
return { top: r.top, left: r.left, width: r.width, height: r.height };
}
function getSpotlightRect(
rect: Rect,
padding: number,
override?: { top?: number; right?: number; bottom?: number; left?: number }
): Rect {
const pTop = override?.top ?? padding;
const pRight = override?.right ?? padding;
const pBottom = override?.bottom ?? padding;
const pLeft = override?.left ?? padding;
const left = Math.max(0, Math.floor(rect.left - pLeft));
const top = Math.max(0, Math.floor(rect.top - pTop));
const right = Math.min(window.innerWidth, Math.ceil(rect.left + rect.width + pRight));
const bottom = Math.min(window.innerHeight, Math.ceil(rect.top + rect.height + pBottom));
return {
top,
left,
width: Math.max(0, right - left),
height: Math.max(0, bottom - top),
};
}
function calcTooltipPos(rect: Rect, position: TutorialHint['position']): TooltipPos {
const tooltipW = 300;
const tooltipH = 140;
@@ -38,29 +60,23 @@ function calcTooltipPos(rect: Rect, position: TutorialHint['position']): Tooltip
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
),
top: Math.min(rect.top + rect.height + PADDING, window.innerHeight - tooltipH - 8),
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
),
top: Math.max(rect.top - tooltipH - PADDING, 8),
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,
top: Math.min(Math.max(rect.top + rect.height / 2 - tooltipH / 2, 8), window.innerHeight - tooltipH - 8),
left: Math.min(rect.left + rect.width + PADDING, window.innerWidth - tooltipW - 8),
};
case 'left':
return {
top: Math.max(rect.top + rect.height / 2 - tooltipH / 2, 8),
left: rect.left - tooltipW - PADDING,
top: Math.min(Math.max(rect.top + rect.height / 2 - tooltipH / 2, 8), window.innerHeight - tooltipH - 8),
left: Math.max(rect.left - tooltipW - PADDING, 8),
};
}
}
@@ -86,47 +102,62 @@ const TutorialOverlay: React.FC<TutorialOverlayProps> = ({
useEffect(() => {
updateRect();
window.addEventListener('resize', updateRect);
return () => window.removeEventListener('resize', updateRect);
window.addEventListener('scroll', updateRect, true);
return () => {
window.removeEventListener('resize', updateRect);
window.removeEventListener('scroll', updateRect, true);
};
}, [updateRect]);
// 대상 요소 z-index 끌어올리기 + 스크롤 + 클릭 시 onNext 연결
useEffect(() => {
if (!hint) return;
const el = document.querySelector<HTMLElement>(hint.targetSelector);
if (!el) return;
let retryTimer: number | undefined;
let rectTimer: number | undefined;
let cleanupTarget: (() => void) | undefined;
// 스크롤해서 요소가 화면 중앙에 오도록
el.scrollIntoView({ behavior: 'smooth', block: 'center' });
const bindToTarget = (el: HTMLElement) => {
el.scrollIntoView({ behavior: 'smooth', block: 'center' });
rectTimer = window.setTimeout(updateRect, 200);
// scrollIntoView 완료 후 rect 재계산
const timer = setTimeout(updateRect, 400);
const shouldClickAdvance = hint.clickToAdvance !== false;
if (shouldClickAdvance) {
el.style.cursor = 'pointer';
el.addEventListener('click', onNext);
}
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);
cleanupTarget = () => {
if (shouldClickAdvance) {
el.style.cursor = '';
el.removeEventListener('click', onNext);
}
};
};
const tryBind = (): boolean => {
const el = document.querySelector(hint.targetSelector) as HTMLElement | null;
if (!el) return false;
bindToTarget(el);
return true;
};
if (!tryBind()) {
retryTimer = window.setInterval(() => {
if (tryBind() && retryTimer) {
window.clearInterval(retryTimer);
retryTimer = undefined;
}
}, 80);
}
return () => {
clearTimeout(timer);
el.style.zIndex = prevZ;
el.style.position = prevPos;
el.style.cursor = prevCursor;
if (shouldClickAdvance) {
el.removeEventListener('click', onNext);
}
if (retryTimer) window.clearInterval(retryTimer);
if (rectTimer) window.clearTimeout(rectTimer);
cleanupTarget?.();
};
}, [hint, updateRect, onNext]);
if (!hint) return null;
// 대상 요소가 없으면 화면 중앙에 툴팁 표시 (오버레이는 보이지 않음)
const tooltipPos: TooltipPos = targetRect
? calcTooltipPos(targetRect, hint.position)
: {
@@ -134,57 +165,85 @@ const TutorialOverlay: React.FC<TutorialOverlayProps> = ({
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;
const spotlightPadding = hint.spotlightPadding ?? PADDING;
const spotlightRect = targetRect ? getSpotlightRect(targetRect, spotlightPadding, hint.spotlightPaddingOverride) : 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)"
{spotlightRect ? (
<>
<div
className="tutorial-overlay-blocker"
style={{ top: 0, left: 0, right: 0, height: spotlightRect.top }}
/>
</svg>
<div
className="tutorial-overlay-blocker"
style={{
top: spotlightRect.top,
left: 0,
width: spotlightRect.left,
height: spotlightRect.height,
}}
/>
<div
className="tutorial-overlay-blocker"
style={{
top: spotlightRect.top,
left: spotlightRect.left + spotlightRect.width,
right: 0,
height: spotlightRect.height,
}}
/>
<div
className="tutorial-overlay-blocker"
style={{
top: spotlightRect.top + spotlightRect.height,
left: 0,
right: 0,
bottom: 0,
}}
/>
<div
className="tutorial-spotlight-ring"
style={{
top: spotlightRect.top,
left: spotlightRect.left,
width: spotlightRect.width,
height: spotlightRect.height,
}}
/>
</>
) : (
<div className="tutorial-overlay-blocker" style={{ inset: 0 }} />
)}
{/* 툴팁 — 항상 표시 */}
<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>
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')}
<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>
{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>
)}
<button className="tutorial-btn-next" onClick={onNext}>
{isLast ? t('tutorial.finish') : t('tutorial.next')}
</button>
</div>
</div>
</div>
</div>
);
};
@@ -200,7 +259,7 @@ export const TutorialRestartPopup: React.FC<TutorialRestartPopupProps> = ({ onCo
const { t } = useTranslation();
return (
<div className="tutorial-restart-backdrop">
<div className="tutorial-restart-popup" onClick={e => e.stopPropagation()}>
<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">
+157 -25
View File
@@ -3,7 +3,10 @@ export interface TutorialHint {
titleKey: string;
descriptionKey: string;
position: 'top' | 'bottom' | 'left' | 'right';
clickToAdvance?: boolean; // true면 요소 클릭 시 튜토리얼 진행, false면 툴팁 버튼으로만 진행
clickToAdvance?: boolean;
advanceSelector?: string;
spotlightPadding?: number;
spotlightPaddingOverride?: { top?: number; right?: number; bottom?: number; left?: number };
}
export interface TutorialStepDef {
@@ -16,11 +19,16 @@ export const TUTORIAL_KEYS = {
ANALYSIS: 'analysis',
ASSET: 'asset',
SOUND: 'sound',
SOUND_LYRICS: 'soundLyrics',
SOUND_AUDIO: 'soundAudio',
GENERATING:'generating',
COMPLETION: 'completion',
MY_INFO: 'myInfo',
ADO2_CONTENTS: 'ado2Contents',
UPLOAD_MODAL: 'uploadModal',
UPLOAD_FORM: 'uploadForm',
DASHBOARD: 'dashboard',
CONTENT_CALENDAR: 'contentCalendar',
FEEDBACK: 'feedback',
} as const;
@@ -32,19 +40,24 @@ export const tutorialSteps: TutorialStepDef[] = [
targetSelector: '.hero-dropdown-container',
titleKey: 'tutorial.landing.dropdown.title',
descriptionKey: 'tutorial.landing.dropdown.desc',
position: 'bottom',
position: 'top',
clickToAdvance: false,
spotlightPaddingOverride: { top: 10, right: 15, bottom: 100, left: 0 },
},
{
targetSelector: '.hero-input-container',
targetSelector: '.hero-input-wrapper',
titleKey: 'tutorial.landing.field.title',
descriptionKey: 'tutorial.landing.field.desc',
position: 'bottom',
position: 'right',
clickToAdvance: false,
spotlightPaddingOverride: { top: 0, right: 0, bottom: 290, left: -105 },
},
{
targetSelector: '.hero-button',
titleKey: 'tutorial.landing.button.title',
descriptionKey: 'tutorial.landing.button.desc',
position: 'top',
position: 'bottom',
clickToAdvance: true,
},
],
},
@@ -55,35 +68,35 @@ export const tutorialSteps: TutorialStepDef[] = [
targetSelector: '.bi2-identity-card',
titleKey: 'tutorial.analysis.identity.title',
descriptionKey: 'tutorial.analysis.identity.desc',
position: 'bottom',
position: 'top',
clickToAdvance: false,
},
{
targetSelector: '.bi2-selling-card',
titleKey: 'tutorial.analysis.selling.title',
descriptionKey: 'tutorial.analysis.selling.desc',
position: 'bottom',
position: 'top',
clickToAdvance: false,
},
{
targetSelector: '.bi2-persona-grid',
titleKey: 'tutorial.analysis.persona.title',
descriptionKey: 'tutorial.analysis.persona.desc',
position: 'bottom',
position: 'top',
clickToAdvance: false,
},
{
targetSelector: '.bi2-keyword-tags',
titleKey: 'tutorial.analysis.keywords.title',
descriptionKey: 'tutorial.analysis.keywords.desc',
position: 'bottom',
position: 'top',
clickToAdvance: false,
},
{
targetSelector: '.bi2-generate-btn',
titleKey: 'tutorial.analysis.generate.title',
descriptionKey: 'tutorial.analysis.generate.desc',
position: 'top',
position: 'right',
clickToAdvance: true,
},
],
@@ -91,11 +104,19 @@ export const tutorialSteps: TutorialStepDef[] = [
{
key: TUTORIAL_KEYS.ASSET,
hints: [
{
targetSelector: '.asset-column.asset-column-left',
titleKey: 'tutorial.asset.image.title',
descriptionKey: 'tutorial.asset.image.desc',
position: 'left',
clickToAdvance: false,
},
{
targetSelector: '.asset-upload-zone',
titleKey: 'tutorial.asset.upload.title',
descriptionKey: 'tutorial.asset.upload.desc',
position: 'left',
clickToAdvance: false,
},
{
targetSelector: '.asset-ratio-section',
@@ -108,6 +129,7 @@ export const tutorialSteps: TutorialStepDef[] = [
titleKey: 'tutorial.asset.next.title',
descriptionKey: 'tutorial.asset.next.desc',
position: 'top',
clickToAdvance: true,
},
],
},
@@ -118,23 +140,48 @@ export const tutorialSteps: TutorialStepDef[] = [
targetSelector: '.genre-grid',
titleKey: 'tutorial.sound.genre.title',
descriptionKey: 'tutorial.sound.genre.desc',
position: 'right',
clickToAdvance: false,
position: 'top',
clickToAdvance: true,
},
{
targetSelector: '.language-selector-wrapper',
titleKey: 'tutorial.sound.language.title',
descriptionKey: 'tutorial.sound.language.desc',
position: 'right',
position: 'top',
clickToAdvance: false,
spotlightPaddingOverride: { bottom: 230 },
},
{
targetSelector: '.btn-generate-sound',
titleKey: 'tutorial.sound.generate.title',
descriptionKey: 'tutorial.sound.generate.desc',
position: 'top',
position: 'right',
clickToAdvance: true,
},
],
},
{
key: TUTORIAL_KEYS.SOUND_LYRICS,
hints: [
{
targetSelector: '.lyrics-display',
titleKey: 'tutorial.sound.lyrics.title',
descriptionKey: 'tutorial.sound.lyrics.desc',
position: 'left',
clickToAdvance: false,
},
],
},
{
key: TUTORIAL_KEYS.SOUND_AUDIO,
hints: [
{
targetSelector: '.audio-player',
titleKey: 'tutorial.sound.audioPlayer.title',
descriptionKey: 'tutorial.sound.audioPlayer.desc',
position: 'left',
clickToAdvance: false,
},
{
targetSelector: '.btn-video-generate',
titleKey: 'tutorial.sound.video.title',
@@ -151,36 +198,76 @@ export const tutorialSteps: TutorialStepDef[] = [
targetSelector: '.youtube-connect-section',
titleKey: 'tutorial.myInfo.connect.title',
descriptionKey: 'tutorial.myInfo.connect.desc',
position: 'bottom',
position: 'top',
},
{
targetSelector: '.youtube-connect-button',
targetSelector: '.myinfo-social-btn.connected',
titleKey: 'tutorial.myInfo.button.title',
descriptionKey: 'tutorial.myInfo.button.desc',
position: 'top',
},
{
targetSelector: '.myinfo-connected-accounts',
titleKey: 'tutorial.myInfo.connected.title',
descriptionKey: 'tutorial.myInfo.connected.desc',
position: 'top',
clickToAdvance: false,
},
{
targetSelector: '#sidebar-ado2-contents',
titleKey: 'tutorial.myInfo.ado2.title',
descriptionKey: 'tutorial.myInfo.ado2.desc',
position: 'right',
clickToAdvance: true,
},
],
},
{
key: TUTORIAL_KEYS.ADO2_CONTENTS,
hints: [
{
targetSelector: '.ado2-contents-list',
targetSelector: '.ado2-content-card',
titleKey: 'tutorial.ado2.list.title',
descriptionKey: 'tutorial.ado2.list.desc',
position: 'bottom',
position: 'right',
clickToAdvance: false,
},
{
targetSelector: '.ado2-upload-button',
targetSelector: '.content-download-btn',
titleKey: 'tutorial.ado2.upload.title',
descriptionKey: 'tutorial.ado2.upload.desc',
position: 'top',
position: 'right',
clickToAdvance: true,
},
],
},
{
key: TUTORIAL_KEYS.GENERATING,
hints:[
{
targetSelector: '.comp2-info-section',
titleKey: 'tutorial.completion.contentInfo.title',
descriptionKey: 'tutorial.completion.contentInfo.desc',
position: 'left',
},
{
targetSelector: '.comp2-video-section',
titleKey: 'tutorial.completion.generating.title',
descriptionKey: 'tutorial.completion.generating.desc',
position: 'right',
}
]
},
{
key: TUTORIAL_KEYS.COMPLETION,
hints: [
{
targetSelector: '.comp2-video-section',
titleKey: 'tutorial.completion.completion.title',
descriptionKey: 'tutorial.completion.completion.desc',
position: 'right',
clickToAdvance: false,
},
{
targetSelector: '#sidebar-my-info',
titleKey: 'tutorial.completion.myInfo.title',
@@ -194,9 +281,21 @@ export const tutorialSteps: TutorialStepDef[] = [
key: TUTORIAL_KEYS.UPLOAD_MODAL,
hints: [
{
targetSelector: '.social-posting-field',
titleKey: 'tutorial.upload.title.title',
descriptionKey: 'tutorial.upload.title.desc',
targetSelector: '.social-posting-content',
titleKey: 'tutorial.upload.seo.title',
descriptionKey: 'tutorial.upload.seo.desc',
position: 'right',
clickToAdvance: false,
},
],
},
{
key: TUTORIAL_KEYS.UPLOAD_FORM,
hints: [
{
targetSelector: '.social-posting-form',
titleKey: 'tutorial.upload.required.title',
descriptionKey: 'tutorial.upload.required.desc',
position: 'left',
clickToAdvance: false,
},
@@ -220,22 +319,55 @@ export const tutorialSteps: TutorialStepDef[] = [
key: TUTORIAL_KEYS.DASHBOARD,
hints: [
{
targetSelector: '.dashboard-metrics-row',
targetSelector: '.stats-grid-8',
titleKey: 'tutorial.dashboard.metrics.title',
descriptionKey: 'tutorial.dashboard.metrics.desc',
position: 'bottom',
},
{
targetSelector: '.dashboard-chart-section',
targetSelector: '.yoy-chart-card',
titleKey: 'tutorial.dashboard.chart.title',
descriptionKey: 'tutorial.dashboard.chart.desc',
position: 'right',
},
{
targetSelector: '.tutorial-center-anchor',
titleKey: 'tutorial.dashboard.more.title',
descriptionKey: 'tutorial.dashboard.more.desc',
position: 'bottom',
clickToAdvance: false,
},
],
},
{
key: TUTORIAL_KEYS.CONTENT_CALENDAR,
hints: [
{
targetSelector: '.calendar-grid-area',
titleKey: 'tutorial.contentCalendar.grid.title',
descriptionKey: 'tutorial.contentCalendar.grid.desc',
position: 'top',
clickToAdvance: true,
},
{
targetSelector: '.calendar-side-panel',
titleKey: 'tutorial.contentCalendar.panel.title',
descriptionKey: 'tutorial.contentCalendar.panel.desc',
position: 'left',
clickToAdvance: false,
},
],
},
{
key: TUTORIAL_KEYS.FEEDBACK,
hints: [
{
targetSelector: '.tutorial-center-anchor',
titleKey: 'tutorial.feedback.complete.title',
descriptionKey: 'tutorial.feedback.complete.desc',
position: 'bottom',
clickToAdvance: false,
},
{
targetSelector: '.sidebar-inquiry-btn',
titleKey: 'tutorial.feedback.title',
+59 -9
View File
@@ -1,7 +1,11 @@
import { useState, useCallback } from 'react';
import React, { useState, useCallback } from 'react';
import { tutorialSteps, TutorialHint } from './tutorialSteps';
const SEEN_KEY = 'castad_tutorial_seen';
const SEEN_KEY = 'ado2_tutorial_seen';
const PROGRESS_KEY = 'ado2_tutorial_progress';
// 전역 단일 활성 튜토리얼 관리 — 새 튜토리얼 시작 시 이전 것을 skip 처리
let globalSkip: (() => void) | null = null;
function getSeenKeys(): string[] {
try {
@@ -16,6 +20,32 @@ function markSeen(key: string) {
if (!seen.includes(key)) {
localStorage.setItem(SEEN_KEY, JSON.stringify([...seen, key]));
}
clearProgress(key);
}
function saveProgress(key: string, index: number) {
try {
const progress = JSON.parse(localStorage.getItem(PROGRESS_KEY) || '{}');
progress[key] = index;
localStorage.setItem(PROGRESS_KEY, JSON.stringify(progress));
} catch {}
}
function loadProgress(key: string): number {
try {
const progress = JSON.parse(localStorage.getItem(PROGRESS_KEY) || '{}');
return progress[key] ?? 0;
} catch {
return 0;
}
}
function clearProgress(key: string) {
try {
const progress = JSON.parse(localStorage.getItem(PROGRESS_KEY) || '{}');
delete progress[key];
localStorage.setItem(PROGRESS_KEY, JSON.stringify(progress));
} catch {}
}
interface UseTutorialReturn {
@@ -24,7 +54,7 @@ interface UseTutorialReturn {
currentHintIndex: number;
hints: TutorialHint[];
tutorialKey: string | null;
startTutorial: (key: string) => void;
startTutorial: (key: string, onComplete?: () => void) => void;
nextHint: () => void;
prevHint: () => void;
skipTutorial: () => void;
@@ -41,22 +71,41 @@ export function useTutorial(): UseTutorialReturn {
const [currentHintIndex, setCurrentHintIndex] = useState(0);
const [hints, setHints] = useState<TutorialHint[]>([]);
const [tutorialKey, setTutorialKey] = useState<string | null>(null);
const onCompleteRef = React.useRef<(() => void) | undefined>(undefined);
const startTutorial = useCallback((key: string) => {
const startTutorial = useCallback((key: string, onComplete?: () => void) => {
const step = tutorialSteps.find(s => s.key === key);
if (!step || step.hints.length === 0) return;
// 다른 인스턴스에서 활성화된 튜토리얼이 있으면 skip 처리
globalSkip?.();
const savedIndex = loadProgress(key);
const resumeIndex = savedIndex < step.hints.length ? savedIndex : 0;
onCompleteRef.current = onComplete;
setHints(step.hints);
setTutorialKey(key);
setCurrentHintIndex(0);
setCurrentHintIndex(resumeIndex);
setIsActive(true);
// 이 인스턴스의 skip을 전역에 등록
globalSkip = () => {
if (key) saveProgress(key, resumeIndex);
setIsActive(false);
setCurrentHintIndex(0);
globalSkip = null;
};
}, []);
const nextHint = useCallback(() => {
setCurrentHintIndex(prev => {
if (prev < hints.length - 1) return prev + 1;
// 마지막 힌트 완료 → seen 기록
if (prev < hints.length - 1) {
const next = prev + 1;
if (tutorialKey) saveProgress(tutorialKey, next);
return next;
}
// 마지막 힌트 완료 → seen 기록 + 진행 상태 삭제
setIsActive(false);
if (tutorialKey) markSeen(tutorialKey);
onCompleteRef.current?.();
onCompleteRef.current = undefined;
return 0;
});
}, [hints.length, tutorialKey]);
@@ -65,11 +114,12 @@ export function useTutorial(): UseTutorialReturn {
setCurrentHintIndex(prev => Math.max(0, prev - 1));
}, []);
// 건너뛰기: 오버레이만 닫고 seen 기록 안 함 → 다음 방문 시 다시 표시
// 건너뛰기: 현재 진행 인덱스 저장 후 오버레이 닫기 → 다음 방문 시 이어서 표시
const skipTutorial = useCallback(() => {
if (tutorialKey) saveProgress(tutorialKey, currentHintIndex);
setIsActive(false);
setCurrentHintIndex(0);
}, []);
}, [tutorialKey, currentHintIndex]);
// 튜토리얼 다시 보기: 팝업 표시만
const showRestartPopup = useCallback((key: string) => {