diff --git a/frontend/src/pages/AddIssuePage.tsx b/frontend/src/pages/AddIssuePage.tsx index 87175bec6..20dcffcf0 100644 --- a/frontend/src/pages/AddIssuePage.tsx +++ b/frontend/src/pages/AddIssuePage.tsx @@ -1,72 +1,102 @@ import styled from 'styled-components'; -import { useEffect, useState } from 'react' +import { useEffect, useState, useRef } from 'react' import ResponsiveLayout from '../components/common/ResponsiveLayout'; const AddIssuePage = () => { const [lastPressedKey, setLastPressedKey] = useState(); const [accumulateLetters, setAccumulateLetters] = useState([]); const [textBlock, setTextBlock] = useState({}); + const $OutputTextBox = useRef() useEffect(() => { console.log("textBlock", textBlock); }) + useEffect(() => { + $OutputTextBox.current.innerHTML = ""; + accumulateLetters.forEach((block) => { + $OutputTextBox.current.insertAdjacentHTML("beforeend", block.tag); + }); + + }, [accumulateLetters?.slice(-1)[0]]) + const inspectLastPressedKey = (curKey) => { if (curKey === " " && lastPressedKey === "-") { - console.log("잘눌림"); } } - const createNewTextBlock = () => { - const textObj = { - tag: '', - contents: '' - } - textObj.contents = accumulateLetters.join(''); - if (textObj.contents[1] === "Shift" && textObj.contents[0] === '#') { - textObj.tag = `

${textObj.contents}

`; - } - setTextBlock(textObj); + const countSharpNum = (str) => { + let count = 0; + str.split('').forEach(letter => { + if (letter === "#") count++; + }) + return count; } - const onKeyDownEvent = (e) => { + const createNewTextBlock = (value) => { + + const targetValueArr = value.split('\n').map((targetValue) => { + const textObj = { + tag: '', + contents: '' + } + + textObj.contents = targetValue; + + switch (textObj.contents[0]) { + case "#" : + const num = countSharpNum(textObj.contents); + textObj.tag = `${textObj.contents.slice(num)}`; + break; + case "-" : + textObj.tag = `
  • ${textObj.contents.slice(1)}
  • `; + break; + default : + textObj.tag = `

    ${textObj.contents}

    `; + break; + } + return textObj; + }); + setAccumulateLetters(targetValueArr); + } + + const handleKeyDownEvent = (e) => { console.log("event", e.key, e.key === "Shift"); const pressedKey = e.key; - if (pressedKey !== "Shift" && pressedKey !== "Meta" && pressedKey !== "Enter" && pressedKey !== "Backspace") { - setAccumulateLetters([...accumulateLetters, pressedKey]); + if (pressedKey !== "Shift" && pressedKey !== "Meta" && pressedKey !== "Enter" && pressedKey !== "Backspace" && pressedKey !== "ArrowRight" && pressedKey !== "") { if(lastPressedKey) { inspectLastPressedKey(pressedKey); - //unordered list를 반환해줘야 함. } - setLastPressedKey(pressedKey); } if (pressedKey === "Enter") { - createNewTextBlock(); + createNewTextBlock(e.target.value); } if (pressedKey === "Backspace") { } + setLastPressedKey(pressedKey); } return ( 새로운 이슈 작성 - + onKeyDownEvent(e)} + onKeyDown={handleKeyDownEvent} /> - - {textBlock.contents} + + {/* {textBlock.contents} */} + ) @@ -99,7 +129,7 @@ const CommentLayer = styled.div` display: flex; ` -const CommentInput = styled.input` +const CommentInput = styled.textarea` width: 50%; height: 34.3rem; border-radius: 1.4rem; @@ -118,4 +148,8 @@ const CommentOutput = styled.div` margin-left: 2rem; ` +const AddFile = styled.input` + /* font-size: var(--TitleFontSize); */ +` + export default AddIssuePage;