검색 기능 분리 및 튜토리얼 수정
This commit is contained in:
1 parent
8d7d0a74a6
commit
3660290f1b
13 files changed
+550
-732
No files matched your search
@@ -113,7 +113,7 @@ const MyInfoContent: React.FC<MyInfoContentProps> = ({ initialTab }) => {
|
||||
const hasConnectedAccounts = youtubeAccounts.length > 0 || instagramAccounts.length > 0;
|
||||
|
||||
const tabs = [
|
||||
{ id: 'basic' as TabType, label: t('myInfo.tabBasic') },
|
||||
// { id: 'basic' as TabType, label: t('myInfo.tabBasic') },
|
||||
{ id: 'payment' as TabType, label: t('myInfo.tabPayment') },
|
||||
{ id: 'business' as TabType, label: t('myInfo.tabBusiness') },
|
||||
];
|
||||
@@ -205,11 +205,11 @@ const MyInfoContent: React.FC<MyInfoContentProps> = ({ initialTab }) => {
|
||||
|
||||
{/* 탭 컨텐츠 */}
|
||||
<div className="myinfo-content">
|
||||
{activeTab === 'basic' && (
|
||||
{/* {activeTab === 'basic' && (
|
||||
<div className="myinfo-section">
|
||||
<p className="myinfo-placeholder">{t('myInfo.basicPlaceholder')}</p>
|
||||
</div>
|
||||
)}
|
||||
)} */}
|
||||
|
||||
{activeTab === 'payment' && (
|
||||
<div className="myinfo-section">
|
||||
@@ -240,7 +240,7 @@ const MyInfoContent: React.FC<MyInfoContentProps> = ({ initialTab }) => {
|
||||
|
||||
{activeTab === 'business' && (
|
||||
<>
|
||||
{/* 내 비즈니스 섹션 */}
|
||||
{/* 내 비즈니스 섹션
|
||||
<div className="myinfo-section">
|
||||
<h2 className="myinfo-section-title">{t('myInfo.myBusiness')}</h2>
|
||||
<div className="myinfo-business-card">
|
||||
@@ -261,7 +261,7 @@ const MyInfoContent: React.FC<MyInfoContentProps> = ({ initialTab }) => {
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div> */}
|
||||
|
||||
{/* 소셜 채널 섹션 */}
|
||||
<div className="myinfo-section">
|
||||
|
||||
@@ -26,6 +26,19 @@ type GenerationStatus = 'idle' | 'generating_lyric' | 'generating_song' | 'polli
|
||||
|
||||
const MAX_RETRY_COUNT = 3;
|
||||
|
||||
const sanitizeError = (message: string, fallback: string): string => {
|
||||
if (
|
||||
message.includes('Traceback') ||
|
||||
message.includes('File "/') ||
|
||||
message.includes('httpx.') ||
|
||||
message.includes('httpcore.') ||
|
||||
message.length > 200
|
||||
) {
|
||||
return fallback;
|
||||
}
|
||||
return message;
|
||||
};
|
||||
|
||||
const LANGUAGE_FLAGS: Record<string, string> = {
|
||||
'한국어': '🇰🇷',
|
||||
'English': '🇺🇸',
|
||||
@@ -131,7 +144,10 @@ const SoundStudioContent: React.FC<SoundStudioContentProps> = ({
|
||||
}
|
||||
} else {
|
||||
setStatus('error');
|
||||
setErrorMessage(error instanceof Error ? error.message : t('soundStudio.musicGenerationError'));
|
||||
setErrorMessage(sanitizeError(
|
||||
error instanceof Error ? error.message : '',
|
||||
t('soundStudio.musicGenerationError')
|
||||
));
|
||||
setRetryCount(0);
|
||||
}
|
||||
}
|
||||
@@ -168,7 +184,10 @@ const SoundStudioContent: React.FC<SoundStudioContentProps> = ({
|
||||
} catch (error) {
|
||||
console.error('Song regeneration failed:', error);
|
||||
setStatus('error');
|
||||
setErrorMessage(error instanceof Error ? error.message : t('soundStudio.songRegenerationError'));
|
||||
setErrorMessage(sanitizeError(
|
||||
error instanceof Error ? error.message : '',
|
||||
t('soundStudio.songRegenerationError')
|
||||
));
|
||||
setRetryCount(0);
|
||||
}
|
||||
};
|
||||
@@ -362,7 +381,10 @@ const SoundStudioContent: React.FC<SoundStudioContentProps> = ({
|
||||
} catch (error) {
|
||||
console.error('Music generation failed:', error);
|
||||
setStatus('error');
|
||||
setErrorMessage(error instanceof Error ? error.message : t('soundStudio.musicGenerationError'));
|
||||
setErrorMessage(sanitizeError(
|
||||
error instanceof Error ? error.message : '',
|
||||
t('soundStudio.musicGenerationError')
|
||||
));
|
||||
setRetryCount(0);
|
||||
}
|
||||
};
|
||||
@@ -496,8 +518,8 @@ const SoundStudioContent: React.FC<SoundStudioContentProps> = ({
|
||||
{['한국어', 'English', '中文'].map((lang) => (
|
||||
<button
|
||||
key={lang}
|
||||
onClick={() => !isGenerating && selectedType !== '배경음악' && setSelectedLang(lang)}
|
||||
disabled={isGenerating || selectedType === '배경음악'}
|
||||
onClick={() => !isGenerating && setSelectedLang(lang)}
|
||||
disabled={isGenerating}
|
||||
className={`genre-btn ${selectedLang === lang ? 'active' : ''}`}
|
||||
>
|
||||
<span>{LANGUAGE_FLAGS[lang]}</span> {lang}
|
||||
@@ -508,8 +530,8 @@ const SoundStudioContent: React.FC<SoundStudioContentProps> = ({
|
||||
{['日本語', 'ไทย', 'Tiếng Việt'].map((lang) => (
|
||||
<button
|
||||
key={lang}
|
||||
onClick={() => !isGenerating && selectedType !== '배경음악' && setSelectedLang(lang)}
|
||||
disabled={isGenerating || selectedType === '배경음악'}
|
||||
onClick={() => !isGenerating && setSelectedLang(lang)}
|
||||
disabled={isGenerating}
|
||||
className={`genre-btn ${selectedLang === lang ? 'active' : ''}`}
|
||||
>
|
||||
<span>{LANGUAGE_FLAGS[lang]}</span> {lang}
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
import React, { useState, useRef, useCallback } from 'react';
|
||||
import React, { useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { searchAccommodation, AccommodationSearchItem, AutocompleteRequest } from '../../utils/api';
|
||||
import { AutocompleteRequest } from '../../utils/api';
|
||||
import { CrawlingResponse } from '../../types/api';
|
||||
import { useSearchHistory } from '../../components/SearchHistory/useSearchHistory';
|
||||
import SearchHistoryDropdown from '../../components/SearchHistory/SearchHistoryDropdown';
|
||||
import BusinessNameInputModal from '../../components/BusinessNameInputModal';
|
||||
|
||||
type SearchType = 'url' | 'name' | 'manual';
|
||||
import SearchInputForm, { SearchType } from '../../components/SearchInputForm';
|
||||
|
||||
// 환경변수에서 테스트 모드 확인
|
||||
const isTestPage = import.meta.env.VITE_IS_TESTPAGE === 'true';
|
||||
@@ -21,34 +17,8 @@ interface UrlInputContentProps {
|
||||
|
||||
const UrlInputContent: React.FC<UrlInputContentProps> = ({ onAnalyze, onAutocomplete, onManualInput, onTestData, error }) => {
|
||||
const { t, i18n } = useTranslation();
|
||||
const [inputValue, setInputValue] = useState('');
|
||||
const [searchType, setSearchType] = useState<SearchType>('name');
|
||||
const [isDropdownOpen, setIsDropdownOpen] = useState(false);
|
||||
const [autocompleteResults, setAutocompleteResults] = useState<AccommodationSearchItem[]>([]);
|
||||
const [isAutocompleteLoading, setIsAutocompleteLoading] = useState(false);
|
||||
const [showAutocomplete, setShowAutocomplete] = useState(false);
|
||||
const [selectedItem, setSelectedItem] = useState<AccommodationSearchItem | null>(null);
|
||||
const [isLoadingTest, setIsLoadingTest] = useState(false);
|
||||
const [isManualModalOpen, setIsManualModalOpen] = useState(false);
|
||||
const { filteredHistory, showHistory, openHistory, closeHistory, hideOnInput, deleteItem } = useSearchHistory(searchType === 'manual' ? 'name' : searchType);
|
||||
|
||||
const handleSelectHistory = (item: { type: 'url' | 'name'; value: string; address?: string; roadAddress?: string }) => {
|
||||
closeHistory();
|
||||
if (item.type === 'url') {
|
||||
setSearchType('url');
|
||||
setInputValue(item.value);
|
||||
} else {
|
||||
setSearchType('name');
|
||||
setInputValue(item.value);
|
||||
setSelectedItem({
|
||||
title: item.value,
|
||||
address: item.address || '',
|
||||
roadAddress: item.roadAddress || '',
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// 테스트 데이터 로드 핸들러
|
||||
const handleTestData = async () => {
|
||||
if (!onTestData) return;
|
||||
setIsLoadingTest(true);
|
||||
@@ -63,273 +33,21 @@ const UrlInputContent: React.FC<UrlInputContentProps> = ({ onAnalyze, onAutocomp
|
||||
setIsLoadingTest(false);
|
||||
}
|
||||
};
|
||||
const [highlightedIndex, setHighlightedIndex] = useState<number>(-1);
|
||||
const debounceRef = useRef<NodeJS.Timeout | null>(null);
|
||||
const autocompleteRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
const searchTypeOptions = [
|
||||
{ value: 'url' as SearchType, label: 'URL' },
|
||||
{ value: 'name' as SearchType, label: t('urlInput.searchTypeBusinessName') },
|
||||
// { value: 'manual' as SearchType, label: t('urlInput.searchTypeManual') },
|
||||
];
|
||||
|
||||
const getPlaceholder = () => {
|
||||
return searchType === 'url'
|
||||
? 'https://naver.me/abcdef'
|
||||
: t('urlInput.placeholderBusinessName');
|
||||
};
|
||||
|
||||
const getGuideText = () => {
|
||||
return searchType === 'url'
|
||||
? t('urlInput.guideUrl')
|
||||
: t('urlInput.guideBusinessName');
|
||||
};
|
||||
|
||||
// 업체명 검색 시 자동완성 (디바운스 적용)
|
||||
const handleAutocompleteSearch = useCallback(async (query: string) => {
|
||||
if (!query.trim() || searchType !== 'name') {
|
||||
setAutocompleteResults([]);
|
||||
setShowAutocomplete(false);
|
||||
return;
|
||||
}
|
||||
|
||||
setIsAutocompleteLoading(true);
|
||||
try {
|
||||
const response = await searchAccommodation(query);
|
||||
setAutocompleteResults(response.items || []);
|
||||
setShowAutocomplete(response.items && response.items.length > 0);
|
||||
} catch (error) {
|
||||
console.error('자동완성 검색 오류:', error);
|
||||
setAutocompleteResults([]);
|
||||
setShowAutocomplete(false);
|
||||
} finally {
|
||||
setIsAutocompleteLoading(false);
|
||||
}
|
||||
}, [searchType]);
|
||||
|
||||
// 자동완성 항목 선택 - 업체 정보 저장
|
||||
const handleSelectAutocomplete = (item: AccommodationSearchItem) => {
|
||||
setInputValue(item.title.replace(/<[^>]*>/g, '')); // HTML 태그 제거
|
||||
setSelectedItem(item); // 선택된 업체 정보 저장
|
||||
setShowAutocomplete(false);
|
||||
setAutocompleteResults([]);
|
||||
setHighlightedIndex(-1);
|
||||
};
|
||||
|
||||
// 키보드 네비게이션 핸들러
|
||||
const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
|
||||
if (e.key === 'Enter') {
|
||||
e.preventDefault();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!showAutocomplete || autocompleteResults.length === 0) return;
|
||||
|
||||
switch (e.key) {
|
||||
case 'ArrowDown':
|
||||
e.preventDefault();
|
||||
setHighlightedIndex(prev =>
|
||||
prev < autocompleteResults.length - 1 ? prev + 1 : 0
|
||||
);
|
||||
break;
|
||||
case 'ArrowUp':
|
||||
e.preventDefault();
|
||||
setHighlightedIndex(prev =>
|
||||
prev > 0 ? prev - 1 : autocompleteResults.length - 1
|
||||
);
|
||||
break;
|
||||
case 'Escape':
|
||||
setShowAutocomplete(false);
|
||||
setHighlightedIndex(-1);
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
// 붙여넣기 시 URL만 추출
|
||||
const handlePaste = (e: React.ClipboardEvent<HTMLInputElement>) => {
|
||||
if (searchType !== 'url') return;
|
||||
const pasted = e.clipboardData.getData('text');
|
||||
const urlMatch = pasted.match(/https?:\/\/[^\s]+/);
|
||||
if (urlMatch) {
|
||||
e.preventDefault();
|
||||
setInputValue(urlMatch[0]);
|
||||
}
|
||||
};
|
||||
|
||||
// 폼 제출 처리
|
||||
const handleSubmit = (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
};
|
||||
|
||||
const handleAnalyzeClick = () => {
|
||||
if (!inputValue.trim()) return;
|
||||
|
||||
if (searchType === 'name') {
|
||||
if (selectedItem && onAutocomplete) {
|
||||
const request: AutocompleteRequest = {
|
||||
address: selectedItem.address,
|
||||
roadAddress: selectedItem.roadAddress,
|
||||
title: selectedItem.title,
|
||||
};
|
||||
onAutocomplete(request);
|
||||
}
|
||||
// selectedItem 없으면 아무것도 하지 않음 (드롭다운에서 선택 필요)
|
||||
} else {
|
||||
// URL 검색인 경우 기존 로직
|
||||
onAnalyze(inputValue.trim(), searchType);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="url-input-container">
|
||||
<div className="url-input-content">
|
||||
{/* 로고 */}
|
||||
<div className="url-input-logo">
|
||||
<img src="/assets/images/ado2-logo.svg" alt="ADO2" />
|
||||
<img src="/assets/images/ADO2_with Slogan_white.svg" alt="ADO2" />
|
||||
</div>
|
||||
|
||||
{/* URL 입력 폼 */}
|
||||
<form onSubmit={handleSubmit} className="url-input-form">
|
||||
<div className="url-input-wrapper">
|
||||
{/* 드롭다운 */}
|
||||
<div className="url-input-dropdown-container">
|
||||
<button
|
||||
type="button"
|
||||
className="url-input-dropdown-trigger"
|
||||
onClick={() => setIsDropdownOpen(!isDropdownOpen)}
|
||||
>
|
||||
<span>{searchTypeOptions.find(opt => opt.value === searchType)?.label}</span>
|
||||
<svg
|
||||
width="12"
|
||||
height="12"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
className={`url-input-dropdown-arrow ${isDropdownOpen ? 'open' : ''}`}
|
||||
>
|
||||
<path d="M6 9l6 6 6-6" />
|
||||
</svg>
|
||||
</button>
|
||||
{isDropdownOpen && (
|
||||
<div className="url-input-dropdown-menu">
|
||||
{searchTypeOptions.map((option) => (
|
||||
<button
|
||||
key={option.value}
|
||||
type="button"
|
||||
className={`url-input-dropdown-item ${searchType === option.value ? 'active' : ''}`}
|
||||
onClick={() => {
|
||||
if (option.value === 'manual') {
|
||||
setIsManualModalOpen(true);
|
||||
setIsDropdownOpen(false);
|
||||
} else {
|
||||
setSearchType(option.value);
|
||||
setIsDropdownOpen(false);
|
||||
}
|
||||
}}
|
||||
>
|
||||
{option.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* 입력 필드 */}
|
||||
<div className="url-input-field-container" ref={autocompleteRef}>
|
||||
<input
|
||||
type="text"
|
||||
value={inputValue}
|
||||
onChange={(e) => {
|
||||
let value = e.target.value;
|
||||
|
||||
// URL 모드일 때 URL만 추출 (예: "[네이버 지도] https://...")
|
||||
if (searchType === 'url') {
|
||||
const urlMatch = value.match(/https?:\/\/\S+/);
|
||||
if (urlMatch && urlMatch[0] !== value) {
|
||||
value = urlMatch[0];
|
||||
}
|
||||
}
|
||||
|
||||
setInputValue(value);
|
||||
hideOnInput(value);
|
||||
|
||||
// 업체명 검색일 때 자동완성 검색 (디바운스)
|
||||
if (searchType === 'name') {
|
||||
if (debounceRef.current) {
|
||||
clearTimeout(debounceRef.current);
|
||||
}
|
||||
debounceRef.current = setTimeout(() => {
|
||||
handleAutocompleteSearch(value);
|
||||
}, 300);
|
||||
}
|
||||
}}
|
||||
onPaste={handlePaste}
|
||||
onFocus={() => {
|
||||
if (searchType === 'name' && autocompleteResults.length > 0) {
|
||||
setShowAutocomplete(true);
|
||||
}
|
||||
openHistory(inputValue);
|
||||
}}
|
||||
onBlur={() => setTimeout(() => closeHistory(), 150)}
|
||||
placeholder={getPlaceholder()}
|
||||
className="url-input-field"
|
||||
/>
|
||||
|
||||
{/* 최근 검색 히스토리 */}
|
||||
{showHistory && !showAutocomplete && (
|
||||
<SearchHistoryDropdown
|
||||
items={filteredHistory}
|
||||
onSelect={handleSelectHistory}
|
||||
onDelete={(e, value) => { e.preventDefault(); e.stopPropagation(); deleteItem(value); }}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* 자동완성 결과 */}
|
||||
{showAutocomplete && searchType === 'name' && (
|
||||
<div className="url-input-autocomplete-dropdown">
|
||||
{isAutocompleteLoading ? (
|
||||
<div className="url-input-autocomplete-loading">{t('urlInput.searching')}</div>
|
||||
) : (
|
||||
autocompleteResults.map((item, index) => (
|
||||
<button
|
||||
key={index}
|
||||
type="button"
|
||||
className="url-input-autocomplete-item"
|
||||
onMouseDown={(e) => {
|
||||
e.preventDefault();
|
||||
handleSelectAutocomplete(item);
|
||||
}}
|
||||
>
|
||||
<div className="url-input-autocomplete-title" dangerouslySetInnerHTML={{ __html: item.title }} />
|
||||
<div className="url-input-autocomplete-address">{item.roadAddress || item.address}</div>
|
||||
</button>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 안내 텍스트 */}
|
||||
<p className="url-input-guide">
|
||||
{getGuideText()}
|
||||
</p>
|
||||
|
||||
{/* 에러 메시지 */}
|
||||
{error && (
|
||||
<p className="url-input-error">{error}</p>
|
||||
)}
|
||||
|
||||
{/* 검색 버튼 */}
|
||||
<button type="button" onClick={handleAnalyzeClick} className="url-input-button">
|
||||
{t('landing.hero.analyzeButton')}
|
||||
</button>
|
||||
|
||||
<button type="button" className="url-input-manual-button" onClick={() => setIsManualModalOpen(true)}>
|
||||
{t('urlInput.searchTypeManual')}
|
||||
</button>
|
||||
</form>
|
||||
<SearchInputForm
|
||||
onAnalyze={onAnalyze}
|
||||
onAutocomplete={onAutocomplete}
|
||||
onManualInput={onManualInput}
|
||||
error={error}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* 테스트 버튼 (VITE_IS_TESTPAGE=true일 때만 표시) */}
|
||||
@@ -342,13 +60,6 @@ const UrlInputContent: React.FC<UrlInputContentProps> = ({ onAnalyze, onAutocomp
|
||||
{isLoadingTest ? t('urlInput.testDataLoading') : t('urlInput.testData')}
|
||||
</button>
|
||||
)}
|
||||
|
||||
{isManualModalOpen && (
|
||||
<BusinessNameInputModal
|
||||
onClose={() => setIsManualModalOpen(false)}
|
||||
onSubmit={(businessName, address) => { setIsManualModalOpen(false); onManualInput?.(businessName, address); }}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user