브랜드 분석 페이지 수정 완료 .

This commit is contained in:
HyeongBaeYang committed 2026-01-26 17:38:04 +09:00
1 parent 3774221202
commit 7d4f3c7e05
16 files changed
+1169 -124

No files matched your search

+461 -124
View File
@@ -1,6 +1,8 @@
import React from 'react';
import React, { useMemo } from 'react';
import { CrawlingResponse } from '../../types/api';
import GeometricChart, { USP } from './GeometricChart';
import KeywordBubble from './KeywordBubble';
interface AnalysisResultSectionProps {
onBack: () => void;
@@ -8,171 +10,506 @@ interface AnalysisResultSectionProps {
data: CrawlingResponse;
}
// 텍스트를 포맷팅 (개행 처리, 제목 스타일링, 해시태그 스타일링)
const formatReportText = (text: string): React.ReactNode[] => {
if (!text) return [];
type MarkdownBlock =
| { type: 'heading'; level: number; text: string }
| { type: 'list'; ordered: boolean; items: string[] }
| { type: 'paragraph'; text: string };
// 먼저 \n으로 단락 분리
const paragraphs = text.split('\n');
const parseMarkdownBlocks = (text: string): MarkdownBlock[] => {
const lines = text.split(/\r?\n/);
const blocks: MarkdownBlock[] = [];
let paragraphLines: string[] = [];
let listItems: string[] = [];
let listOrdered = false;
return paragraphs.map((paragraph, pIdx) => {
// 빈 줄은 줄바꿈으로 처리
if (paragraph.trim() === '') {
return <br key={pIdx} />;
const flushParagraph = () => {
if (paragraphLines.length === 0) return;
blocks.push({ type: 'paragraph', text: paragraphLines.join(' ') });
paragraphLines = [];
};
const flushList = () => {
if (listItems.length === 0) return;
blocks.push({ type: 'list', ordered: listOrdered, items: listItems });
listItems = [];
listOrdered = false;
};
lines.forEach((line) => {
const trimmed = line.trim();
if (!trimmed) {
flushParagraph();
flushList();
return;
}
// 제목 패턴 (한글로 된 짧은 텍스트로 시작하는 경우)
const titleMatch = paragraph.match(/^(타겟 고객|핵심 차별점|지역 특성|시즌별 포인트)$/);
if (titleMatch) {
const headingMatch = trimmed.match(/^(#{1,6})\s+(.*)$/);
if (headingMatch) {
flushParagraph();
flushList();
blocks.push({
type: 'heading',
level: headingMatch[1].length,
text: headingMatch[2].trim(),
});
return;
}
const listMatch = trimmed.match(/^([-*+]|\d+\.)\s+(.*)$/);
if (listMatch) {
flushParagraph();
listOrdered = listMatch[1].endsWith('.');
listItems.push(listMatch[2].trim());
return;
}
flushList();
paragraphLines.push(trimmed);
});
flushParagraph();
flushList();
return blocks;
};
const renderInlineMarkdown = (text: string): React.ReactNode[] => {
const parts = text.split(/(\*\*[^*]+\*\*|`[^`]+`|#[^\s#]+)/g).filter(Boolean);
return parts.map((part, idx) => {
if (part.startsWith('**') && part.endsWith('**')) {
return (
<div key={pIdx} style={{ marginTop: pIdx > 0 ? '16px' : '0' }}>
<strong style={{ color: '#94FBE0', fontSize: '18px' }}>{paragraph}</strong>
</div>
<strong key={idx} className="text-white">
{part.slice(2, -2)}
</strong>
);
}
if (part.startsWith('`') && part.endsWith('`')) {
return (
<code key={idx} className="px-1 py-0.5 rounded bg-brand-bg/60 text-brand-accent text-xs">
{part.slice(1, -1)}
</code>
);
}
if (part.startsWith('#')) {
return (
<span key={idx} className="text-brand-purple font-semibold">
{part}
</span>
);
}
return <span key={idx}>{part}</span>;
});
};
// 해시태그 처리
const hashtagParts = paragraph.split(/(#[^\s#]+)/g);
const renderMarkdown = (text: string) => {
const blocks = parseMarkdownBlocks(text);
return blocks.map((block, idx) => {
if (block.type === 'heading') {
return (
<h4
key={idx}
className="text-sm font-semibold text-brand-accent uppercase tracking-wider mt-4 first:mt-0"
>
{block.text}
</h4>
);
}
if (block.type === 'list') {
const ListTag = block.ordered ? 'ol' : 'ul';
const listClass = block.ordered ? 'list-decimal' : 'list-disc';
return (
<ListTag key={idx} className={`space-y-1 text-sm text-brand-text/90 ${listClass} pl-4`}>
{block.items.map((item, itemIdx) => (
<li key={itemIdx}>{renderInlineMarkdown(item)}</li>
))}
</ListTag>
);
}
return (
<div key={pIdx} style={{ marginBottom: '4px' }}>
{hashtagParts.map((segment, segIdx) => {
if (segment.startsWith('#')) {
return (
<span key={segIdx} style={{ color: '#A78BFA' }}>
{segment}
</span>
);
}
return segment;
})}
</div>
<p key={idx} className="text-sm text-brand-text/80 leading-relaxed">
{renderInlineMarkdown(block.text)}
</p>
);
});
};
// 셀링 포인트 카드 타입
interface SellingPointCard {
title: string;
items: string[];
}
const splitMarkdownSections = (text: string) => {
const blocks = parseMarkdownBlocks(text);
const sections: Array<{ title: string; content: string }> = [];
let currentTitle = '본문';
let contentLines: string[] = [];
// facilities 배열을 셀링 포인트 카드 형태로 변환
const parseSellingPoints = (facilities: string[]): SellingPointCard[] => {
// 기본 카테고리 정의
const categories: SellingPointCard[] = [
{ title: '브랜드 컨셉', items: [] },
{ title: '프라이버시', items: [] },
{ title: '로컬 결합', items: [] },
{ title: '무드/비주얼', items: [] },
{ title: '편의/신뢰', items: [] },
{ title: '체류형 가치', items: [] },
];
// facilities를 카테고리에 분배 (최대 2개씩)
facilities.forEach((facility, idx) => {
const categoryIdx = Math.floor(idx / 2) % categories.length;
if (categories[categoryIdx].items.length < 2) {
categories[categoryIdx].items.push(facility);
blocks.forEach((block) => {
if (block.type === 'heading') {
if (contentLines.length > 0) {
sections.push({ title: currentTitle, content: contentLines.join('\n') });
}
currentTitle = block.text;
contentLines = [];
return;
}
if (block.type === 'list') {
contentLines.push(block.items.map((item) => `- ${item}`).join('\n'));
return;
}
contentLines.push(block.text);
});
// 아이템이 있는 카테고리만 반환
return categories.filter(cat => cat.items.length > 0);
if (contentLines.length > 0) {
sections.push({ title: currentTitle, content: contentLines.join('\n') });
}
return sections;
};
const pickSectionContent = (sections: Array<{ title: string; content: string }>, keywords: string[]) => {
const lowered = keywords.map((keyword) => keyword.toLowerCase());
const match = sections.find((section) =>
lowered.some((keyword) => section.title.toLowerCase().includes(keyword))
);
return match?.content || '';
};
const buildUSPs = (facilities: string[], tags: string[]) => {
const candidates = [...facilities, ...tags.filter((tag) => !facilities.includes(tag))];
const labels = candidates.slice(0, 7);
const subLabels = ['CONCEPT', 'PRIVACY', 'LOCAL', 'MOOD', 'TRUST', 'STAY', 'PHOTO', 'HEALING'];
if (labels.length < 3) {
return [
{
label: '브랜드 컨셉',
subLabel: 'CONCEPT',
score: 88,
description: '분석 데이터 기반 컨셉 도출',
},
{
label: '프라이버시',
subLabel: 'PRIVACY',
score: 84,
description: '프라이빗 경험 강조 포인트',
},
{
label: '무드',
subLabel: 'MOOD',
score: 82,
description: '감성적 장면 강조',
},
];
}
return labels.map((label, idx) => ({
label,
subLabel: subLabels[idx % subLabels.length],
score: Math.min(96, 78 + idx * 3 + (label.length % 6)),
description: tags[idx] ? `키워드: ${tags[idx]}` : label,
}));
};
const buildTargets = (sectionText: string, tags: string[]) => {
if (!sectionText.trim()) {
return [
{
segment: '타겟 고객',
age: '',
needs: tags.slice(0, 3),
triggers: [],
},
];
}
const blocks = parseMarkdownBlocks(sectionText);
const listBlock = blocks.find((block) => block.type === 'list') as
| { type: 'list'; ordered: boolean; items: string[] }
| undefined;
const rawItems = listBlock?.items ?? sectionText.split(/\r?\n/).filter(Boolean);
return rawItems.slice(0, 3).map((item, idx) => {
const [segmentPart, detailPart] = item.split(':');
const segment = (segmentPart || item).trim();
const detail = (detailPart || '').trim();
const needs = detail
? detail
.split(/[,/·]/)
.map((value) => value.trim())
.filter(Boolean)
: tags.slice(idx * 2, idx * 2 + 3);
const ageMatch = segment.match(/(\d{2}~\d{2}세|\d{2}대|\d{2}s)/);
return {
segment,
age: ageMatch ? ageMatch[0] : '',
needs,
triggers: [],
};
});
};
const ArrowLeftIcon = () => (
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
<path d="M15 18l-6-6 6-6" />
</svg>
);
const SparklesIcon = ({ className = '' }: { className?: string }) => (
<svg className={className} viewBox="0 0 24 24" fill="currentColor" aria-hidden>
<path d="M12 2l2.4 6.8L22 12l-7.6 3.2L12 22l-2.4-6.8L2 12l7.6-3.2L12 2z" />
</svg>
);
const MapPinIcon = () => (
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
<path d="M12 22s7-6.1 7-12a7 7 0 10-14 0c0 5.9 7 12 7 12z" />
<circle cx="12" cy="10" r="3" />
</svg>
);
const TargetIcon = () => (
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
<circle cx="12" cy="12" r="8" />
<circle cx="12" cy="12" r="3" />
<path d="M12 2v4M22 12h-4M12 22v-4M2 12h4" />
</svg>
);
const UsersIcon = () => (
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
<path d="M16 11a4 4 0 10-8 0" />
<path d="M4 20c0-3.3 3.6-6 8-6s8 2.7 8 6" />
<circle cx="12" cy="7" r="3" />
</svg>
);
const CrownIcon = ({ className = '' }: { className?: string }) => (
<svg className={className} viewBox="0 0 24 24" fill="currentColor" aria-hidden>
<path d="M3 7l4 4 5-6 5 6 4-4v10H3z" />
</svg>
);
const TrendingUpIcon = () => (
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
<path d="M3 17l6-6 4 4 7-7" />
<path d="M14 7h7v7" />
</svg>
);
const LayoutGridIcon = () => (
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
<rect x="3" y="3" width="7" height="7" />
<rect x="14" y="3" width="7" height="7" />
<rect x="14" y="14" width="7" height="7" />
<rect x="3" y="14" width="7" height="7" />
</svg>
);
const AnalysisResultSection: React.FC<AnalysisResultSectionProps> = ({ onBack, onGenerate, data }) => {
const { processed_info, marketing_analysis } = data;
const tags = marketing_analysis.tags || [];
const facilities = marketing_analysis.facilities || [];
const sellingPoints = parseSellingPoints(facilities);
const reportSections = useMemo(
() => splitMarkdownSections(marketing_analysis.report || ''),
[marketing_analysis.report]
);
const locationAnalysis =
pickSectionContent(reportSections, ['지역', '입지']) || reportSections[0]?.content || '';
const conceptAnalysis =
pickSectionContent(reportSections, ['핵심', '차별', '컨셉', '콘셉트']) || reportSections[1]?.content || '';
const targetSection = pickSectionContent(reportSections, ['타겟', '고객']);
const positioningCategory = facilities.length > 0 ? facilities.join(' · ') : '정보 없음';
const positioningCore =
pickSectionContent(reportSections, ['핵심 가치', '핵심', '차별']) || tags.slice(0, 3).join(' · ') || '정보 없음';
const usps: USP[] = useMemo(() => buildUSPs(facilities, tags), [facilities, tags]);
const topUSP = useMemo(
() => [...usps].sort((a, b) => b.score - a.score)[0],
[usps]
);
const targets = useMemo(() => buildTargets(targetSection, tags), [targetSection, tags]);
return (
<div className="analysis-container">
{/* Header Area */}
<div className="analysis-header-area">
{/* Back Button */}
<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>
{/* Header */}
<div className="analysis-header">
<div className="analysis-icon">
<svg className="w-8 h-8" viewBox="0 0 24 24" fill="currentColor">
<path d="M12 2l2.4 7.2L22 12l-7.6 2.4L12 22l-2.4-7.2L2 12l7.6-2.4z" />
</svg>
</div>
<h1 className="page-title">브랜드 분석</h1>
<p className="page-subtitle">
쉽고 빠르게, 브랜드 소셜 미디어 캠페인을 만드세요.
</p>
</div>
<div className="min-h-screen bg-brand-bg text-brand-text pb-24 selection:bg-brand-accent/30 font-sans">
<div className="p-6">
<button
onClick={onBack}
className="flex items-center gap-2 px-4 py-2 rounded-full border border-brand-muted/30 text-brand-muted hover:text-brand-accent hover:border-brand-accent transition-all text-sm group"
>
<ArrowLeftIcon />
<span>뒤로가기</span>
</button>
</div>
{/* Main Content Grid */}
<div className="analysis-grid">
{/* Left: Brand Identity (Scrollable) */}
<div className="brand-identity-card">
<div className="brand-header">
<span className="section-title">브랜드 정체성</span>
<span className="brand-subtitle">AI 마케팅 분석 요약</span>
</div>
<div className="brand-content">
<div className="brand-info">
<h2 className="brand-name">{processed_info.customer_name}</h2>
<p className="brand-location">{processed_info.detail_region_info}</p>
</div>
<div className="report-content">
{marketing_analysis.report
? formatReportText(marketing_analysis.report)
: '분석 결과가 없습니다.'}
</div>
<div className="text-center mb-10 px-4">
<div className="flex justify-center mb-4">
<div className="relative">
<SparklesIcon className="text-brand-accent w-8 h-8 animate-pulse relative z-10" />
</div>
</div>
<h1 className="text-4xl font-bold mb-3 tracking-tight text-white">브랜드 인텔리전스</h1>
<p className="text-brand-muted text-lg max-w-xl mx-auto">
<span className="text-brand-accent font-semibold">AI 데이터 분석</span>을 통해 도출된 브랜드 전략입니다.
</p>
</div>
{/* Right: Selling Points & Keywords (Fixed) */}
<div className="analysis-cards-column">
{/* Main Selling Points */}
<div className="feature-card selling-points-card">
<span className="section-title">주요 셀링 포인트</span>
<div className="selling-points-grid">
{sellingPoints.map((point, idx) => (
<div key={idx} className="selling-point-item">
<span className="selling-point-title">{point.title}</span>
<div className="selling-point-content">
{point.items.map((item, itemIdx) => (
<p key={itemIdx}>{item}</p>
))}
<div className="max-w-7xl mx-auto px-4 md:px-8 grid grid-cols-1 lg:grid-cols-2 gap-8">
<div className="space-y-6">
<div className="bg-brand-card rounded-3xl p-8 border border-brand-muted/10 shadow-lg relative overflow-hidden group hover:border-brand-accent/20 transition-all duration-500">
<div className="absolute top-0 left-0 w-1.5 h-full bg-gradient-to-b from-brand-accent to-brand-purple"></div>
<div className="mb-4 flex items-center gap-2">
<span className="text-brand-accent font-bold text-sm uppercase tracking-wider flex items-center gap-2">
<LayoutGridIcon /> 브랜드 정체성
</span>
</div>
<h2 className="text-3xl font-bold mb-2 text-white tracking-tight">{processed_info.customer_name}</h2>
<div className="flex items-start gap-2 text-brand-muted text-sm mb-6">
<MapPinIcon />
<div>
<p>{processed_info.detail_region_info || '주소 정보 없음'}</p>
<p className="opacity-70">{processed_info.region}</p>
</div>
</div>
<div className="space-y-5 text-gray-300 leading-relaxed border-t border-white/5 pt-5">
<div>
<h3 className="text-white font-semibold mb-2 text-sm text-brand-muted">입지 특성 분석</h3>
{locationAnalysis ? renderMarkdown(locationAnalysis) : <p className="text-sm opacity-90">정보 없음</p>}
</div>
<div>
<h3 className="text-white font-semibold mb-2 text-sm text-brand-muted">컨셉 확장성</h3>
{conceptAnalysis ? renderMarkdown(conceptAnalysis) : <p className="text-sm opacity-90">정보 없음</p>}
</div>
</div>
</div>
<div className="bg-brand-card rounded-3xl p-8 border border-brand-muted/10">
<h3 className="text-xl font-bold mb-6 flex items-center gap-2 text-white">
<TargetIcon /> 시장 포지셔닝
</h3>
<div className="grid grid-cols-1 gap-4">
<div className="bg-brand-bg/50 p-5 rounded-xl border border-brand-muted/20 hover:border-brand-accent/30 transition-colors group">
<span className="block text-xs text-brand-muted mb-1 group-hover:text-brand-accent transition-colors">
카테고리 정의
</span>
<span className="font-bold text-lg text-white">{positioningCategory}</span>
</div>
<div className="bg-gradient-to-r from-brand-bg/50 to-brand-cardHover p-5 rounded-xl border border-brand-muted/20 border-l-4 border-l-brand-accent">
<span className="block text-xs text-brand-accent mb-1 font-semibold">핵심 가치 (Core Value)</span>
<span className="font-semibold text-white">{positioningCore}</span>
</div>
</div>
</div>
<div className="bg-brand-card rounded-3xl p-8 border border-brand-muted/10">
<h3 className="text-xl font-bold mb-6 flex items-center gap-2 text-white">
<UsersIcon /> 타겟 페르소나
</h3>
<div className="space-y-4">
{targets.map((target, idx) => (
<div
key={idx}
className="flex flex-col sm:flex-row sm:items-center gap-4 p-4 bg-brand-bg/30 rounded-xl border border-white/5 hover:border-brand-accent/20 transition-all group"
>
<div className="min-w-[120px]">
<div className="font-bold text-white group-hover:text-brand-accent transition-colors">
{target.segment}
</div>
{target.age && <div className="text-xs text-brand-muted">{target.age}</div>}
</div>
<div className="flex-1">
{target.needs.length > 0 && (
<div className="flex flex-wrap gap-1.5 mb-2">
{target.needs.map((need, i) => (
<span
key={i}
className="text-[10px] px-2 py-0.5 bg-brand-accent/10 text-brand-accent rounded-sm font-medium"
>
{need}
</span>
))}
</div>
)}
{target.triggers.length > 0 && (
<p className="text-xs text-gray-400 border-t border-white/5 pt-2 mt-2">
<span className="text-brand-muted">Trigger:</span> {target.triggers.join(', ')}
</p>
)}
</div>
</div>
))}
</div>
</div>
</div>
{/* Recommended Target Keywords */}
<div className="feature-card keywords-card">
<span className="section-title">추천 타겟 키워드</span>
<div className="tags-wrapper">
{tags.map((tag, idx) => (
<span key={idx} className="feature-tag">
{tag}
</span>
<div className="space-y-6">
<div className="bg-brand-card rounded-3xl p-8 border border-brand-muted/10 min-h-[500px] flex flex-col relative overflow-hidden">
<div className="flex justify-between items-center mb-2 z-10">
<h3 className="text-xl font-bold text-white">주요 셀링 포인트 (USP)</h3>
<div className="flex items-center gap-1 text-xs text-brand-accent bg-brand-accent/10 px-2 py-1 rounded">
<TrendingUpIcon />
<span>AI Data Analysis</span>
</div>
</div>
<div className="flex-1 flex items-center justify-center relative z-10 -my-4">
<GeometricChart data={usps} />
</div>
{topUSP && (
<div className="mt-2 mb-6 p-4 rounded-xl bg-gradient-to-r from-brand-accent/10 to-transparent border border-brand-accent/20 relative overflow-hidden">
<div className="absolute top-0 right-0 p-2 opacity-10">
<CrownIcon className="w-16 h-16 text-brand-accent" />
</div>
<div className="relative z-10">
<div className="text-xs text-brand-accent font-bold uppercase tracking-wider mb-1 flex items-center gap-1">
<CrownIcon className="w-3 h-3" /> Core Competitiveness
</div>
<div className="flex justify-between items-end">
<div>
<div className="text-lg font-bold text-white">{topUSP.label}</div>
<div className="text-xs text-brand-accent/80 font-mono tracking-wider">{topUSP.subLabel}</div>
</div>
</div>
</div>
</div>
)}
<div className="grid grid-cols-2 gap-3 z-10">
{usps
.filter((usp) => usp.label !== topUSP?.label)
.slice(0, 4)
.map((usp, idx) => (
<div
key={idx}
className="p-3 rounded-xl bg-brand-bg/40 border border-white/5 hover:bg-brand-bg/60 transition-colors"
>
<div className="flex justify-between items-start mb-1">
<div className="text-xs text-brand-muted font-bold uppercase tracking-tight">{usp.subLabel}</div>
</div>
<div className="text-sm font-bold text-white mb-1">{usp.label}</div>
<div className="text-xs text-gray-400 leading-tight truncate">{usp.description}</div>
</div>
))}
</div>
</div>
<div className="bg-brand-card rounded-3xl p-8 border border-brand-muted/10 relative overflow-hidden">
<h3 className="text-xl font-bold mb-6 text-center text-white">추천 타겟 키워드</h3>
<div className="flex flex-wrap justify-center gap-3 relative z-10">
{tags.length === 0 && <span className="text-sm text-brand-muted">정보 없음</span>}
{tags.map((keyword, idx) => (
<KeywordBubble key={idx} text={keyword} />
))}
</div>
</div>
</div>
</div>
{/* Bottom Button */}
<div className="analysis-bottom">
<button onClick={onGenerate} className="btn-primary">
<div className="fixed bottom-8 left-0 right-0 flex justify-center z-50 pointer-events-none">
<button
onClick={onGenerate}
className="pointer-events-auto bg-brand-purple hover:bg-brand-purpleHover text-white font-bold py-3 px-12 rounded-full shadow-2xl shadow-brand-purple/40 transform hover:scale-105 transition-all duration-300 flex items-center gap-2"
>
<SparklesIcon className="w-5 h-5" />
콘텐츠 생성
</button>
</div>