{
/* ์์ */
}
{
step === 0 && <Intro nextStep={nextStep} />;
}
{
/* ํ
์คํธ ์งํ */
}
{
step > 0 && step < 13 && <Question step={step} nextStep={nextStep} answers={answers} setAnswers={setAnswers}></Question>;
}
{
/* ํ
์คํธ ์๋ฃ */
}
{
step === 13 && <Result answers={answers} reStart={reStart} />;
}
// ๊ฒฐ๊ณผ ๋ฐ์ดํฐ ํธ์ถ
useEffect(() => {
fetch('../api/questions.json')
.then((res) => res.json())
.then((data: QuestionData[]) => {
setData(data);
})
.catch((error) => console.error('Error loading questions:', error));
}, []);
if (data.length === 0) {
return <div>๋ก๋ฉ์ค...</div>;
}
const { title, type, A, B } = data[step - 1] || {};
// ์ ์ ๋ฌธํญ ์ ํ์ ๋์ ์ฐ
const handleAnswer = (answer: 'A' | 'B') => {
const newAnswers = { ...answers };
// console.log(answer + newAnswers);
newAnswers[type] = answers[type] + (answer === 'A' ? 1 : 0);
setAnswers(newAnswers);
nextStep();
};
const { EI, SN, TF, JP } = answers;
const mbti = `${EI < 2 ? 'I' : 'E'}${SN < 2 ? 'N' : 'S'}${TF < 2 ? 'F' : 'T'}${JP < 2 ? 'P' : 'J'}`;
const result: ResultItem | undefined = data[mbti];
const { writer, img } = result;
// aํ๊ทธ๋ฅผ ์์ฑํ์ฌ download ์์ฑ์ url์ ๋งคํํ์ฌ ๋ค์ด๋ก๋ ์คํ
const handleSaveResult = () => {
const link = document.createElement('a');
link.href = `/assets/download/result_${img}`;
link.download = `result_${img}`;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
};
// ํด๋ฆฝ๋ณด๋์ ๋ณต์ฌ ๋ฐ Toast ๋ฉ์์ง ์ถ๋ ฅ
const handleShareResult = () => {
navigator.clipboard
.writeText(baseUrl)
.then(() => {
setShowToast(true);
setTimeout(() => {
setShowToast(false);
}, 3000);
})
.catch((err) => console.error('Failed to copy: ', err));
};