-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
1357 lines (1221 loc) · 59.4 KB
/
index.html
File metadata and controls
1357 lines (1221 loc) · 59.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>문제정의 아키타입 진단 (Preview)</title>
<!-- React & Libraries (Stable Version for Standalone) -->
<script src="https://unpkg.com/react@17/umd/react.production.min.js"></script>
<script src="https://unpkg.com/react-dom@17/umd/react-dom.production.min.js"></script>
<script src="https://unpkg.com/history@5/umd/history.production.min.js"></script>
<!-- React Router v5 -->
<script src="https://unpkg.com/react-router-dom@5.3.4/umd/react-router-dom.min.js"></script>
<script src="https://unpkg.com/framer-motion@4.1.17/dist/framer-motion.js"></script>
<!-- Babel for JSX -->
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
<!-- External Data -->
<script src="src/data/questions.js"></script>
<script src="src/data/archetypes.js"></script>
<style>
/* CSS Variables */
:root {
--color-bg: #FAFAFA;
--color-surface: #FFFFFF;
--color-text-main: #222222;
--color-text-sub: #4A4A4A;
--color-text-muted: #888888;
--color-accent: #3344DD;
--color-accent-subtle: #EBEFFE;
--color-border: #EEEEEE;
--color-card-bg: #F5F5F7;
--font-main: -apple-system, BlinkMacSystemFont, "Pretendard", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
--space-1: 4px;
--space-2: 8px;
--space-3: 12px;
--space-4: 16px;
--space-5: 20px;
--space-6: 24px;
--space-8: 32px;
--space-10: 40px;
--space-12: 48px;
--max-width: 460px;
}
/* Global Reset & Styles */
* {
box-sizing: border-box;
margin: 0;
padding: 0;
-webkit-tap-highlight-color: transparent;
}
body {
font-family: var(--font-main);
background-color: var(--color-bg);
color: var(--color-text-main);
line-height: 1.6;
}
#root {
display: flex;
justify-content: center;
min-height: 100vh;
width: 100%;
}
.app-container {
width: 100%;
max-width: var(--max-width);
background-color: var(--color-surface);
min-height: 100vh;
position: relative;
display: flex;
flex-direction: column;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.03);
}
/* Typography */
.text-h1 {
font-size: 26px;
font-weight: 700;
line-height: 1.3;
margin-bottom: var(--space-4);
letter-spacing: -0.02em;
}
.text-h2 {
font-size: 20px;
font-weight: 600;
line-height: 1.35;
margin-bottom: var(--space-3);
letter-spacing: -0.01em;
}
.text-h3 {
font-size: 16px;
font-weight: 600;
margin-bottom: var(--space-2);
color: var(--color-text-main);
}
.text-body {
font-size: 16px;
color: var(--color-text-sub);
margin-bottom: var(--space-3);
word-break: keep-all;
}
.text-small {
font-size: 14px;
color: var(--color-text-muted);
}
button {
border: none;
background: none;
font-family: inherit;
cursor: pointer;
}
.screen {
flex: 1;
display: flex;
flex-direction: column;
padding: var(--space-6);
padding-bottom: var(--space-10);
}
/* Markdown-like content styling
UPDATED: Removed explicit colors to allow inheritance for 'highlight' mode */
.content-block h3 {
font-size: 16px;
font-weight: 700;
margin-top: 24px;
margin-bottom: 8px;
color: inherit;
}
.content-block p {
font-size: 15px;
line-height: 1.65;
margin-bottom: 12px;
color: inherit;
opacity: 0.95;
}
.content-block ul {
padding-left: 20px;
margin-bottom: 16px;
}
.content-block li {
margin-bottom: 6px;
font-size: 15px;
}
.content-block strong {
font-weight: 600;
color: inherit;
}
.container {
width: 100%;
padding: var(--space-6);
max-width: var(--max-width);
margin: 0 auto;
}
.content-block h3 {
font-size: 1.1rem;
margin-top: 1.5rem;
margin-bottom: 0.5rem;
color: var(--color-accent);
}
.content-block p {
margin-bottom: 1rem;
line-height: 1.6;
}
</style>
</head>
<body>
<div id="root"></div>
<script type="text/babel">
const { useState, useEffect } = React;
const { HashRouter, Switch, Route, useHistory, useLocation } = ReactRouterDOM;
const { motion, AnimatePresence } = window.Motion;
// --- DATA ---
const questions = window.questions;
const archetypes = window.archetypes;
const archetypeIcons = {
'Anthropologist': '🔍',
'Journalist': '📰',
'Detective': '🕵️',
'Systems Thinker': '🌐',
'Cartographer': '🗺️',
'Philosopher': '💭',
'Scientist': '🔬',
'Economist': '💰',
'Scenario Planner': '🎯',
'Judge': '⚖️'
};
const calculateResults = (answers) => {
const archetypeCounts = {};
const archetypeSums = {};
archetypes.forEach(a => {
archetypeCounts[a.id] = 0;
archetypeSums[a.id] = 0;
});
questions.forEach(q => {
if (archetypeCounts.hasOwnProperty(q.archetype)) {
archetypeCounts[q.archetype]++;
}
});
Object.entries(answers).forEach(([qId, value]) => {
const q = questions.find(q => q.id === Number(qId));
if (q && archetypeSums.hasOwnProperty(q.archetype)) {
archetypeSums[q.archetype] += value;
}
});
const scores = {};
Object.keys(archetypeSums).forEach(id => {
const count = archetypeCounts[id];
if (count > 0) {
scores[id] = Math.round((archetypeSums[id] / (count * 5)) * 100);
} else {
scores[id] = 0;
}
});
const sorted = Object.entries(scores).sort((a, b) => b[1] - a[1]);
const activeArchetypes = sorted.filter(s => s[1] >= 80).map(s => s[0]);
const inactiveArchetypes = sorted.filter(s => s[1] <= 40).map(s => s[0]);
return {
activeArchetypes,
inactiveArchetypes,
allScores: sorted
};
};
// --- COMPONENTS ---
const LandingPage = () => {
const history = useHistory();
const [name, setName] = useState(localStorage.getItem('archetype_user_name') || '');
const handleStart = () => {
if (!name.trim()) {
alert('이름을 입력해주세요.');
return;
}
localStorage.setItem('archetype_user_name', name.trim());
history.push('/intro');
};
return (
<div className="screen" style={{ justifyContent: 'center', background: 'linear-gradient(135deg, #f5f7fa 0%, #ffffff 100%)' }}>
<motion.div
initial={{ opacity: 0, y: 20 }}
animate={{ opacity: 1, y: 0 }}
transition={{ duration: 0.8, ease: "easeOut" }}
style={{ textAlign: 'center', width: '100%', maxWidth: '400px', margin: '0 auto' }}
>
<motion.div
initial={{ scale: 0.9 }}
animate={{ scale: 1 }}
transition={{ duration: 1, ease: "easeOut" }}
style={{
width: '80px',
height: '80px',
margin: '0 auto 32px',
background: 'linear-gradient(135deg, var(--color-accent) 0%, #5a8fb8 100%)',
borderRadius: '20px',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
boxShadow: '0 10px 30px rgba(69, 123, 157, 0.3)'
}}
>
<span style={{ fontSize: '40px' }}>🧭</span>
</motion.div>
<h1 className="text-h1" style={{ marginBottom: '24px', fontSize: '28px', lineHeight: '1.4' }}>
문제를 푸는 능력보다,<br />
<span style={{ color: 'var(--color-accent)', fontWeight: 700 }}>문제를 정의하는 방식</span>이<br />
결과를 바꿉니다.
</h1>
<div style={{ marginBottom: '32px', background: 'rgba(255,255,255,0.8)', padding: '24px', borderRadius: '12px', backdropFilter: 'blur(10px)' }}>
<div style={{ marginBottom: '20px' }}>
<label style={{ display: 'block', fontSize: '14px', color: '#666', marginBottom: '8px', textAlign: 'left' }}>성함을 알려주세요</label>
<input
type="text"
value={name}
onChange={(e) => setName(e.target.value)}
placeholder="예: 홍길동"
style={{
width: '100%',
padding: '16px',
borderRadius: '8px',
border: '1px solid #ddd',
fontSize: '16px',
outline: 'none',
textAlign: 'center'
}}
/>
</div>
<p className="text-body" style={{ marginBottom: '16px', fontSize: '15px' }}>
이 테스트는 당신이 문제에 직면했을 때<br />
<strong style={{ color: 'var(--color-accent)' }}>가장 먼저 꺼내 드는 사고 도구</strong>를 진단합니다.
</p>
<div style={{ display: 'flex', gap: '8px', justifyContent: 'center', flexWrap: 'wrap' }}>
<span style={{ padding: '4px 12px', background: '#f0f4f8', borderRadius: '20px', fontSize: '12px', color: '#555' }}>⏱️ 5분 소요</span>
<span style={{ padding: '4px 12px', background: '#f0f4f8', borderRadius: '20px', fontSize: '12px', color: '#555' }}>📊 {questions.length}문항</span>
</div>
</div>
<button
onClick={handleStart}
disabled={!name.trim()}
style={{
width: '100%',
padding: '20px',
background: name.trim() ? 'linear-gradient(135deg, var(--color-accent) 0%, #5a8fb8 100%)' : '#ccc',
color: '#fff',
borderRadius: '12px',
fontSize: '17px',
fontWeight: 600,
boxShadow: name.trim() ? '0 4px 15px rgba(69, 123, 157, 0.3)' : 'none',
border: 'none',
cursor: name.trim() ? 'pointer' : 'default',
transition: 'all 0.2s'
}}
>
🚀 시작하기
</button>
</motion.div>
</div>
);
};
const IntroPage = () => {
const history = useHistory();
return (
<div className="screen" style={{ background: 'linear-gradient(135deg, #f5f7fa 0%, #ffffff 100%)' }}>
<motion.div initial={{ opacity: 0 }} animate={{ opacity: 1 }} transition={{ duration: 0.6 }}>
<div style={{ height: '20px' }}></div>
<h2 className="text-h2" style={{ textAlign: 'center', marginBottom: '32px', fontSize: '24px' }}>시작하기 전에 📋</h2>
<div style={{ background: 'linear-gradient(135deg, #eef2f7 0%, #ffffff 100%)', padding: '28px', borderRadius: '16px', marginBottom: '24px', border: '1px solid #e0e7ef', boxShadow: '0 4px 12px rgba(0,0,0,0.05)' }}>
<div style={{ display: 'flex', alignItems: 'center', marginBottom: '20px' }}>
<div style={{ width: '40px', height: '40px', borderRadius: '50%', background: 'var(--color-accent)', display: 'flex', alignItems: 'center', justifyContent: 'center', marginRight: '12px' }}>
<span style={{ fontSize: '20px' }}>✍️</span>
</div>
<p style={{ fontWeight: 700, fontSize: '17px', margin: 0, color: '#222' }}>참여 가이드</p>
</div>
<ul style={{ paddingLeft: '0', listStyle: 'none', lineHeight: '2' }}>
<li style={{ display: 'flex', alignItems: 'flex-start', marginBottom: '12px' }}>
<span style={{ fontSize: '20px', marginRight: '12px' }}>⚡</span>
<span className="text-body">생각을 멈추지 말고 <strong style={{ color: 'var(--color-accent)' }}>직관적</strong>으로 답하세요</span>
</li>
<li style={{ display: 'flex', alignItems: 'flex-start', marginBottom: '12px' }}>
<span style={{ fontSize: '20px', marginRight: '12px' }}>💼</span>
<span className="text-body">구체적인 <strong style={{ color: 'var(--color-accent)' }}>최근 프로젝트</strong>를 떠올리세요</span>
</li>
<li style={{ display: 'flex', alignItems: 'flex-start' }}>
<span style={{ fontSize: '20px', marginRight: '12px' }}>🎯</span>
<span className="text-body">'이상적인 모습'이 아닌 <strong style={{ color: 'var(--color-accent)' }}>'실제 모습'</strong>에 체크하세요</span>
</li>
</ul>
</div>
<div style={{ background: '#fff9e6', padding: '16px', borderRadius: '12px', marginBottom: '32px', border: '1px solid #ffe4a3' }}>
<p style={{ fontSize: '14px', margin: 0, color: '#856404', lineHeight: '1.6' }}>
💡 <strong>Tip:</strong> 정답은 없습니다. 평소 당신의 모습을 솔직하게 표현해주세요.
</p>
</div>
<button
onClick={() => history.push('/test')}
style={{
width: '100%',
padding: '20px',
background: 'linear-gradient(135deg, var(--color-accent) 0%, #5a8fb8 100%)',
color: '#fff',
borderRadius: '12px',
fontWeight: 600,
fontSize: '17px',
border: 'none',
cursor: 'pointer',
boxShadow: '0 4px 15px rgba(69, 123, 157, 0.3)',
transition: 'transform 0.2s'
}}
onMouseEnter={(e) => e.currentTarget.style.transform = 'translateY(-2px)'}
onMouseLeave={(e) => e.currentTarget.style.transform = 'none'}
>
🚀 테스트 진행하기
</button>
</motion.div>
</div>
);
};
const TestPage = () => {
const history = useHistory();
const [index, setIndex] = useState(() => {
try {
const saved = localStorage.getItem('archetype_progress');
if (saved) {
const parsed = JSON.parse(saved);
if (parsed && typeof parsed === 'object' && typeof parsed.index === 'number') {
return parsed.index >= questions.length ? 0 : parsed.index;
}
}
} catch (e) {
console.error("Failed to parse progress", e);
}
return 0;
});
const [answers, setAnswers] = useState(() => {
try {
const saved = localStorage.getItem('archetype_progress');
if (saved) {
const parsed = JSON.parse(saved);
if (parsed && typeof parsed === 'object' && parsed.answers) {
return parsed.answers;
}
}
} catch (e) {
console.error("Failed to parse answers", e);
}
return {};
});
const [isFinishing, setIsFinishing] = useState(false);
// Save progress whenever it changes
useEffect(() => {
if (!isFinishing) {
localStorage.setItem('archetype_progress', JSON.stringify({ index, answers }));
}
}, [index, answers, isFinishing]);
const currentQuestion = questions[index] || questions[0];
const progress = ((index) / questions.length) * 100;
const handleAnswer = (val) => {
const newAnswers = { ...answers, [currentQuestion.id]: val };
setAnswers(newAnswers);
// Wait for animation
setTimeout(() => {
if (index < questions.length - 1) {
setIndex(prev => {
const next = prev + 1;
return next < questions.length ? next : prev;
});
} else {
finishTest(newAnswers);
}
}, 300);
};
const finishTest = async (finalAnswers) => {
setIsFinishing(true);
const name = localStorage.getItem('archetype_user_name');
const results = calculateResults(finalAnswers);
try {
await fetch('/api/save-result', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
name,
answers: finalAnswers,
scores: results.allScores,
timestamp: new Date().toISOString()
})
});
} catch (e) {
console.error("Failed to save results", e);
}
setTimeout(() => {
localStorage.setItem('archetype_answers', JSON.stringify(finalAnswers));
localStorage.removeItem('archetype_progress');
history.push('/result');
}, 1500);
};
const getRound = () => {
if (index < 14) return { title: "Round 1: 발견과 탐색", desc: "현상의 관찰과 문제의 범위를 설정하는 초기 단계" };
if (index < 27) return { title: "Round 2: 심층 해석과 통찰", desc: "보이지 않는 구조와 맥락을 파악하고 의심하는 단계" };
return { title: "Round 3: 현실 검증과 결단", desc: "실행 가능성을 따지고 최종적인 가치를 판단하는 마무리 단계" };
};
const round = getRound();
if (isFinishing) return (
<div className="screen" style={{ justifyContent: 'center', alignItems: 'center' }}>
<p className="text-body" style={{ opacity: 0.6 }}>결과를 분석하고 있습니다...</p>
</div>
);
return (
<div className="screen" style={{ display: 'flex', flexDirection: 'column' }}>
<div style={{ marginBottom: '24px', textAlign: 'center' }}>
<span style={{ fontSize: '12px', color: 'var(--color-accent)', fontWeight: 700, letterSpacing: '1px', textTransform: 'uppercase' }}>{round.title}</span>
<div style={{ fontSize: '14px', color: '#666', marginTop: '4px' }}>{round.desc}</div>
</div>
<div style={{ width: '100%', height: '6px', background: '#f0f0f0', marginBottom: '32px', borderRadius: '3px', overflow: 'hidden' }}>
<motion.div
style={{ height: '100%', background: 'linear-gradient(90deg, var(--color-accent) 0%, #5a8fb8 100%)' }}
initial={{ width: 0 }}
animate={{ width: `${progress}%` }}
transition={{ duration: 0.3 }}
/>
</div>
<div style={{ position: 'relative', flex: 1, width: '100%' }}>
<AnimatePresence>
<motion.div
key={index}
initial={{ opacity: 0, x: 20 }}
animate={{ opacity: 1, x: 0 }}
exit={{ opacity: 0, x: -20 }}
transition={{ duration: 0.3 }}
style={{
position: 'absolute',
top: 0,
left: 0,
width: '100%',
height: '100%',
display: 'flex',
flexDirection: 'column',
backgroundColor: 'var(--color-surface)'
}}
>
<div style={{ flex: 1, display: 'flex', flexDirection: 'column', justifyContent: 'center', padding: '0 0 40px 0' }}>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start', marginBottom: '24px' }}>
<div>
<span className="text-small" style={{ color: 'var(--color-accent)', marginBottom: '8px', display: 'block', fontWeight: 600 }}>QUESTION {index + 1} / {questions.length}</span>
<div style={{ width: '60px', height: '3px', background: 'linear-gradient(90deg, var(--color-accent) 0%, #5a8fb8 100%)', borderRadius: '2px' }}></div>
</div>
{index > 0 && (
<button
onClick={() => setIndex(prev => prev - 1)}
style={{
background: '#f0f0f0',
border: 'none',
color: '#666',
fontSize: '12px',
fontWeight: 600,
cursor: 'pointer',
padding: '6px 12px',
borderRadius: '20px',
display: 'flex',
alignItems: 'center',
gap: '4px',
transition: 'background 0.2s'
}}
onMouseEnter={(e) => e.currentTarget.style.background = '#e0e0e0'}
onMouseLeave={(e) => e.currentTarget.style.background = '#f0f0f0'}
>
← 이전
</button>
)}
</div>
<h2 className="text-h1" style={{ fontSize: '20px', lineHeight: '1.6', marginBottom: '0' }}>{currentQuestion.text}</h2>
</div>
<div style={{ marginBottom: '20px', background: '#f8f9fa', padding: '24px', borderRadius: '12px' }}>
<div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: '16px' }}>
{[1, 2, 3, 4, 5].map((val) => (
<button
key={val}
onClick={() => handleAnswer(val)}
style={{
width: '52px',
height: '52px',
borderRadius: '50%',
background: '#fff',
border: '2px solid #e0e0e0',
boxShadow: '0 2px 8px rgba(0,0,0,0.08)',
cursor: 'pointer',
transition: 'all 0.2s',
display: 'flex',
alignItems: 'center',
justifyContent: 'center'
}}
onMouseEnter={(e) => { e.currentTarget.style.transform = 'scale(1.1)'; e.currentTarget.style.borderColor = 'var(--color-accent)'; }}
onMouseLeave={(e) => { e.currentTarget.style.transform = 'scale(1)'; e.currentTarget.style.borderColor = '#e0e0e0'; }}
>
<div style={{
width: val === 1 || val === 5 ? '16px' : val === 2 || val === 4 ? '12px' : '8px',
height: val === 1 || val === 5 ? '16px' : val === 2 || val === 4 ? '12px' : '8px',
background: val === 5 ? '#888' : val === 1 ? '#ccc' : '#ddd',
borderRadius: '50%'
}}></div>
</button>
))}
</div>
<div style={{ display: 'flex', justifyContent: 'space-between', paddingTop: '8px' }}>
<span className="text-small" style={{ color: '#666', fontSize: '13px' }}>전혀 아니다</span>
<span className="text-small" style={{ color: '#666', fontSize: '13px' }}>매우 그렇다</span>
</div>
</div>
</motion.div>
</AnimatePresence>
</div>
</div>
);
};
const RadarChart = ({ data, size = 300 }) => {
// Safety Check
if (!data || data.length === 0) return null;
const radius = size / 2;
const center = size / 2;
const angleStep = (Math.PI * 2) / data.length;
const safeMaxScore = 100; // Fixed scale for percentage
const scaleFactor = (radius - 60) / safeMaxScore;
const points = data.map(([id, score], i) => {
const angle = i * angleStep - Math.PI / 2;
const r = score * scaleFactor;
return [
center + r * Math.cos(angle),
center + r * Math.sin(angle)
];
}).join(' ');
const outerPoints = data.map((_, i) => {
const angle = i * angleStep - Math.PI / 2;
const r = radius - 60;
return [
center + r * Math.cos(angle),
center + r * Math.sin(angle)
];
});
return (
<div style={{ display: 'flex', justifyContent: 'center', margin: '40px 0' }}>
<svg width={size} height={size} style={{ overflow: 'visible' }}>
{/* Background Grid (Pentagons/Decagons) */}
{[0.2, 0.4, 0.6, 0.8, 1].map(scale => (
<polygon
key={scale}
points={outerPoints.map(([x, y]) => {
const dx = x - center; const dy = y - center;
return `${center + dx * scale},${center + dy * scale} `;
}).join(' ')}
fill="none"
stroke="#eee"
strokeWidth="1"
/>
))}
{/* Axes */}
{outerPoints.map(([x, y], i) => (
<line key={i} x1={center} y1={center} x2={x} y2={y} stroke="#eee" strokeWidth="1" />
))}
{/* Data Area */}
<polygon points={points} fill="rgba(69, 123, 157, 0.2)" stroke="var(--color-accent)" strokeWidth="2" />
{/* Scale Labels (20%, 40%, 60%, 80%, 100%) */}
{[0.2, 0.4, 0.6, 0.8, 1].map(scale => (
<text
key={scale}
x={center}
y={center - (radius - 60) * scale}
textAnchor="middle"
fontSize="10"
fill="#ccc"
dominantBaseline="middle"
>
{Math.round(scale * 100)}%
</text>
))}
{/* Data Points */}
{points.split(' ').map((p, i) => {
const [x, y] = p.split(',');
return <circle key={i} cx={x} cy={y} r="3" fill="var(--color-accent)" />
})}
{/* Labels */}
{data.map(([id, score], i) => {
const angle = i * angleStep - Math.PI / 2;
const r = radius - 30; // Push labels out
const x = center + r * Math.cos(angle);
const y = center + r * Math.sin(angle);
const arch = archetypes.find(a => a.id === id);
return (
<g key={id}>
<text
x={x}
y={y - 8}
textAnchor="middle"
dominantBaseline="middle"
fill="#666"
fontSize="11"
fontWeight="600"
>
{arch.name.split(' (')[0]}
</text>
<text
x={x}
y={y + 6}
textAnchor="middle"
dominantBaseline="middle"
fill="var(--color-accent)"
fontSize="10"
fontWeight="700"
>
{score}%
</text>
</g>
);
})}
</svg>
</div>
);
};
const ResultCard = ({ archetype, label, subLabel, delay, highlight, isUnderUsed, score }) => {
const [expanded, setExpanded] = useState(false);
if (!archetype) return null;
return (
<motion.div
initial={{ opacity: 0, y: 20 }}
animate={{ opacity: 1, y: 0 }}
transition={{ delay, duration: 0.6 }}
style={{ background: highlight ? 'var(--color-accent)' : 'var(--color-card-bg)', color: highlight ? '#fff' : 'inherit', padding: '24px', borderRadius: '4px', marginBottom: '16px', cursor: 'pointer', borderLeft: isUnderUsed ? '4px solid #999' : 'none' }}
onClick={() => setExpanded(!expanded)}
>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start' }}>
<div>
<div style={{ display: 'flex', alignItems: 'center', gap: '8px' }}>
<span className="text-small" style={{ textTransform: 'uppercase', color: highlight ? 'rgba(255,255,255,0.7)' : '#888' }}>{label}</span>
<span style={{ fontSize: '12px', fontWeight: 700, background: highlight ? 'rgba(255,255,255,0.2)' : 'rgba(0,0,0,0.05)', padding: '2px 8px', borderRadius: '10px' }}>{score}%</span>
</div>
<h3 className="text-h2" style={{ marginTop: '8px', fontSize: '24px' }}>{archetype.name.split(' (')[0]}</h3>
<p style={{ opacity: 0.9, fontSize: '15px' }}>{archetype.oneLiner}</p>
</div>
<div style={{ fontSize: '24px' }}>{archetypeIcons[archetype.id]}</div>
</div>
<AnimatePresence>
{expanded && (
<motion.div initial={{ height: 0, opacity: 0 }} animate={{ height: 'auto', opacity: 1 }} exit={{ height: 0, opacity: 0 }} style={{ overflow: 'hidden' }}>
<div style={{ paddingTop: '24px', marginTop: '24px', borderTop: highlight ? '1px solid rgba(255,255,255,0.2)' : '1px solid #eee' }}>
<div style={{ marginBottom: '24px' }}>
<p style={{ fontSize: '15px', lineHeight: '1.6' }}>{archetype.desc}</p>
</div>
{/* Full Content Block injected via HTML */}
<div className="content-block" dangerouslySetInnerHTML={{ __html: archetype.fullContent }} style={{ color: highlight ? 'rgba(255,255,255,0.95)' : 'inherit' }} />
<div style={{ background: highlight ? 'rgba(0,0,0,0.2)' : 'rgba(0,0,0,0.05)', padding: '16px', borderRadius: '4px', marginTop: '24px' }}>
<strong style={{ display: 'block', marginBottom: '8px', color: highlight ? '#fff' : 'var(--color-accent)' }}>⚠️ Blind Spot</strong>
<p style={{ fontSize: '14px', margin: 0, color: highlight ? 'rgba(255,255,255,0.9)' : '#555' }}>{archetype.blindSpot}</p>
</div>
</div>
</motion.div>
)}
</AnimatePresence>
</motion.div>
);
}
const ResultPage = () => {
const history = useHistory();
const [results, setResults] = useState(null);
const [stats, setStats] = useState(null);
const [statsError, setStatsError] = useState(null);
const [statsStatus, setStatsStatus] = useState('idle'); // idle, loading, done
const userName = localStorage.getItem('archetype_user_name') || '방문자';
useEffect(() => {
const saved = localStorage.getItem('archetype_answers');
if (saved) {
setResults(calculateResults(JSON.parse(saved)));
}
}, []);
const fetchStats = async () => {
setStatsStatus('loading');
try {
const res = await fetch('/api/get-stats');
if (!res.ok) throw new Error(`${res.status} ${res.statusText}`);
const data = await res.json();
if (data.error) throw new Error(data.error);
setStats(data);
setStatsStatus('done');
} catch (err) {
console.error("Failed to fetch stats", err);
setStatsError(err.message);
setStatsStatus('done');
}
};
if (!results) return (
<div className="screen" style={{ justifyContent: 'center', alignItems: 'center' }}>
<p className="text-body" style={{ opacity: 0.6 }}>결과를 찾을 수 없습니다.</p>
<button className="btn-secondary" onClick={() => window.location.hash = '#/'} style={{ marginTop: '20px' }}>홈으로 돌아가기</button>
</div>
);
const activeList = results.activeArchetypes.map(id => ({
...archetypes.find(a => a.id === id),
score: results.allScores.find(s => s[0] === id)[1]
}));
const inactiveList = results.inactiveArchetypes.map(id => ({
...archetypes.find(a => a.id === id),
score: results.allScores.find(s => s[0] === id)[1]
}));
const primary = archetypes.find(a => a.id === (results.allScores[0] ? results.allScores[0][0] : '')) || archetypes[0];
const secondary = archetypes.find(a => a.id === (results.allScores[1] ? results.allScores[1][0] : '')) || archetypes[1];
const underUsed = archetypes.find(a => a.id === (results.allScores[results.allScores.length - 1] ? results.allScores[results.allScores.length - 1][0] : '')) || archetypes[archetypes.length - 1];
return (
<div className="screen">
<div style={{ textAlign: 'center', marginBottom: '40px' }}>
<h2 className="text-h1" style={{ marginBottom: '8px' }}>{userName}님의 진단 결과</h2>
<p className="text-body">이 결과는 고정된 성향이 아니라<br />지금 이 시점에서 자주 활용된 사고 방식입니다.</p>
</div>
<section style={{ marginBottom: '48px' }}>
<h3 className="text-h2" style={{ marginBottom: '16px', display: 'flex', alignItems: 'center', gap: '8px' }}>
🔥 활성 아키타입 <span style={{ fontSize: '14px', fontWeight: 500, color: '#666' }}>({activeList.length})</span>
</h3>
{activeList.length > 0 ? (
activeList.map((a, i) => (
<ResultCard key={a.id} archetype={a} label="ACTIVE" score={a.score} delay={i * 0.1} highlight />
))
) : (
<p style={{ color: '#999', fontSize: '14px', padding: '20px', textAlign: 'center', border: '1px dashed #ddd', borderRadius: '8px' }}>강력하게 활성화된 유형이 없습니다.</p>
)}
</section>
<section style={{ marginBottom: '48px' }}>
<h3 className="text-h2" style={{ marginBottom: '16px', display: 'flex', alignItems: 'center', gap: '8px' }}>
❄️ 비활성 아키타입 <span style={{ fontSize: '14px', fontWeight: 500, color: '#666' }}>({inactiveList.length})</span>
</h3>
{inactiveList.length > 0 ? (
inactiveList.map((a, i) => (
<ResultCard key={a.id} archetype={a} label="INACTIVE" score={a.score} delay={0.3 + i * 0.1} isUnderUsed />
))
) : (
<p style={{ color: '#999', fontSize: '14px', padding: '20px', textAlign: 'center', border: '1px dashed #ddd', borderRadius: '8px' }}>모든 유형이 어느 정도 활용되고 있습니다.</p>
)}
</section>
<div style={{ marginTop: '50px' }}>
<AnalysisSection
primary={primary}
secondary={secondary}
underUsed={underUsed}
allScores={results.allScores}
rawAnswers={JSON.parse(localStorage.getItem('archetype_answers'))}
/>
</div>
{statsStatus === 'idle' ? (
<div style={{ marginTop: '60px', background: '#F8F9FA', padding: '24px', borderRadius: '12px', textAlign: 'center', border: '1px dashed #ccc' }}>
<span style={{ fontSize: '20px', display: 'block', marginBottom: '8px' }}>📊</span>
<p style={{ fontSize: '14px', color: '#666', marginBottom: '16px' }}>궁금하신가요? 다른 참여자들의<br />평균 데이터와 비교해 보세요.</p>
<button
onClick={fetchStats}
className="btn-secondary"
style={{ padding: '8px 20px', fontSize: '13px' }}
>
전체 통계 데이터 확인하기
</button>
</div>
) : statsStatus === 'loading' ? (
<div style={{ marginTop: '60px', textAlign: 'center', opacity: 0.5 }}>
<div className="small-spinner" style={{ margin: '0 auto 12px' }}></div>
<p className="text-small">데이터베이스에서 실시간 통계를 가져오는 중...</p>
<style>{`
.small-spinner { width: 16px; height: 16px; border: 2px solid #ddd; border-top-color: #666; border-radius: 50%; animation: spin 1s linear infinite; }
`}</style>
</div>
) : stats ? (
<div style={{ marginTop: '60px' }}>
<StatisticsSection stats={stats} userPrimaryId={primary.id} />
</div>
) : statsError ? (
<div style={{ marginTop: '60px', padding: '20px', background: '#fff3f3', border: '1px solid #ffc1c1', borderRadius: '12px', color: '#d63031', fontSize: '13px' }}>
<strong>📊 통계 데이터를 불러올 수 없습니다:</strong> {statsError}<br />
(Vercel의 SUPABASE 환경 변수 및 DB 테이블 설정을 확인해주세요.)
</div>
) : null}
<div style={{ marginTop: '60px' }}>
<h3 className="text-h2">전체 사고 분포</h3>
<RadarChart data={results.allScores} />
<div style={{ marginTop: '40px', textAlign: 'center', display: 'flex', flexDirection: 'column', gap: '12px' }}>
<button
onClick={() => history.push('/explore')}
className="btn-secondary"
style={{ width: '100%', padding: '16px' }}
>
다른 아키타입 전체 보기
</button>
<button
onClick={() => {
if (confirm('모든 진단 데이터가 초기화됩니다. 다시 시작할까요?')) {
localStorage.clear();
window.location.hash = '#/';
window.location.reload();
}
}}
style={{ background: 'none', border: 'none', color: '#999', fontSize: '13px', cursor: 'pointer', textDecoration: 'underline' }}
>
처음부터 다시 진단하기
</button>
</div>
</div>
</div>
);
}
// Inject marked.js for Markdown parsing
const script = document.createElement('script');
script.src = "https://cdn.jsdelivr.net/npm/marked/marked.min.js";
document.head.appendChild(script);
const AnalysisSection = ({ primary, secondary, underUsed, allScores, rawAnswers }) => {
const [status, setStatus] = useState('idle'); // idle, analyzing, done
const [analysis, setAnalysis] = useState(null);
const generateAnalysis = async () => {
setStatus('analyzing');
try {
const response = await fetch('/api/analyze', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
primaryId: primary.id,
secondaryId: secondary.id,
underUsedIds: [underUsed.id],
scores: allScores,
rawAnswers: rawAnswers
})
});
if (!response.ok) {
let errorMsg = `HTTP Error ${response.status}`;
try {
const errData = await response.json();
if (errData.error) errorMsg = errData.error;
} catch (e) {
errorMsg = `${response.status} ${response.statusText}`;
}
throw new Error(errorMsg);
}
const data = await response.json();
if (data.error) throw new Error(data.error);
// Clean the response: remove markdown code fences if present (e.g. ```html ... ```)
let cleanText = data.analysis || "";
cleanText = cleanText.replace(/```html/gi, "").replace(/```/g, "").trim();
// Use marked.js if available, else fallback to raw text
const htmlContent = window.marked ? window.marked.parse(cleanText) : cleanText;
setAnalysis(htmlContent);
setStatus('done');
} catch (error) {
console.error('AI Analysis Error:', error);
// Fallback to rule-based analysis if AI fails
const fallback = generateInterpretation(primary, secondary, underUsed);
setAnalysis(`
<div style="background:#fff3f3; padding:12px; border-radius:4px; border:1px solid #ffc1c1; color:#d63031; font-size:12px; margin-bottom:16px;">
<strong>⚠️ AI 분석 서버 연결 실패:</strong> ${error.message}<br/>
(Vercel의 GEMINI_API_KEY 설정을 확인해주세요. 현재는 규칙 기반 엔진으로 대체되었습니다.)
</div>
${fallback}
`);