Skip to content

Commit

Permalink
Fix/버그 수정 여러개 (#31)
Browse files Browse the repository at this point in the history
* fix: 로그인 필요 시 모달 띄우기

* feat: 메인 페이지 로딩 전 기본 정보

* fix: 코멘트 페이지 로그인 모달 띄우기

* fix: 박스오피스 순위 내평점

* feat: 영화 상세 페이지 평가한 사람수

* fix: 코멘트 리스트 페이지 뒤로가기

* fix: CommentCard 스포일러

* fix: commentcard/mycommentbox 줄 수 제한'

* feat: commentcard 좋아요 버튼

* fix: 코멘트 리스트 좋아요 여부

* fix: 좋아요 누른 코멘트 리스트에 좋아요 표시

* fix: 유저 하위 페이지 commentcard 좋아요 반영

* fix: 검색창에서 username 대신 nickname

* fix: 코멘트 길면 포스터 작아지는 현상 수정

* fix: 영화상세 페이지 아닌 곳에서는 줄 수 제한 없음

* fix: 메인페이지 기본데이터 약간 수정

* fix: 메인페이지 기본데이터 약간 수정 2
  • Loading branch information
ComPhyPark authored Jan 31, 2024
1 parent 325e10c commit 8083e4f
Show file tree
Hide file tree
Showing 18 changed files with 331 additions and 96 deletions.
20 changes: 19 additions & 1 deletion src/apis/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,29 @@ import { BASE_API_URL } from "./const";

export async function getCommentListRequest(
movieCD: string,
accessToken?: string,
sortQuery?: string,
) {
if (!sortQuery) return fetch(`${BASE_API_URL}/contents/${movieCD}/comments`);
if (!sortQuery) {
return fetch(`${BASE_API_URL}/contents/${movieCD}/comments`, {
method: "GET",
headers: accessToken
? {
Authorization: "Bearer " + accessToken,
}
: {},
});
}
return fetch(
`${BASE_API_URL}/contents/${movieCD}/comments/?order=${sortQuery}`,
{
method: "GET",
headers: accessToken
? {
Authorization: "Bearer " + accessToken,
}
: {},
},
);
}

Expand Down
19 changes: 17 additions & 2 deletions src/apis/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,28 @@ export async function postUnFollow(accessToken: string, userId: number) {

export async function getUserWrittenComments(
userId: number,
accessToken?: string,
query?: "like" | "created" | "high-rating" | "low-rating",
) {
if (!query) {
return fetch(`${BASE_API_URL}/users/${userId}/comments/`);
return fetch(`${BASE_API_URL}/users/${userId}/comments/`, {
method: "GET",
headers: accessToken
? {
Authorization: "Bearer " + accessToken,
}
: {},
});
}

return fetch(`${BASE_API_URL}/users/${userId}/comments/?order=${query}`);
return fetch(`${BASE_API_URL}/users/${userId}/comments/?order=${query}`, {
method: "GET",
headers: accessToken
? {
Authorization: "Bearer " + accessToken,
}
: {},
});
}

export async function getUserRatingMovies(
Expand Down
42 changes: 35 additions & 7 deletions src/components/CommentCard.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@
margin: 20px 0;
display: flex;
align-items: center;
height: 150px;
min-height: 120px;
.posterBox {
width: 20%;
min-width: 100px;
min-width: 20%;

img {
cursor: pointer;
Expand All @@ -68,8 +68,7 @@
}
.commentTextBox {
margin-left: auto;

height: 120px;
min-height: 120px;
margin: 12px 0 15px 0;

.movieTitle {
Expand All @@ -87,17 +86,37 @@
margin: 0px 0px 7px;
}
.commentText {
display: block;
line-height: 24px;
font-size: 14px;
font-weight: 400;
word-break: break-all;
white-space-collapse: preserve;
white-space: pre-wrap;
word-break: break-word;
cursor: pointer;

.spoiler {
button {
cursor: pointer;
background: none;
border: none;
color: rgb(255, 47, 110);
font-size: 15px;
}
}
}
.commentText.inContentPage {
text-overflow: ellipsis;
overflow: hidden;
display: -webkit-box;
-webkit-line-clamp: 5;
-webkit-box-orient: vertical;
}
}
}

.commentContentContainer.inContentPage {
height: 120px;
}

.commentFeedbackCon {
display: flex;
align-items: center;
Expand Down Expand Up @@ -127,9 +146,18 @@
color: $pink;
cursor: pointer;
}
button:disabled {
color: rgba(255, 47, 110, 0.5);
cursor: default;
}
.liked {
background: rgb(255, 47, 110);
color: rgb(255, 255, 255);
}
.liked:disabled {
background: rgba(255, 47, 110, 0.5);
color: rgb(255, 255, 255);
cursor: default;
}
}
}
110 changes: 97 additions & 13 deletions src/components/CommentCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,48 @@ import { CommentType } from "../type";

import styles from "./CommentCard.module.scss";
import profileDefault from "../assets/user_default.jpg";
import { Link, useNavigate } from "react-router-dom";
import {
Link,
useLocation,
useNavigate,
useOutletContext,
} from "react-router-dom";
import { useState } from "react";
import { useAuthContext } from "../contexts/authContext";
import { OutletContextType } from "../pages/Layout";
import { postToggleCommentLike } from "../apis/comment";
import { defaultResponseHandler } from "../apis/custom";

export default function CommentCard({ comment }: { comment: CommentType }) {
// user 하위 페이지에서 코멘트를 불러오는 경우, movie의 정보를 이용해야 한다.
console.log(comment);
const { accessToken } = useAuthContext();
const { setCurrentModal } = useOutletContext<OutletContextType>();
const likeExceptMe =
(comment.like_count ?? comment.likes_count) -
(comment.liked_by_user ? 1 : 0);
const [likeByMe, setLikeByMe] = useState(comment.liked_by_user);
const [likeGoing, setLikeGoing] = useState(false);
const [spoiler, setSpoiler] = useState(comment.has_spoiler);
const inContentPage = /^\/contents\/\d+$/.test(location.pathname);

const likeClicked = () => {
if (!accessToken) {
setCurrentModal("login");
return;
}
setLikeGoing(true);
postToggleCommentLike(comment.id, accessToken)
.then(defaultResponseHandler)
.then(() => {
setLikeByMe(!likeByMe);
setLikeGoing(false);
})
.catch((e) => {
setLikeGoing(false);
console.log(e);
});
};

return (
<li className={styles.cardCon}>
Expand All @@ -27,29 +65,57 @@ export default function CommentCard({ comment }: { comment: CommentType }) {
</div>
)}
</div>
<div className={styles.commentContentContainer}>
<CommentContentBox comment={comment} />
<div
className={
styles.commentContentContainer +
(inContentPage ? " " + styles.inContentPage : "")
}
>
<CommentContentBox
comment={comment}
spoiler={spoiler}
setSpoiler={setSpoiler}
/>
</div>

<div className={styles.commentFeedbackCon}>
<img
src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij4KICA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LjE0Mi00LjAzIDcuNS05IDcuNS0uNzM5IDAtMS40NTYtLjA3NC0yLjE0My0uMjE0eiIvPgo8L3N2Zz4K"
alt=""
/>
{comment.reply_count}
</div>
<div className={styles.commentLikeBtnBox}>
<button
className={likeByMe ? styles.liked : ""}
disabled={spoiler || likeGoing}
onClick={likeClicked}
>
좋아요
</button>
</div>
</li>
);
}

function CommentContentBox({ comment }: { comment: CommentType }) {
function CommentContentBox({
comment,
spoiler,
setSpoiler,
}: {
comment: CommentType;
spoiler: boolean;
setSpoiler: (s: boolean) => void;
}) {
const navigate = useNavigate();
const location = useLocation();
const onHiddenMoviedata = window.location.pathname.includes("contents");
const inContentPage = /^\/contents\/\d+$/.test(location.pathname);

return (
<>
Expand All @@ -65,7 +131,12 @@ function CommentContentBox({ comment }: { comment: CommentType }) {
</div>
)}
<div className={styles.commentTextBox}>
<div className={styles.commentText}>
<div
className={
styles.commentText +
(inContentPage ? " " + styles.inContentPage : "")
}
>
{!onHiddenMoviedata && (
<p
className={styles.movieTitle}
Expand All @@ -86,13 +157,26 @@ function CommentContentBox({ comment }: { comment: CommentType }) {
영화 · {new Date(comment.movie.release_date).getFullYear()}
</p>
)}
<span
onClick={() => {
navigate(`/comments/${comment.id}`);
}}
>
{comment.content}
</span>
{spoiler ? (
<div className={styles.spoiler}>
이 코멘트에는 스포일러가 있습니다.{" "}
<button
onClick={() => {
setSpoiler(false);
}}
>
보기
</button>
</div>
) : (
<span
onClick={() => {
navigate(`/comments/${comment.id}`);
}}
>
{comment.content}
</span>
)}
</div>
</div>
</>
Expand Down
17 changes: 13 additions & 4 deletions src/components/CommentInfo.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Link, useParams } from "react-router-dom";
import { Link, useOutletContext, useParams } from "react-router-dom";
import userImage from "../assets/user_default.jpg";
import styles from "./CommentInfo.module.scss";

Expand All @@ -16,6 +16,7 @@ import { getCommentReplies } from "../apis/comment";
import DeleteComReplyModal from "./DeleteComReplyModal";
import { MdEdit } from "react-icons/md";
import { RiDeleteBin6Line } from "react-icons/ri";
import { OutletContextType } from "../pages/Layout";

function CommentHeader({ comment }: { comment: CommentType }) {
const { movie, rating, created_by, created_at } = comment;
Expand Down Expand Up @@ -155,7 +156,8 @@ function LikeReplyBar({
) => void;
refetchComment: () => void;
}) {
const { accessToken } = useAuthContext();
const { isLogined, accessToken } = useAuthContext();
const { setCurrentModal } = useOutletContext<OutletContextType>();
const { id: commentId } = useParams();

return (
Expand All @@ -164,7 +166,10 @@ function LikeReplyBar({
<div className={styles.likeReplyGrid}>
<button
onClick={() => {
if (!accessToken) return;
if (!accessToken) {
setCurrentModal("login");
return;
}
if (!commentId) return;
postToggleCommentLike(parseInt(commentId), accessToken)
.then(defaultResponseHandler)
Expand Down Expand Up @@ -219,6 +224,10 @@ function LikeReplyBar({
</button>
<button
onClick={() => {
if (!isLogined) {
setCurrentModal("login");
return;
}
setCurrentModalState({ type: "createReply" });
}}
>
Expand Down Expand Up @@ -275,7 +284,7 @@ export default function CommentInfo({
setNextRepliesUrl(repliesResponse.next);
})
.catch(() => alert("잘못된 요청입니다"));
}, [commentId]);
}, [commentId, accessToken]);

// 무한스크롤 페이지네이션 특성상 단순히 데이터 리패칭을 할 수 없음 따라서 state를 직접 변경한다.
const deleteReplyState = (replyId: number) => {
Expand Down
Loading

0 comments on commit 8083e4f

Please sign in to comment.