-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprofile.tsx
220 lines (196 loc) · 5.53 KB
/
profile.tsx
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
import ProfileInfo from 'components/profile/profileInfo';
import FixedTopBar from 'components/TopBar/FixedTopBar';
import styled from 'styled-components';
import { useState, useEffect } from 'react';
import Image from 'next/image';
import { BsFillPencilFill } from 'react-icons/bs';
import Keywords from 'components/profile/keywords';
import { sendProfileImage, getProfile } from 'utils/apis/api';
import { useCookies } from 'react-cookie';
import Contribution from '@components/profile/contribution';
import { profile } from '@public/images';
const Layout = styled.div`
width: 100vw;
height: 95vh;
background-color: #333;
`;
const ProfileLayout = styled.div`
width: 80vw;
height: 90vh;
margin: 5vh auto 0px auto;
display: flex;
padding: 20px;
`;
const ProfileInfoLayout = styled.div`
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-around;
`;
const ProfileImageLayout = styled.div`
width: 300px;
height: 300px;
border-radius: 50%;
background-color: rgb(197, 197, 197);
border: 4px solid rgb(255, 255, 255);
cursor: pointer;
display: flex;
justify-content: center;
align-items: center;
position: relative;
`;
const UserProfileImage = styled(Image)`
border-radius: 50%;
object-fit: cover;
`;
const ProfileImageInput = styled.input`
display: none;
`;
const HoverInput = styled.div`
width: inherit;
height: inherit;
position: absolute;
background-color: rgba(0, 0, 0, 0.2);
border-radius: 50%;
`;
const InputLabel = styled.label`
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
`;
const ProfileDetailLayout = styled.div`
width: 300px;
height: 400px;
background-color: white;
border-radius: 10px;
`;
const QuestionInfoLayout = styled.div`
width: 100%;
display: flex;
flex-direction: column;
padding: 0px 80px;
justify-content: space-around;
gap: 20px;
`;
const Keyword = styled.div`
width: 100%;
height: 100%;
border-radius: 10px;
background-color: white;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
gap: 10px;
`;
const Title = styled.span`
font-size: 20px;
font-weight: 600;
text-align: center;
padding: 7px;
`;
const Profile = () => {
const [cookies, setCookie, removeCookie] = useCookies(['userInfo']);
const [userInfo, setUserInfo] = useState({
username: '',
email: '',
questionCount: 0,
keywords: [],
});
const [profileImage, setProfileImage] = useState("");
const [hoverProfileImage, setHoverProfileImage] = useState(false);
useEffect(() => {
setProfile();
}, []);
const setProfile = async () => {
let result: any = await getProfile(cookies.userInfo.userid);
console.log(result);
result = result.data.context;
setUserInfo({
...userInfo,
username: result.info.username,
email: result.info.email,
questionCount: result.info.questionCount,
keywords: result.keywords,
});
const newBlob = new Blob([new Uint8Array(result.info.image)], {
type: 'image/png',
});
setProfileImage(result.info.image);
};
const handleHover = () => {
hoverProfileImage
? setHoverProfileImage(false)
: setHoverProfileImage(true);
};
const handleFile = async (e: any) => {
const formData: FormData = new FormData();
formData.append('img', e.target.files[0]);
formData.append('userid', cookies.userInfo.userid);
const result = await sendProfileImage(cookies.userInfo.userid, formData);
if (result.status === 200) {
setProfileImage(URL.createObjectURL(e.target.files[0]));
}
};
return (
<Layout>
<FixedTopBar />
<ProfileLayout>
<ProfileInfoLayout>
<ProfileImageLayout
onMouseEnter={handleHover}
onMouseLeave={handleHover}
>
{profileImage.length > 0 ? (
<UserProfileImage src={profileImage} width={300} height={300} />
) : null}
{/* <UserProfileImage src={profile} width={300} height={300} /> */}
{hoverProfileImage ? (
<HoverInput>
<ProfileImageInput
type="file"
id="file"
accept="image/png, image/jpeg"
onChange={handleFile}
/>
<InputLabel htmlFor="file">
<BsFillPencilFill size={40} color="gray" />
</InputLabel>
</HoverInput>
) : null}
</ProfileImageLayout>
<ProfileDetailLayout>
<ProfileInfo
email={userInfo.email}
username={userInfo.username}
questionCount={userInfo.questionCount}
/>
</ProfileDetailLayout>
</ProfileInfoLayout>
<QuestionInfoLayout>
<Keyword>
<Title>My Keywords</Title>
<Keywords data={userInfo.keywords} />
</Keyword>
{/* <div
style={{
display: 'flex',
justifyContent: 'space-between',
gap: '20px',
}}
>
<AddInfo />
<AddInfo />
</div> */}
<Keyword>
<Contribution />
</Keyword>
</QuestionInfoLayout>
</ProfileLayout>
</Layout>
);
};
export default Profile;