css 정리 .

This commit is contained in:
HyeongBaeYang committed 2025-12-24 13:09:05 +09:00
1 parent 97577b6ba3
commit ecbd81d091
16 files changed
+3778 -485

No files matched your search

+57 -94
View File
@@ -17,7 +17,6 @@ interface SoundStudioContentProps {
type GenerationStatus = 'idle' | 'generating_lyric' | 'generating_song' | 'polling' | 'complete' | 'error';
// localStorage에 저장할 데이터 구조
interface SavedGenerationState {
taskId: string;
lyrics: string;
@@ -26,8 +25,8 @@ interface SavedGenerationState {
}
const STORAGE_KEY = 'castad_song_generation';
const STORAGE_EXPIRY = 30 * 60 * 1000; // 30분
const MAX_RETRY_COUNT = 3; // 최대 재시도 횟수
const STORAGE_EXPIRY = 30 * 60 * 1000;
const MAX_RETRY_COUNT = 3;
const SoundStudioContent: React.FC<SoundStudioContentProps> = ({ onBack, onNext, businessInfo }) => {
const [selectedType, setSelectedType] = useState('보컬');
@@ -49,7 +48,6 @@ const SoundStudioContent: React.FC<SoundStudioContentProps> = ({ onBack, onNext,
const progressBarRef = useRef<HTMLDivElement>(null);
const audioRef = useRef<HTMLAudioElement>(null);
// localStorage에 상태 저장
const saveToStorage = (taskId: string, currentLyrics: string, currentStatus: GenerationStatus) => {
const data: SavedGenerationState = {
taskId,
@@ -60,12 +58,10 @@ const SoundStudioContent: React.FC<SoundStudioContentProps> = ({ onBack, onNext,
localStorage.setItem(STORAGE_KEY, JSON.stringify(data));
};
// localStorage에서 상태 제거
const clearStorage = () => {
localStorage.removeItem(STORAGE_KEY);
};
// localStorage에서 상태 복구
const loadFromStorage = (): SavedGenerationState | null => {
try {
const saved = localStorage.getItem(STORAGE_KEY);
@@ -73,7 +69,6 @@ const SoundStudioContent: React.FC<SoundStudioContentProps> = ({ onBack, onNext,
const data: SavedGenerationState = JSON.parse(saved);
// 만료된 데이터인지 확인 (30분)
if (Date.now() - data.timestamp > STORAGE_EXPIRY) {
clearStorage();
return null;
@@ -86,26 +81,19 @@ const SoundStudioContent: React.FC<SoundStudioContentProps> = ({ onBack, onNext,
}
};
// 컴포넌트 마운트 시 저장된 상태 복구
useEffect(() => {
const savedState = loadFromStorage();
if (savedState && (savedState.status === 'polling' || savedState.status === 'generating_song')) {
// 저장된 가사가 있으면 표시
if (savedState.lyrics) {
setLyrics(savedState.lyrics);
setShowLyrics(true);
}
// 폴링 상태 복구
setStatus('polling');
setStatusMessage('음악을 처리하고 있습니다... (새로고침 후 복구됨)');
// 폴링 재개 (저장된 가사와 함께)
resumePolling(savedState.taskId, savedState.lyrics, 0);
}
}, []);
// 폴링 재개 함수 (타임아웃 시 재생성)
const resumePolling = async (taskId: string, currentLyrics: string, currentRetryCount: number = 0) => {
try {
const downloadResponse = await waitForSongComplete(
@@ -132,14 +120,11 @@ const SoundStudioContent: React.FC<SoundStudioContentProps> = ({ onBack, onNext,
} catch (error) {
console.error('Polling failed:', error);
// 타임아웃인 경우 재생성 시도
if (error instanceof Error && error.message === 'TIMEOUT') {
if (currentRetryCount < MAX_RETRY_COUNT) {
const newRetryCount = currentRetryCount + 1;
setRetryCount(newRetryCount);
setStatusMessage(`시간 초과로 재생성 중... (${newRetryCount}/${MAX_RETRY_COUNT})`);
// 새로운 노래 생성 요청
await regenerateSongOnly(currentLyrics, newRetryCount);
} else {
setStatus('error');
@@ -156,7 +141,6 @@ const SoundStudioContent: React.FC<SoundStudioContentProps> = ({ onBack, onNext,
}
};
// 노래만 재생성 (가사는 유지)
const regenerateSongOnly = async (currentLyrics: string, currentRetryCount: number) => {
if (!businessInfo) return;
@@ -179,10 +163,7 @@ const SoundStudioContent: React.FC<SoundStudioContentProps> = ({ onBack, onNext,
throw new Error(songResponse.error_message || '음악 생성 요청에 실패했습니다.');
}
// 새 task_id로 저장
saveToStorage(songResponse.task_id, currentLyrics, 'polling');
// 폴링 재개
await resumePolling(songResponse.task_id, currentLyrics, currentRetryCount);
} catch (error) {
@@ -288,7 +269,6 @@ const SoundStudioContent: React.FC<SoundStudioContentProps> = ({ onBack, onNext,
setStatusMessage('가사를 생성하고 있습니다...');
try {
// Step 1: Generate lyrics
const language = LANGUAGE_MAP[selectedLang] || 'Korean';
let lyricResponse = await generateLyric({
customer_name: businessInfo.customer_name,
@@ -297,7 +277,6 @@ const SoundStudioContent: React.FC<SoundStudioContentProps> = ({ onBack, onNext,
region: businessInfo.region,
});
// Retry if the response contains error message
let retryCount = 0;
while (lyricResponse.lyric.includes("I'm sorry") && retryCount < 3) {
retryCount++;
@@ -314,7 +293,6 @@ const SoundStudioContent: React.FC<SoundStudioContentProps> = ({ onBack, onNext,
throw new Error(lyricResponse.error_message || '가사 생성에 실패했습니다.');
}
// 3번 재시도 후에도 여전히 에러 메시지가 포함되어 있으면 가사 카드를 표시하지 않고 에러 처리
if (lyricResponse.lyric.includes("I'm sorry")) {
throw new Error('가사 생성에 실패했습니다. 다시 시도해주세요.');
}
@@ -322,7 +300,6 @@ const SoundStudioContent: React.FC<SoundStudioContentProps> = ({ onBack, onNext,
setLyrics(lyricResponse.lyric);
setShowLyrics(true);
// Step 2: Generate song
setStatus('generating_song');
setStatusMessage('음악을 생성하고 있습니다...');
@@ -343,12 +320,10 @@ const SoundStudioContent: React.FC<SoundStudioContentProps> = ({ onBack, onNext,
throw new Error(songResponse.error_message || '음악 생성 요청에 실패했습니다.');
}
// Step 3: Poll for completion - 상태 저장
setStatus('polling');
setStatusMessage('음악을 처리하고 있습니다...');
saveToStorage(songResponse.task_id, lyricResponse.lyric, 'polling');
// 폴링 시작 (타임아웃 시 자동 재생성)
await resumePolling(songResponse.task_id, lyricResponse.lyric, 0);
} catch (error) {
@@ -376,53 +351,50 @@ const SoundStudioContent: React.FC<SoundStudioContentProps> = ({ onBack, onNext,
const isGenerating = status === 'generating_lyric' || status === 'generating_song' || status === 'polling';
return (
<div className="flex flex-col h-full overflow-hidden">
{/* Hidden audio element */}
<div className="flex-col h-full overflow-hidden" style={{ display: 'flex' }}>
{audioUrl && (
<audio ref={audioRef} src={audioUrl} preload="metadata" />
)}
<div className="flex-shrink-0 p-3 sm:p-4 md:p-6 pb-0">
<div className="flex justify-start mb-2 sm:mb-3 ml-10 md:ml-0">
<button
onClick={onBack}
className="flex items-center gap-1.5 py-1 px-3 sm:py-1.5 sm:px-4 rounded-full border border-gray-700 hover:bg-gray-800 transition-colors text-[9px] sm:text-[10px] md:text-xs text-gray-300"
>
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
{/* Header Section */}
<div className="shrink-0 p-6 md:p-8 pb-0">
<div className="back-button-container">
<button onClick={onBack} className="btn-back">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
<path d="M15 18l-6-6 6-6" />
</svg>
뒤로가기
</button>
</div>
<div className="hidden sm:block text-center mb-2 md:mb-4">
<h1 className="text-lg md:text-xl lg:text-2xl font-bold mb-0.5 tracking-tight">사운드 스튜디오</h1>
<p className="text-gray-400 text-[9px] md:text-[10px] lg:text-xs font-light">
<div className="page-header">
<h1 className="page-title">사운드 스튜디오</h1>
<p className="page-subtitle">
쉽고 빠르게, 브랜드 소셜 미디어 캠페인을 만드세요.
</p>
</div>
</div>
<div className="flex-1 px-3 sm:px-4 md:px-6 min-h-0 overflow-hidden">
<div className="flex flex-col md:flex-row gap-2 sm:gap-3 md:gap-4 max-w-6xl mx-auto w-full justify-center h-full">
{/* Left Card: Audio Style */}
<div className="flex-1 px-6 md:px-8 min-h-0 overflow-hidden">
<div className="main-content h-full justify-center">
{/* Audio Style Card */}
<div
className={`bg-[#1c2a2e] rounded-xl sm:rounded-2xl md:rounded-3xl p-3 sm:p-4 md:p-5 border border-white/5 shadow-2xl flex flex-col transition-all duration-700 ease-out overflow-hidden ${
showLyrics ? 'md:flex-[1.5]' : 'flex-1 md:max-w-xl'
className={`card card-flex card-overflow-hidden transition-all duration-700 ease-out ${
showLyrics ? 'lg:flex-[1.5]' : 'flex-1 lg:max-w-2xl'
}`}
>
<h3 className="text-[#a6ffea] text-[9px] sm:text-[10px] md:text-xs font-bold mb-2 sm:mb-3 tracking-wide shrink-0">오디오 스타일</h3>
<h3 className="section-title">오디오 스타일</h3>
<div className="space-y-2 sm:space-y-3 flex-1 min-h-0 overflow-y-auto custom-scrollbar">
<div className="space-y-5 flex-1 min-h-0 overflow-y-auto custom-scrollbar">
<div>
<p className="text-[8px] sm:text-[9px] md:text-[10px] text-gray-500 mb-1.5 sm:mb-2 font-bold">AI 사운드 유형 선택</p>
<div className="grid grid-cols-3 gap-1.5 sm:gap-2">
<p className="text-sm text-gray-400 mb-3 font-medium">AI 사운드 유형 선택</p>
<div className="grid-cols-3 gap-3" style={{ display: 'grid' }}>
{['보컬', '성우 내레이션', '배경음악'].map(type => (
<button
key={type}
onClick={() => setSelectedType(type)}
disabled={isGenerating}
className={`py-1.5 sm:py-2 rounded-lg border text-[8px] sm:text-[9px] md:text-[10px] font-bold transition-all ${selectedType === type ? 'border-[#a6ffea] bg-[#121a1d] text-[#a6ffea]' : 'border-gray-800 bg-[#121a1d]/40 text-gray-400'} ${isGenerating ? 'opacity-50 cursor-not-allowed' : ''}`}
className={`btn-select ${selectedType === type ? 'active' : ''}`}
>
{type}
</button>
@@ -431,8 +403,8 @@ const SoundStudioContent: React.FC<SoundStudioContentProps> = ({ onBack, onNext,
</div>
<div>
<p className="text-[8px] sm:text-[9px] md:text-[10px] text-gray-500 mb-1.5 sm:mb-2 font-bold">언어 선택</p>
<div className="grid grid-cols-3 gap-1.5 sm:gap-2">
<p className="text-sm text-gray-400 mb-3 font-medium">언어 선택</p>
<div className="grid-cols-3 gap-3" style={{ display: 'grid' }}>
{[
{ label: '한국어', flag: '🇰🇷' },
{ label: 'English', flag: '🇺🇸' },
@@ -445,9 +417,10 @@ const SoundStudioContent: React.FC<SoundStudioContentProps> = ({ onBack, onNext,
key={lang.label}
onClick={() => setSelectedLang(lang.label)}
disabled={isGenerating}
className={`py-1.5 sm:py-2 rounded-lg border text-[8px] sm:text-[9px] font-bold flex flex-col items-center gap-0.5 transition-all ${selectedLang === lang.label ? 'border-[#a6ffea] bg-[#121a1d] text-[#a6ffea]' : 'border-gray-800 bg-[#121a1d]/40 text-gray-400'} ${isGenerating ? 'opacity-50 cursor-not-allowed' : ''}`}
className={`btn-select flex-col gap-1 ${selectedLang === lang.label ? 'active' : ''}`}
style={{ display: 'flex', alignItems: 'center' }}
>
<span className="text-xs sm:text-sm">{lang.flag}</span>
<span className="text-lg">{lang.flag}</span>
<span>{lang.label}</span>
</button>
))}
@@ -455,12 +428,12 @@ const SoundStudioContent: React.FC<SoundStudioContentProps> = ({ onBack, onNext,
</div>
<div>
<p className="text-[8px] sm:text-[9px] md:text-[10px] text-gray-500 mb-1.5 sm:mb-2 font-bold">음악 장르 선택</p>
<p className="text-sm text-gray-400 mb-3 font-medium">음악 장르 선택</p>
<select
value={selectedGenre}
onChange={(e) => setSelectedGenre(e.target.value)}
disabled={isGenerating}
className={`w-full py-1.5 sm:py-2 px-2 sm:px-3 rounded-lg bg-[#121a1d] border border-gray-800 text-[8px] sm:text-[9px] md:text-[10px] text-gray-300 focus:outline-none focus:border-[#a6ffea] ${isGenerating ? 'opacity-50 cursor-not-allowed' : ''}`}
className="select-input"
>
<option>AI 추천</option>
<option>로파이</option>
@@ -470,17 +443,15 @@ const SoundStudioContent: React.FC<SoundStudioContentProps> = ({ onBack, onNext,
</div>
</div>
{/* Error Message */}
{errorMessage && (
<div className="mt-2 p-2 bg-red-500/10 border border-red-500/30 rounded-lg text-red-400 text-[9px] sm:text-[10px] shrink-0">
<div className="error-message">
{errorMessage}
</div>
)}
{/* Status Message */}
{isGenerating && statusMessage && (
<div className="mt-2 p-2 bg-[#a6ffea]/10 border border-[#a6ffea]/30 rounded-lg text-[#a6ffea] text-[9px] sm:text-[10px] flex items-center gap-2 shrink-0">
<svg className="animate-spin h-3 w-3" viewBox="0 0 24 24">
<div className="status-message">
<svg className="animate-spin h-4 w-4" viewBox="0 0 24 24">
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4" fill="none"/>
<path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"/>
</svg>
@@ -488,19 +459,15 @@ const SoundStudioContent: React.FC<SoundStudioContentProps> = ({ onBack, onNext,
</div>
)}
<div className="mt-2 sm:mt-3 shrink-0">
<div className="mt-4 shrink-0">
<button
onClick={handleGenerateMusic}
disabled={isGenerating}
className={`w-full py-2 sm:py-2.5 md:py-3 font-bold rounded-xl transition-all transform active:scale-[0.98] text-[10px] sm:text-xs flex items-center justify-center gap-2 ${
isGenerating
? 'bg-[#a6ffea]/50 text-[#121a1d]/50 cursor-not-allowed'
: 'bg-[#a6ffea] text-[#121a1d] hover:bg-[#8affda]'
}`}
className={`btn-secondary ${isGenerating ? 'disabled' : ''}`}
>
{isGenerating ? (
<>
<svg className="animate-spin h-3 w-3" viewBox="0 0 24 24">
<svg className="animate-spin h-4 w-4" viewBox="0 0 24 24">
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4" fill="none"/>
<path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"/>
</svg>
@@ -513,62 +480,61 @@ const SoundStudioContent: React.FC<SoundStudioContentProps> = ({ onBack, onNext,
</div>
</div>
{/* Right Card: Lyrics - 애니메이션으로 나타남 */}
{/* Lyrics Card */}
{showLyrics && (
<div
className="bg-[#1c2a2e] rounded-xl sm:rounded-2xl md:rounded-3xl p-3 sm:p-4 md:p-5 border border-white/5 shadow-2xl flex flex-col flex-1 animate-slide-in overflow-hidden"
style={{ minWidth: '240px' }}
className="card card-flex flex-1 animate-slide-in card-overflow-hidden min-w-280"
>
<h3 className="text-[#a6ffea] text-[9px] sm:text-[10px] md:text-xs font-bold mb-0.5 sm:mb-1 tracking-wide shrink-0">가사</h3>
<p className="text-gray-500 text-[8px] sm:text-[9px] mb-2 sm:mb-3 shrink-0">가사 영역을 선택해서 수정 가능해요</p>
<h3 className="section-title mb-1">가사</h3>
<p className="text-gray-500 text-sm mb-4 shrink-0">가사 영역을 선택해서 수정 가능해요</p>
<div className="flex-1 bg-[#121a1d]/50 rounded-lg sm:rounded-xl border border-white/5 p-2 sm:p-3 flex flex-col gap-2 min-h-0 overflow-hidden">
{/* Interactive Player Bar */}
<div className="bg-black/40 rounded-full p-1.5 sm:p-2 flex items-center gap-2 shrink-0">
<div className="card-inner flex-col gap-3 min-h-0 overflow-hidden" style={{ display: 'flex', flex: 1 }}>
{/* Player Bar */}
<div className="player-bar">
<button
onClick={togglePlayPause}
disabled={!audioUrl}
className={`text-[#a6ffea] flex-shrink-0 transition-transform hover:scale-110 ${!audioUrl ? 'opacity-50 cursor-not-allowed' : ''}`}
className={`play-btn ${!audioUrl ? 'disabled' : ''}`}
>
{isPlaying ? (
<svg className="w-4 h-4 sm:w-5 sm:h-5" viewBox="0 0 24 24" fill="currentColor">
<svg className="w-6 h-6" viewBox="0 0 24 24" fill="currentColor">
<rect x="6" y="4" width="4" height="16" rx="1" />
<rect x="14" y="4" width="4" height="16" rx="1" />
</svg>
) : (
<svg className="w-4 h-4 sm:w-5 sm:h-5" viewBox="0 0 24 24" fill="currentColor"><path d="M8 5v14l11-7z"/></svg>
<svg className="w-6 h-6" viewBox="0 0 24 24" fill="currentColor"><path d="M8 5v14l11-7z"/></svg>
)}
</button>
<div
ref={progressBarRef}
onMouseDown={onMouseDown}
className={`flex-1 h-1 bg-gray-800 rounded-full relative group ${audioUrl ? 'cursor-pointer' : 'cursor-not-allowed opacity-50'}`}
className={`progress-bar-container ${!audioUrl ? 'disabled' : ''}`}
>
<div
className="absolute left-0 top-0 h-full bg-[#a6ffea] rounded-full"
className="progress-bar-fill"
style={{ width: `${progress}%` }}
></div>
<div
className="absolute top-1/2 -translate-y-1/2 -translate-x-1/2 flex items-center justify-center pointer-events-none"
className="progress-bar-thumb"
style={{ left: `${progress}%` }}
>
<div className="absolute w-3 h-3 sm:w-4 sm:h-4 bg-[#a6ffea] rounded-full opacity-20 animate-pulse"></div>
<div className="w-2 h-2 sm:w-2.5 sm:h-2.5 bg-[#a6ffea] rounded-full shadow-[0_0_10px_rgba(166,255,234,0.6)] border border-[#121a1d]/20"></div>
<div className="progress-bar-thumb-glow"></div>
<div className="progress-bar-thumb-dot"></div>
</div>
</div>
<span className="text-[8px] sm:text-[9px] text-gray-500 font-mono w-12 sm:w-14 text-right">
{formatTime(currentTime)} / {formatTime(duration)}
<span className="time-display">
{formatTime(Math.max(0, duration - currentTime))}
</span>
</div>
{/* Editable Lyrics */}
{/* Lyrics Textarea */}
<textarea
value={lyrics}
onChange={(e) => setLyrics(e.target.value)}
className="flex-1 overflow-y-auto text-[9px] sm:text-[10px] text-gray-400 bg-transparent resize-none focus:outline-none focus:text-gray-300 pr-2 custom-scrollbar leading-relaxed min-h-0"
className="textarea-lyrics custom-scrollbar"
placeholder="가사가 여기에 표시됩니다..."
/>
</div>
@@ -576,7 +542,7 @@ const SoundStudioContent: React.FC<SoundStudioContentProps> = ({ onBack, onNext,
<button
onClick={handleRegenerate}
disabled={isGenerating}
className={`mt-2 sm:mt-3 w-full py-2 sm:py-2.5 bg-[#a6ffea]/20 text-[#a6ffea] border border-[#a6ffea]/30 font-bold rounded-lg sm:rounded-xl hover:bg-[#a6ffea]/30 transition-all text-[9px] sm:text-[10px] md:text-xs shrink-0 ${isGenerating ? 'opacity-50 cursor-not-allowed' : ''}`}
className="btn-regenerate"
>
재생성
</button>
@@ -585,15 +551,12 @@ const SoundStudioContent: React.FC<SoundStudioContentProps> = ({ onBack, onNext,
</div>
</div>
<div className="flex-shrink-0 flex justify-center py-2 sm:py-3 md:py-4 px-3 sm:px-4">
{/* Bottom Button */}
<div className="bottom-button-container">
<button
onClick={onNext}
disabled={status !== 'complete'}
className={`font-bold py-2 sm:py-2.5 md:py-3 px-6 sm:px-10 md:px-14 rounded-full transition-all transform active:scale-95 shadow-2xl text-[9px] sm:text-[10px] md:text-xs tracking-wide ${
status === 'complete'
? 'bg-[#a682ff] hover:bg-[#9570f0] text-white shadow-[#a682ff44]'
: 'bg-gray-600 text-gray-400 cursor-not-allowed shadow-none'
}`}
className={`btn-primary ${status !== 'complete' ? 'disabled' : ''}`}
>
영상 생성하기
</button>