|
| 1 | +import { useState } from "react"; |
| 2 | +import { |
| 3 | + Body, |
| 4 | + CharacterImg, |
| 5 | + CharacterName, |
| 6 | + CharacterRow, |
| 7 | + CommentCard, |
| 8 | + CommentText, |
| 9 | + StarIcon, |
| 10 | + StarIconFill, |
| 11 | +} from "../DiaryDetail"; |
| 12 | +import styled from "styled-components"; |
| 13 | +import { |
| 14 | + IoChevronBack, |
| 15 | + IoChevronForward, |
| 16 | + IoHomeOutline, |
| 17 | +} from "react-icons/io5"; |
| 18 | +import { useNavigate } from "react-router-dom"; |
| 19 | + |
| 20 | +const dummyComments = [ |
| 21 | + "오랜만에 영화관에서 좋은 시간 보냈다니 내가 다 기쁘다! 너의 여유로운 하루가 참 따뜻하게 느껴져 :)", |
| 22 | + "오늘 하루도 수고 많았어! 너의 일상이 더 행복해지길 바랄게.", |
| 23 | + "새로운 도전을 했다는 말에 나도 힘이 나! 계속 응원할게 :)", |
| 24 | +]; |
| 25 | + |
1 | 26 | const Comments = () => { |
| 27 | + const [starred, setStarred] = useState<boolean[]>( |
| 28 | + new Array(dummyComments.length).fill(false), |
| 29 | + ); |
| 30 | + const [currentIndex, setCurrentIndex] = useState(0); |
| 31 | + const navigate = useNavigate(); |
| 32 | + |
| 33 | + const goPrev = () => { |
| 34 | + setCurrentIndex( |
| 35 | + (prev) => (prev - 1 + characterList.length) % characterList.length, |
| 36 | + ); |
| 37 | + }; |
| 38 | + |
| 39 | + const goNext = () => { |
| 40 | + setCurrentIndex((prev) => (prev + 1) % characterList.length); |
| 41 | + }; |
| 42 | + |
2 | 43 | return ( |
3 | | - <> |
4 | | - <>Comments</> |
5 | | - <p>일단 없는 걸로</p> |
6 | | - </> |
| 44 | + <Body> |
| 45 | + <HeaderWrapper> |
| 46 | + <IoHomeOutline |
| 47 | + size={24} |
| 48 | + color="#2d3552" |
| 49 | + onClick={() => navigate("/")} |
| 50 | + /> |
| 51 | + |
| 52 | + <CenterContainer> |
| 53 | + <ClickableIcon onClick={goPrev}> |
| 54 | + <IoChevronBack /> |
| 55 | + </ClickableIcon> |
| 56 | + <Name>{characterList[currentIndex]}</Name> |
| 57 | + <ClickableIcon onClick={goNext}> |
| 58 | + <IoChevronForward /> |
| 59 | + </ClickableIcon> |
| 60 | + </CenterContainer> |
| 61 | + |
| 62 | + <Placeholder /> |
| 63 | + </HeaderWrapper> |
| 64 | + <div>즐겨찾기 한 코멘트 목록</div> |
| 65 | + {dummyComments.map((comment, index) => ( |
| 66 | + <CommentCard key={index}> |
| 67 | + <CharacterRow> |
| 68 | + <CharacterImg src={`/images/characters/웅이.png`} alt="웅이" /> |
| 69 | + <CharacterName>웅이</CharacterName> |
| 70 | + {starred[index] ? ( |
| 71 | + <StarIconFill |
| 72 | + onClick={() => { |
| 73 | + const newStars = [...starred]; |
| 74 | + newStars[index] = false; |
| 75 | + setStarred(newStars); |
| 76 | + }} |
| 77 | + /> |
| 78 | + ) : ( |
| 79 | + <StarIcon |
| 80 | + onClick={() => { |
| 81 | + const newStars = [...starred]; |
| 82 | + newStars[index] = true; |
| 83 | + setStarred(newStars); |
| 84 | + }} |
| 85 | + /> |
| 86 | + )} |
| 87 | + </CharacterRow> |
| 88 | + <CommentText>{comment}</CommentText> |
| 89 | + </CommentCard> |
| 90 | + ))} |
| 91 | + </Body> |
7 | 92 | ); |
8 | 93 | }; |
| 94 | + |
9 | 95 | export default Comments; |
| 96 | + |
| 97 | +const characterList = ["웅이", "앙글이", "티바노"]; |
| 98 | + |
| 99 | +const HeaderWrapper = styled.div` |
| 100 | + display: flex; |
| 101 | + align-items: center; |
| 102 | + justify-content: space-between; |
| 103 | + margin-bottom: 20px; |
| 104 | +`; |
| 105 | + |
| 106 | +const CenterContainer = styled.div` |
| 107 | + position: absolute; |
| 108 | + left: 50%; |
| 109 | + transform: translateX(-50%); |
| 110 | + width: 160px; /* 고정 너비로 좌우 아이콘 위치 유지 */ |
| 111 | + display: flex; |
| 112 | + align-items: center; |
| 113 | + justify-content: space-between; |
| 114 | + color: #2d3552; |
| 115 | + font-weight: 500; |
| 116 | + font-size: 1.2rem; |
| 117 | +`; |
| 118 | + |
| 119 | +const Name = styled.span` |
| 120 | + flex: 1; |
| 121 | + text-align: center; |
| 122 | +`; |
| 123 | + |
| 124 | +const Placeholder = styled.div` |
| 125 | + width: 28px; /* 오른쪽 균형용 */ |
| 126 | +`; |
| 127 | + |
| 128 | +const ClickableIcon = styled.div` |
| 129 | + cursor: pointer; |
| 130 | +`; |
0 commit comments