diff --git a/src/components/display/EmojiAnimation.tsx b/src/components/display/EmojiAnimation.tsx
new file mode 100644
index 0000000..057e59f
--- /dev/null
+++ b/src/components/display/EmojiAnimation.tsx
@@ -0,0 +1,20 @@
+import React, { useState, useEffect } from "react";
+import { ZoomAnimation } from "@/pages/ResultLoading.style";
+
+
+const EmojiAnimation: React.FC = () => {
+ const emojis = ["πΆ", "πββοΈ", "ποΈ", "π", "π€", "β½", "πΈ"];
+ const [currentEmojiIndex, setCurrentEmojiIndex] = useState(0);
+
+ useEffect(() => {
+ const emojiInterval = setInterval(() => {
+ setCurrentEmojiIndex((prevIndex) => (prevIndex + 1) % emojis.length);
+ }, 1000); // 1μ΄λ§λ€ μ΄λͺ¨μ§λ₯Ό λ³κ²½
+
+ return () => clearInterval(emojiInterval);
+ }, []);
+
+ return {emojis[currentEmojiIndex]};
+};
+
+export default EmojiAnimation;
diff --git a/src/components/display/TypingAnimation.tsx b/src/components/display/TypingAnimation.tsx
new file mode 100644
index 0000000..0cd345b
--- /dev/null
+++ b/src/components/display/TypingAnimation.tsx
@@ -0,0 +1,77 @@
+import React, { useState, useEffect } from "react";
+import Hangul from "hangul-js";
+import { TypingText } from "@/pages/ResultLoading.style";
+
+interface TypingAnimationProps {
+ texts: string[];
+ typingInterval: number;
+ deleteInterval: number;
+ waitInterval: number;
+}
+
+const TypingAnimation: React.FC = ({
+ texts,
+ typingInterval,
+ deleteInterval,
+ waitInterval,
+}) => {
+ const [displayedText, setDisplayedText] = useState("");
+ const [currentTextIndex, setCurrentTextIndex] = useState(0);
+ const [isCursorBlinking, setIsCursorBlinking] = useState(false);
+
+ useEffect(() => {
+ const disassembled = Hangul.disassemble(texts[currentTextIndex]);
+ let index = 0;
+ let isDeleting = false;
+ let typeTimeout: NodeJS.Timeout;
+
+ const handleTyping = () => {
+ if (!isDeleting) {
+ setIsCursorBlinking(false); // νμ΄ν μ€μλ 컀μ κΉλΉ‘μ λΉνμ±ν
+
+ if (index <= disassembled.length) {
+ const nextText = Hangul.assemble(disassembled.slice(0, index));
+ setDisplayedText(nextText);
+ index++;
+ } else {
+ setIsCursorBlinking(true); // λͺ¨λ ν
μ€νΈκ° νμ΄νλλ©΄ 컀μ κΉλΉ‘μ νμ±ν
+ setTimeout(() => {
+ isDeleting = true;
+ index = texts[currentTextIndex].length;
+ setIsCursorBlinking(false); // μμ μ€μλ 컀μ κΉλΉ‘μ λΉνμ±ν
+ handleTyping();
+ }, waitInterval);
+ return;
+ }
+ } else {
+ if (index > 0) {
+ setDisplayedText((prevText) => prevText.slice(0, index - 1));
+ index--;
+ } else {
+ setCurrentTextIndex((prevIndex) => (prevIndex + 1) % texts.length);
+ isDeleting = false;
+ setDisplayedText("");
+ clearTimeout(typeTimeout);
+ setIsCursorBlinking(true); // λ€μ ν
μ€νΈλ‘ μ΄λνκΈ° μ κΉλΉ‘μ νμ±ν
+ return;
+ }
+ }
+
+ typeTimeout = setTimeout(handleTyping, isDeleting ? deleteInterval : typingInterval);
+ };
+
+ typeTimeout = setTimeout(handleTyping, typingInterval);
+
+ return () => clearTimeout(typeTimeout);
+ }, [currentTextIndex]);
+
+ return (
+
+
+ {displayedText}
+
+
+ );
+};
+
+export default TypingAnimation;
diff --git a/src/pages/ResultLoading.style.ts b/src/pages/ResultLoading.style.ts
index 3555f82..ca9056d 100644
--- a/src/pages/ResultLoading.style.ts
+++ b/src/pages/ResultLoading.style.ts
@@ -27,7 +27,7 @@ export const TypingText = styled.div<{ isCursorBlinking: boolean }>`
display: inline-flex;
align-items: center;
position: relative;
- min-height: 1.5em; /* νμ΄ν ν
μ€νΈ μμμ μ΅μ λμ΄ μ€μ */
+ min-height: 1.5em;
&::after {
content: "";
@@ -36,9 +36,9 @@ export const TypingText = styled.div<{ isCursorBlinking: boolean }>`
height: 1em;
background-color: black;
position: absolute;
- right: -8px; /* μ€λ₯Έμͺ½μΌλ‘ μ½κ° μ΄λ */
- bottom: 5px; /* μλμͺ½μΌλ‘ μ½κ° μ΄λ */
- animation: ${({ isCursorBlinking }) => (isCursorBlinking ? 'blink 0.7s steps(1) infinite' : 'none')}; /* 쑰건μ λ°λΌ κΉλΉ‘μ */
+ right: -8px;
+ bottom: 5px;
+ animation: ${({ isCursorBlinking }) => (isCursorBlinking ? 'blink 0.7s steps(1) infinite' : 'none')};
}
@keyframes blink {
diff --git a/src/pages/ResultLoading.tsx b/src/pages/ResultLoading.tsx
index 18b6de4..659f913 100644
--- a/src/pages/ResultLoading.tsx
+++ b/src/pages/ResultLoading.tsx
@@ -1,85 +1,29 @@
-import React, { useState, useEffect } from "react";
-import Hangul from "hangul-js"; //npm install hangul-js νμ
-import { LoadingContainer, ZoomAnimation, TypingText } from "./ResultLoading.style";
+import React from "react";
+import TypingAnimation from "../components/display/TypingAnimation";
+import EmojiAnimation from "../components/display/EmojiAnimation";
+import { LoadingContainer } from "./ResultLoading.style";
const ResultLoading: React.FC = () => {
- const emojis = ["πΆ", "πββοΈ", "ποΈ", "π", "π€", "β½", "πΈ"];
- const [currentEmojiIndex, setCurrentEmojiIndex] = useState(0);
- const [displayedText, setDisplayedText] = useState("");
- const [currentTextIndex, setCurrentTextIndex] = useState(0);
- const [isCursorBlinking, setIsCursorBlinking] = useState(false); // 컀μ κΉλΉ‘μ μν
const texts = [
"λΉμ μ μ·¨ν₯μ λΆμνλ μ€...",
"μ μλ§ κΈ°λ€λ € μ£ΌμΈμ...",
"μ·¨ν₯ λΆμ μ€...",
- "곧 λΉμ μ λμ리 μ΄λͺ
μ 곡κ°ν©λλ€...!",
"λμ리 μ΄λͺ
λΆμ μ€... ",
- "... μ€λ μ§ μλμ?",
];
- const typingInterval = 30; // νμ΄ν μλ
- const deleteInterval = 300 / texts[currentTextIndex].length; // μμ μλ
- const waitInterval = 1500; // νμ΄ν μ΄ν μμ μ κΉμ§ λκΈ° μκ°
-
- useEffect(() => {
- const emojiInterval = setInterval(() => {
- setCurrentEmojiIndex((prevIndex) => (prevIndex + 1) % emojis.length);
- }, 1000); // 1μ΄λ§λ€ μ΄λͺ¨μ§λ₯Ό λ³κ²½
-
- return () => clearInterval(emojiInterval);
- }, []);
-
- useEffect(() => {
- const disassembled = Hangul.disassemble(texts[currentTextIndex]);
- let index = 0;
- let isDeleting = false;
- let typeTimeout: NodeJS.Timeout;
-
- const handleTyping = () => {
- if (!isDeleting) {
- setIsCursorBlinking(false); // νμ΄ν μ€μλ 컀μ κΉλΉ‘μμ λΉνμ±ν
-
- if (index <= disassembled.length) {
- const nextText = Hangul.assemble(disassembled.slice(0, index));
- setDisplayedText(nextText);
- index++;
- } else {
- // λͺ¨λ ν
μ€νΈκ° νμ΄νλλ©΄ 컀μ κΉλΉ‘μ νμ±ν
- setIsCursorBlinking(true);
- setTimeout(() => {
- isDeleting = true;
- index = texts[currentTextIndex].length;
- setIsCursorBlinking(false); // μμ μ€μλ 컀μ κΉλΉ‘μ λΉνμ±ν
- handleTyping();
- }, waitInterval);
- return;
- }
- } else {
- if (index > 0) {
- setDisplayedText((prevText) => prevText.slice(0, index - 1));
- index--;
- } else {
- setCurrentTextIndex((prevIndex) => (prevIndex + 1) % texts.length);
- isDeleting = false;
- setDisplayedText("");
- clearTimeout(typeTimeout);
- setIsCursorBlinking(true); // λ€μ ν
μ€νΈλ‘ μ΄λνκΈ° μ κΉλΉ‘μ νμ±ν
- return;
- }
- }
-
- typeTimeout = setTimeout(handleTyping, isDeleting ? deleteInterval : typingInterval);
- };
-
- typeTimeout = setTimeout(handleTyping, typingInterval);
-
- return () => clearTimeout(typeTimeout);
- }, [currentTextIndex]);
+ const typingInterval = 30;
+ const deleteInterval = 10;
+ const waitInterval = 1500;
return (
- {displayedText}
- {emojis[currentEmojiIndex]}
+
+
);
};