브랜드 분석 페이지 수정, ado2 컨텐츠 추가, header jwt 인증 작업 .
This commit is contained in:
1 parent
7d4f3c7e05
commit
7ee911f0aa
7 files changed
+865
-139
No files matched your search
@@ -1,8 +1,12 @@
|
||||
|
||||
import React, { useState, useEffect, useRef } from 'react';
|
||||
import React, { useState, useEffect, useRef, useCallback } from 'react';
|
||||
import { searchNaverLocal, NaverLocalSearchItem, AutocompleteRequest } from '../../utils/api';
|
||||
|
||||
type SearchType = 'url' | 'name';
|
||||
|
||||
interface HeroSectionProps {
|
||||
onAnalyze?: (url: string) => void;
|
||||
onAnalyze?: (value: string, type?: SearchType) => void;
|
||||
onAutocomplete?: (data: AutocompleteRequest) => void;
|
||||
onNext?: () => void;
|
||||
error?: string | null;
|
||||
scrollProgress?: number; // 0 ~ 1 (스크롤 진행률)
|
||||
@@ -47,12 +51,78 @@ const orbConfigs: OrbConfig[] = [
|
||||
{ id: 'orb-6', size: 450, initialX: 65, initialY: 70, color: 'radial-gradient(circle, rgba(180, 255, 235, 0.95) 15%, rgba(200, 160, 255, 0.8) 50%, rgba(94, 235, 195, 0.45) 100%)', minX: 45, maxX: 110, minY: 55, maxY: 110 },
|
||||
];
|
||||
|
||||
const HeroSection: React.FC<HeroSectionProps> = ({ onAnalyze, onNext, error: externalError, scrollProgress = 0 }) => {
|
||||
const [url, setUrl] = useState('');
|
||||
const HeroSection: React.FC<HeroSectionProps> = ({ onAnalyze, onAutocomplete, onNext, error: externalError, scrollProgress = 0 }) => {
|
||||
const [inputValue, setInputValue] = useState('');
|
||||
const [searchType, setSearchType] = useState<SearchType>('url');
|
||||
const [isDropdownOpen, setIsDropdownOpen] = useState(false);
|
||||
const [localError, setLocalError] = useState('');
|
||||
const [isFocused, setIsFocused] = useState(false);
|
||||
const [autocompleteResults, setAutocompleteResults] = useState<NaverLocalSearchItem[]>([]);
|
||||
const [isAutocompleteLoading, setIsAutocompleteLoading] = useState(false);
|
||||
const [showAutocomplete, setShowAutocomplete] = useState(false);
|
||||
const orbRefs = useRef<(HTMLDivElement | null)[]>([]);
|
||||
const animationRefs = useRef<number[]>([]);
|
||||
const dropdownRef = useRef<HTMLDivElement>(null);
|
||||
const autocompleteRef = useRef<HTMLDivElement>(null);
|
||||
const debounceRef = useRef<NodeJS.Timeout | null>(null);
|
||||
|
||||
const searchTypeOptions = [
|
||||
{ value: 'url' as SearchType, label: 'URL' },
|
||||
{ value: 'name' as SearchType, label: '업체명' },
|
||||
];
|
||||
|
||||
// 드롭다운 외부 클릭 감지
|
||||
useEffect(() => {
|
||||
const handleClickOutside = (event: MouseEvent) => {
|
||||
if (dropdownRef.current && !dropdownRef.current.contains(event.target as Node)) {
|
||||
setIsDropdownOpen(false);
|
||||
}
|
||||
if (autocompleteRef.current && !autocompleteRef.current.contains(event.target as Node)) {
|
||||
setShowAutocomplete(false);
|
||||
}
|
||||
};
|
||||
document.addEventListener('mousedown', handleClickOutside);
|
||||
return () => document.removeEventListener('mousedown', handleClickOutside);
|
||||
}, []);
|
||||
|
||||
// 업체명 검색 시 자동완성 (디바운스 적용)
|
||||
const handleAutocompleteSearch = useCallback(async (query: string) => {
|
||||
if (!query.trim() || searchType !== 'name') {
|
||||
setAutocompleteResults([]);
|
||||
setShowAutocomplete(false);
|
||||
return;
|
||||
}
|
||||
|
||||
setIsAutocompleteLoading(true);
|
||||
try {
|
||||
const response = await searchNaverLocal(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 = async (item: NaverLocalSearchItem) => {
|
||||
const request: AutocompleteRequest = {
|
||||
address: item.address,
|
||||
roadAddress: item.roadAddress,
|
||||
title: item.title,
|
||||
};
|
||||
|
||||
setInputValue(item.title.replace(/<[^>]*>/g, '')); // HTML 태그 제거
|
||||
setShowAutocomplete(false);
|
||||
setAutocompleteResults([]);
|
||||
|
||||
if (onAutocomplete) {
|
||||
onAutocomplete(request);
|
||||
}
|
||||
};
|
||||
|
||||
// Random movement for orbs
|
||||
useEffect(() => {
|
||||
@@ -132,20 +202,32 @@ const HeroSection: React.FC<HeroSectionProps> = ({ onAnalyze, onNext, error: ext
|
||||
|
||||
const error = externalError || localError;
|
||||
|
||||
const getPlaceholder = () => {
|
||||
return searchType === 'url'
|
||||
? 'https://www.castad.com'
|
||||
: '업체명을 입력하세요';
|
||||
};
|
||||
|
||||
const getGuideText = () => {
|
||||
return searchType === 'url'
|
||||
? 'URL에서 가져온 정보로 영상이 자동 생성됩니다.'
|
||||
: '업체명으로 검색하여 정보를 가져옵니다.';
|
||||
};
|
||||
|
||||
const handleStart = () => {
|
||||
if (!url.trim()) {
|
||||
setLocalError('URL을 입력해주세요.');
|
||||
if (!inputValue.trim()) {
|
||||
setLocalError(searchType === 'url' ? 'URL을 입력해주세요.' : '업체명을 입력해주세요.');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isValidUrl(url.trim())) {
|
||||
if (searchType === 'url' && !isValidUrl(inputValue.trim())) {
|
||||
setLocalError('올바른 URL 형식이 아닙니다. (예: https://example.com)');
|
||||
return;
|
||||
}
|
||||
|
||||
setLocalError('');
|
||||
if (onAnalyze) {
|
||||
onAnalyze(url);
|
||||
onAnalyze(inputValue, searchType);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -183,34 +265,116 @@ const HeroSection: React.FC<HeroSectionProps> = ({ onAnalyze, onNext, error: ext
|
||||
|
||||
{/* Input Form */}
|
||||
<div className="hero-form">
|
||||
<span className="hero-input-label">URL 입력</span>
|
||||
<div className={`hero-input-wrapper ${isFocused ? 'focused' : ''} ${error ? 'error' : ''} ${url && !isFocused ? 'filled' : ''}`}>
|
||||
<input
|
||||
type="text"
|
||||
value={url}
|
||||
onChange={(e) => {
|
||||
setUrl(e.target.value);
|
||||
if (localError) setLocalError('');
|
||||
}}
|
||||
onFocus={() => setIsFocused(true)}
|
||||
onBlur={() => setIsFocused(false)}
|
||||
placeholder="https://www.castad.com"
|
||||
className={`hero-input ${url ? 'has-value' : ''}`}
|
||||
/>
|
||||
{url && (
|
||||
<div className={`hero-input-wrapper ${isFocused ? 'focused' : ''} ${error ? 'error' : ''} ${inputValue && !isFocused ? 'filled' : ''}`}>
|
||||
{/* 드롭다운 */}
|
||||
<div className="hero-dropdown-container" ref={dropdownRef}>
|
||||
<button
|
||||
type="button"
|
||||
className="hero-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={`hero-dropdown-arrow ${isDropdownOpen ? 'open' : ''}`}
|
||||
>
|
||||
<path d="M6 9l6 6 6-6" />
|
||||
</svg>
|
||||
</button>
|
||||
{isDropdownOpen && (
|
||||
<div className="hero-dropdown-menu">
|
||||
{searchTypeOptions.map((option) => (
|
||||
<button
|
||||
key={option.value}
|
||||
type="button"
|
||||
className={`hero-dropdown-item ${searchType === option.value ? 'active' : ''}`}
|
||||
onClick={() => {
|
||||
setSearchType(option.value);
|
||||
setIsDropdownOpen(false);
|
||||
}}
|
||||
>
|
||||
{option.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="hero-input-container" ref={autocompleteRef}>
|
||||
<input
|
||||
type="text"
|
||||
value={inputValue}
|
||||
onChange={(e) => {
|
||||
const value = e.target.value;
|
||||
setInputValue(value);
|
||||
if (localError) setLocalError('');
|
||||
|
||||
// 업체명 검색일 때 자동완성 검색 (디바운스)
|
||||
if (searchType === 'name') {
|
||||
if (debounceRef.current) {
|
||||
clearTimeout(debounceRef.current);
|
||||
}
|
||||
debounceRef.current = setTimeout(() => {
|
||||
handleAutocompleteSearch(value);
|
||||
}, 300);
|
||||
}
|
||||
}}
|
||||
onFocus={() => {
|
||||
setIsFocused(true);
|
||||
if (searchType === 'name' && autocompleteResults.length > 0) {
|
||||
setShowAutocomplete(true);
|
||||
}
|
||||
}}
|
||||
onBlur={() => setIsFocused(false)}
|
||||
placeholder={getPlaceholder()}
|
||||
className={`hero-input ${inputValue ? 'has-value' : ''}`}
|
||||
/>
|
||||
|
||||
{/* 자동완성 결과 */}
|
||||
{showAutocomplete && searchType === 'name' && (
|
||||
<div className="hero-autocomplete-dropdown">
|
||||
{isAutocompleteLoading ? (
|
||||
<div className="hero-autocomplete-loading">검색 중...</div>
|
||||
) : (
|
||||
autocompleteResults.map((item, index) => (
|
||||
<button
|
||||
key={index}
|
||||
type="button"
|
||||
className="hero-autocomplete-item"
|
||||
onMouseDown={(e) => {
|
||||
e.preventDefault();
|
||||
handleSelectAutocomplete(item);
|
||||
}}
|
||||
>
|
||||
<div className="hero-autocomplete-title" dangerouslySetInnerHTML={{ __html: item.title }} />
|
||||
<div className="hero-autocomplete-address">{item.roadAddress || item.address}</div>
|
||||
</button>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{inputValue && (
|
||||
<button
|
||||
type="button"
|
||||
className="hero-input-clear"
|
||||
onClick={() => {
|
||||
setUrl('');
|
||||
setInputValue('');
|
||||
setLocalError('');
|
||||
setAutocompleteResults([]);
|
||||
setShowAutocomplete(false);
|
||||
}}
|
||||
>
|
||||
<img src="/assets/images/input-clear-icon.svg" alt="Clear" />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
<span className="hero-input-hint">URL에서 가져온 정보로 영상이 자동 생성됩니다.</span>
|
||||
<span className="hero-input-hint">{getGuideText()}</span>
|
||||
{error && (
|
||||
<p className="hero-error">{error}</p>
|
||||
)}
|
||||
|
||||
Reference in new issue
Block a user