Newer
Older
import {SetStateAction, useEffect, useRef, useState} from 'react';
import Typewriter, {TypewriterClass} from "typewriter-effect";
import {intro} from "../../public/lit/texts";
const [paused, setPaused] = useState(false);
const [, setAnimationObject] = useState(null);
const getAnimationObject = (obj: SetStateAction<null>) => setAnimationObject(obj);
const [currentIndex, setCurrentIndex] = useState(0);
const [isAnimationComplete, setIsAnimationComplete] = useState(false);
const {EN} = intro[currentIndex];
const typewriterRef = useRef<TypewriterClass>();
useEffect(() => {
if (typewriterRef.current) {
typewriterRef.current.deleteAll(0.0000000000000000000001);
typewriterRef.current
.typeString(EN)
.start()
.callFunction(() => {
setIsAnimationComplete(true);
setPaused(true)
});
}
}, [EN]);
if(currentIndex == intro.length -1) {
navigate('/opening');
setCurrentIndex((prevIndex) => (prevIndex + 1) % intro.length);
setIsAnimationComplete(false);
setPaused(false);
}
};
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
return (
<>
<div className="flex items-center justify-center">
<div className="container">
<div className="text mt-12">
<div id="intro-text" className="font-speech">
<Typewriter
options={{
delay: 40,
}}
onInit={(typewriter) => {
typewriterRef.current = typewriter;
typewriter
.typeString(EN)
.start()
.callFunction(() => {
setIsAnimationComplete(true);
setPaused(true);
});
}}
/>
</div>
<div className="mt-12 ml-44 flex justify-center">
<div
id="animation-container"
style={{ width: '600px', height: '300px', position: 'relative' }}
>
<AnimateCC
animationName="intro"
getAnimationObject={getAnimationObject}
paused={paused}
/>
</div>
</div>
</div>
<div className="mt-20 flex justify-center">
<button
onClick={handleClick}
className={`mt-20 border-4 border-black font-primary ${
!isAnimationComplete ? 'bg-gray-main' : 'bg-yellow-500'
}`}
>
{currentIndex == intro.length -1 ? 'To Chapter 1' : 'Next'}
</button>
</div>
</div>
</div>
</>
);