import React, {Component} from 'react'; import ProfilePicture from '../../images/home/profilePicture.jpg'; import "./introduction.css"; const lineOneText = 'Hi, my name is Giovani.'; const lineTwoText = 'I am a software developer. '; class Introduction extends Component { constructor(props) { super(props); let typingInterval = this.startTyping(); this.state = { currentLineOne: '', currentLineTwo: '', currentCharLineOne: 0, currentCharLineTwo: 0, isCursorOneVisible: true, isCursorTwoVisible: false, typingInterval: typingInterval, cursorBlinkingInterval: null }; } getLineOneText = () => { return lineOneText; } getLineTwoText = () => { return lineTwoText; } startTyping = () => { let typingInterval = setInterval(this.type, 55); return typingInterval; } startBlinking = () => { let blinkingInterval = setInterval(this.blink, 125); return blinkingInterval; } type = () => { let { currentLineOne, currentCharLineOne, currentLineTwo, currentCharLineTwo, typingInterval, blinkingInterval, isCursorOneVisible, isCursorTwoVisible } = this.state; if (currentCharLineOne === 0 || currentCharLineOne !== this.getLineOneText().length) { isCursorOneVisible = true; isCursorTwoVisible = false; currentLineOne += this.getLineOneText()[currentCharLineOne]; currentCharLineOne++; } else if (currentCharLineTwo === 0 || currentCharLineTwo !== this.getLineTwoText().length) { isCursorOneVisible = false; isCursorTwoVisible = true; currentLineTwo += this.getLineTwoText()[currentCharLineTwo]; currentCharLineTwo++; } else { clearInterval(typingInterval); blinkingInterval = setInterval(this.blink, 500, 2); } this.setState({ currentLineOne: currentLineOne, currentCharLineOne: currentCharLineOne, currentLineTwo: currentLineTwo, currentCharLineTwo: currentCharLineTwo, blinkingInterval: blinkingInterval, isCursorOneVisible: isCursorOneVisible, isCursorTwoVisible: isCursorTwoVisible }); } blink = (cursorNumber) => { if (cursorNumber === 1) { this.setState({ isCursorOneVisible: !this.state.isCursorOneVisible }); } else { this.setState({ isCursorTwoVisible: !this.state.isCursorTwoVisible }); } } getCursorClasses = (cursorNumber) => { let isCursorVisible = cursorNumber === 1 ? this.state.isCursorOneVisible : this.state.isCursorTwoVisible; return `align-text-top ${isCursorVisible ? 'visible' : 'invisible'}`; } render() { return (
); } // componentDidUpdate() { // } } export default Introduction;