-
Notifications
You must be signed in to change notification settings - Fork 1
/
ViewPage.js
236 lines (214 loc) · 10.2 KB
/
ViewPage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
import { useContext, useEffect, useState } from "react";
import styled from "styled-components";
import { UserContext } from "../contexts/userContext";
import axios from "axios";
import flower from "../assets/flower.png"
import OverImage from '../assets/over.png';
import { Link, useLocation } from "react-router-dom";
const Div = styled.div `
display: ${props => props.display || "flex"};
justify-content: ${props => props.justifyContent || "center"};
flex-direction: ${props => props.flexDirection || "row"};
align-items: ${props => props.alignItems || "center"};
width : ${props => props.width || "100%"};
height : ${props => props.height || "100%"};
border : ${props => props.border || "0px solid black"};
border-radius : ${props => props.borderRadius || "0px"};
box-sizing : ${props => props.boxSizing || "border-box"};
background-color: ${props => props.backgroundColor || "white"};
color: ${props => props.color || "black"};
font-size: ${props => props.fontSize || "10px"};
padding : ${props => props.padding || "0px"};
margin : ${props => props.margin || "0px"};
overflow: ${props => props.overflow || ""};
border-bottom : ${props => props.borderBottom || "0px solid black"};
border-top : ${props => props.borderTop || "0px solid black"};
`;
const Img = styled.img`
width: ${props => props.width || "12vh"};
`;
const Input = styled.input`
border: none;
width: 100%;
height : ${props => props.height || "100%"};
background-color: ${props => props.backgroundColor || "white"};
&::placeholder {
color: black;
}
`;
const Button = styled.button`
border: ${props => props.border || "none"};
background-color: ${props => props.backgroundColor || "black"};
color: ${props => props.color || "white"};
width: 100%;
height : ${props => props.height || "80%"};
border-radius: 28px;
`;
function ViewPage() {
const funeralName = "꼴초 김현중님 장례식"
const keyValue = localStorage.getItem("key");
console.log(keyValue);
const [curComment, setCurComment] = useState(null);
const [messageClicked, setMessageClicked] = useState(false);
const [commentChanged, setCommentChanged] = useState(false);
const [comments, setComments] = useState([]);
const [logInData, setLogInData] = useContext(UserContext);
const [userData, setUserData] = useState("");
console.log(userData);
console.log(comments);
console.log(commentChanged);
const handleCommentChange = (e) => {
console.log(e.target.value);
setCurComment(e.target.value);
}
const getData = async () => {
try {
const data = await axios.get(`http://172.17.200.74:8080/api/v1/posting/${keyValue}`);
setUserData(data.data.data);
setComments(data.data.data.comment);
} catch (error) {
console.log(error);
}
// const comments = await axios.get("http://172.17.200.74:8080/api/v1/posting/2");
}
useEffect(() => {
getData();
}, [commentChanged]);
const startDate = new Date(userData.startDate);
// 월과 일 추출
const month = startDate.getMonth() + 1; // getMonth()는 0부터 시작하므로 +1 해줍니다.
const day = startDate.getDate();
const handleCommentUpload = async (e) => {
const newComment = {
"content": curComment,
}
const response = await axios.post(`http://172.17.200.74:8080/api/v1/posting/${keyValue}/comment`, newComment);
console.log(response);
setCommentChanged(!commentChanged);
setCurComment('');
}
const setMessageClickedFalse = async (e) => {
setMessageClicked(false);
}
const setMessageClickedTrue = async (e) => {
setMessageClicked(true);
}
return (
<Div>
<Div flexDirection="column" width="80%" height="90vh">
<Div height="20%" fontSize="80px" >{userData.title}</Div>
<Div height="70%">
<Div width="30%" flexDirection="column">
{messageClicked == false ? <div
style={{
position: "relative",
width: "380px",
height: "470px"
}}>
{/* 첫 번째 이미지 */}
<img
src={userData.imageUrl}
alt="사진"
width="380px"
height="470px"
style={{
borderRadius: "20px"
}}/> {/* 두 번째 이미지 */}
<img
src={OverImage}
alt="오버사진"
width="380px"
height="470px"
style={{
position: "absolute",
top: 0,
left: 0,
zIndex: 1,
opacity: 1
}}/>
</div>: <div
style={{
position: "relative",
width: "380px",
height: "470px"
}}>
{/* 첫 번째 이미지 */}
<img
src={userData.imageUrl}
alt="사진"
width="380px"
height="470px"
style={{
borderRadius: "20px"
}}/> {/* 두 번째 이미지 */}
<img
src={OverImage}
alt="오버사진"
width="380px"
height="470px"
style={{
position: "absolute",
top: 0,
left: 0,
zIndex: 1,
opacity: 1
}}/>
<Div width="380px"
height="470px"
backgroundColor="black"
color="white"
flexDirection="column"
style={{
position: "absolute",
top: 0,
left: 0,
zIndex: 2,
opacity: 0.7
}}>
<Div backgroundColor="black" color="white" fontSize="32px" height="20%" margin="20px 0 0 0">유언장</Div>
<Div backgroundColor="black" color="white" fontSize="24px" height="80%" width="80%">{userData.content}</Div>
</Div>
</div>}
<Div height="30%">
<Link to="/editPage"><Button name="comment2" onClick={setMessageClickedFalse} >수정</Button></Link>
<Button name="comment2" onClick={setMessageClickedFalse} >영정 사진</Button>
<Button name="comment2" onClick={setMessageClickedTrue} backgroundColor="white" border="solid 1px black" color="black">유언장</Button>
</Div>
</Div>
<Div width="70%" flexDirection="column" alignItems="end">
<Div width="80%" backgroundColor="#F0F0F0" borderRadius="20px" flexDirection="column" >
<Div height="10%" width="95%" backgroundColor="#F0F0F0" color="black" justifyContent="start" borderBottom="1px solid black" >
<Div width="20%" fontSize="15px" backgroundColor="#F0F0F0" >조문 종료 기간</Div>
<Div width="20%" fontSize="15px" backgroundColor="#F0F0F0">{month}월 {day+3}일</Div>
</Div>
<Div flexDirection="column" height="80%" width="95%" backgroundColor="#F0F0F0" overflow="scroll" justifyContent="start" borderBottom="1px solid black" >
{comments.map((comment, index) => (
<Div key={index} margin="1% 0 0 0" backgroundColor="#F0F0F0" alignItems="start" height="10%">
<Div height="100%" justifyContent="start" alignItems="center" fontSize="12px" fontWeight="bold" backgroundColor="#F0F0F0" >
<Div width="10%" backgroundColor="#F0F0F0">
<Img src={flower} width="30px"/>
</Div>
{comment.content}
</Div>
</Div>
))}
</Div>
<Div height="10%" width="95%" backgroundColor="#F0F0F0" >
<Div width="10%" backgroundColor="#F0F0F0" height="100%">
<Img src={flower} width="30px"/>
</Div>
<Div width="75%" justifyContent="start" alignItems="center" height="100%" backgroundColor="#F0F0F0">
<Input type="text" height="90%" placeholder="댓글 달기.." name="inputComment" value={curComment} backgroundColor="#F0F0F0" onChange={handleCommentChange} />
</Div>
<Div width="15%" justifyContent="end" alignItems="center" backgroundColor="#F0F0F0" >
<Button name="comment2" onClick={handleCommentUpload} >댓글 작성</Button>
</Div>
</Div>
</Div>
</Div>
</Div>
</Div>
</Div>
);
}
export default ViewPage;