Skip to content

Commit

Permalink
[fix] #68, #43 댓글 데이터 수정, 마이페이지 수정, 탈퇴 구현 중
Browse files Browse the repository at this point in the history
  • Loading branch information
kr-nius committed Dec 4, 2023
1 parent dbf970a commit 749e5a9
Show file tree
Hide file tree
Showing 7 changed files with 589 additions and 83 deletions.
21 changes: 15 additions & 6 deletions src/app/detail/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ interface boardCommentType {
createdDate: string;
createdTime: string;
replyList: [];
status: number;
}

export default function Detail(): JSX.Element {
Expand Down Expand Up @@ -53,20 +54,23 @@ export default function Detail(): JSX.Element {
setLocalBoardId(boardIdNumber);

console.log("정수 변환", boardIdNumber);
console.log("로컬에서 불러온 아이읻", localBoardId);
console.log("로컬에서 불러온 아이디", localBoardId);
}, []);

useEffect(() => {
const fetchData = async () => {
try {
const response = await axios.get(
`https://www.jerneithe.site/board/detail/${localBoardId}`,
`https://www.jerneithe.site/board/detail/${localBoardId}`
// `https://www.jerneithe.site/board/detail/3`,
);
console.log("detail response: ", response.data);
console.log("댓글: ", response.data.comments);
setBoardDetail(response.data);
setComment(response.data.comments);
// setComment(
// response.data.comments.filter((comment: any) => comment.status === 1)
// );
console.log(response);
} catch (error) {
console.error("Error fetching data:", error);
Expand Down Expand Up @@ -136,15 +140,17 @@ export default function Detail(): JSX.Element {

<section
className="main flex flex-col items-center"
style={{ width: "70%" }}>
style={{ width: "70%" }}
>
{boardDetail && (
<>
<div className="w-full flex items-center">
<Profile nickName={boardDetail.nickName} />
{decoded_nickName === boardDetail.nickName && (
<div
onClick={toggleDropdown}
className="ml-auto flex flex-col items-center p-3">
className="ml-auto flex flex-col items-center p-3"
>
<Image
src="/images/more.svg"
alt="etc"
Expand All @@ -156,12 +162,14 @@ export default function Detail(): JSX.Element {
<div className="dropdown absolute mt-7 z-10">
<button
onClick={handleEdit}
className="block w-full text-left py-2 px-4 hover:bg-gray-200 focus:outline-none">
className="block w-full text-left py-2 px-4 hover:bg-gray-200 focus:outline-none"
>
수정
</button>
<button
onClick={handleDelete}
className="block w-full text-left py-2 px-4 hover:bg-gray-200 focus:outline-none">
className="block w-full text-left py-2 px-4 hover:bg-gray-200 focus:outline-none"
>
삭제
</button>
</div>
Expand All @@ -182,6 +190,7 @@ export default function Detail(): JSX.Element {
accessToken={accessToken}
boardComment={comment}
decoded_nickName={decoded_nickName}
localBoardId={localBoardId}
/>
</div>
<CategoryDetail category={boardDetail.category} />
Expand Down
72 changes: 43 additions & 29 deletions src/app/mypage/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,25 @@ interface FEEDATA {
weather: string;
}

// interface userProfileType {
// id: number;
// email: string;
// fromSocial: boolean;
// image: string | null;
// name: string;
// nickname: string;
// password: string;
// phone: number | null;
// status: boolean;
// }

export default function Mypage() {
// 회원 정보 수정 모달
const [showProfileModify, setShowProfileModify] = useState<boolean>(false);

// 회원 정보
const [userPofile, setUserProfile] = useState<any>(null);
const [userImage, setUserImage] = useState<string | null>("");
const [nickname, setNickname] = useState<string | undefined>("");
const [password, setPassword] = useState<string | undefined>("");

Expand Down Expand Up @@ -63,7 +76,6 @@ export default function Mypage() {
}

setEmail(localStorage.getItem("user_email"));

}, [logintoken]);

// ------------------------------------------------------------------------
Expand Down Expand Up @@ -94,51 +106,50 @@ export default function Mypage() {
const decoded_nickName = decodedToken?.sub;
console.log("디코딩", decodedToken);

const response = await axios.post(
`https://www.jerneithe.site/user/api/profile`,
{ email: "user95@test.com" }
);
setUserProfile(response.data);
// const response = await axios({
// method: "POST",
// url: "https://www.jerneithe.site/user/api/profile",
// data: {
// email: email,
// },
// });

// 비밀번호 디코딩
// console.log("회원정보 pw: ", response.data.password);
// let pw_jwt = response.data.password;
// let pw_payload = pw_jwt.substring(
// pw_jwt.indexOf(".") + 1,
// pw_jwt.lastIndexOf(".")
// const response = await axios.post(
// `https://www.jerneithe.site/user/api/profile`,
// { email: "user100@test.com" }
// );

// console.log("pw_payload: ", pw_payload);
const response = await axios({
method: "POST",
url: `https://www.jerneithe.site/user/api/profile`,
headers: {
Authorization: "Bearer " + accessToken,
},
data: {
email: localStorage.getItem("user_email"),
},
});

// let pw_decode = base64.decode(pw_payload);

// console.log("pw 디코딩: ", pw_decode);

// 기존 것
// let password_jwt: string = response.data.password;
// const decodedPass = password_jwt
// ? (jwt.decode(password_jwt) as { [key: string]: any })
// : null;
// // console.log("디코딩 비번", decodedPass);
// const decoded_password = decodedPass?.sub;
// setPassword(decoded_password);

console.log("회원정보 Data: ", response.data);
setUserProfile(response.data);
setNickname(response.data.nickname);
setUserImage(response.data.image);
} catch (error) {
console.error("회원정보 에러: ", error);
}
};
profileData();
}, []);

console.log("회원정보 Data: ", userPofile);

// ------------------------------------------------------------------------

// board 이미지 데이터 불러오기
// board 이미지 데이터 불러오기 (my post)
useEffect(() => {
const postData = async () => {
const req = await axios.get("https://www.jerneithe.site/board/list");
const data: FEEDATA[] = req.data;
const filteredData = data.filter((item) => item.nickName === "테스터");
const filteredData = data.filter((item) => item.nickName === nickname);
console.log("filterData: ", filteredData);
setMyPostData(filteredData);
};
Expand Down Expand Up @@ -168,6 +179,7 @@ export default function Mypage() {
nickname={userPofile.nickname}
postnum={myPostData.length}
myPostData={myPostData}
userProfileImage={userImage}
/>
</>
)}
Expand All @@ -191,6 +203,8 @@ export default function Mypage() {
email={userPofile.email}
name={userPofile.name}
password={userPofile.password}
userProfileImage={userImage}
accessToken={logintoken}
/>
)}
</>
Expand Down
5 changes: 4 additions & 1 deletion src/component/CommentIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ interface CommentIconProps {
accessToken: string | undefined;
boardComment: boardCommentType[];
decoded_nickName: string;
localBoardId: number | null;
}

interface boardCommentType {
Expand All @@ -18,10 +19,11 @@ interface boardCommentType {
createdDate: string;
createdTime: string;
replyList: [];
status: number;
}

export default function CommentIcon(props: CommentIconProps) {
const { accessToken, boardComment, decoded_nickName } = props;
const { accessToken, boardComment, decoded_nickName, localBoardId } = props;

console.log("아이콘 눌렀을 때 댓글: ", boardComment);

Expand Down Expand Up @@ -49,6 +51,7 @@ export default function CommentIcon(props: CommentIconProps) {
accessToken={accessToken}
boardComment={boardComment}
decoded_nickName={decoded_nickName}
localBoardId={localBoardId}
/>
)}
</>
Expand Down
Loading

0 comments on commit 749e5a9

Please sign in to comment.