Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 20 additions & 22 deletions src/app/routes/private/ArticlesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import type {
ArticlesOrderBy,
RestoreArticlesParams,
} from "@/api/articles/types";
import { getInterests } from "@/api/interests";
import type { InterestListItem, InterestOrderBy } from "@/api/interests/types";
import type { InterestListItem } from "@/api/interests/types";
import Button from "@/shared/components/button/Button";
import EmptyState from "@/shared/components/EmptyState";
import Input from "@/shared/components/Input";
Expand All @@ -28,6 +27,7 @@ import {
useSearchParams,
} from "react-router";
import { toast } from "react-toastify";
import { getUserActivities } from "@/api/user-activities";

interface ApiErrorResponse {
message: string;
Expand All @@ -38,10 +38,6 @@ interface ApiErrorResponse {
status?: number;
}

const INTEREST_ORDER_BY = "name" as InterestOrderBy;
const INTEREST_DIRECTION = "DESC" as SortDirection;
const INTEREST_LIMIT = 9999;

export default function ArticlesPage() {
const [searchParams, setSearchParams] = useSearchParams();

Expand Down Expand Up @@ -118,10 +114,10 @@ export default function ArticlesPage() {
};

const [sortValue, setSortValue] = useState(
reverseSortMap[orderBy] || "게시일"
reverseSortMap[orderBy] || "게시일",
);
const [directionValue, setDirectionValue] = useState(
direction === "DESC" ? "내림차순" : "오름차순"
direction === "DESC" ? "내림차순" : "오름차순",
);

const fetchInitialData = useCallback(async () => {
Expand Down Expand Up @@ -199,14 +195,16 @@ export default function ArticlesPage() {

const fetchInterestData = useCallback(async () => {
try {
const interestParams = {
orderBy: INTEREST_ORDER_BY,
direction: INTEREST_DIRECTION,
limit: INTEREST_LIMIT,
};

const response = await getInterests(interestParams, userId);
setInterests(response.content);
const response = await getUserActivities(userId);

const userInterests = response.subscriptions.map((sub) => ({
id: sub.interestId,
name: sub.interestName,
keywords: sub.interestKeywords,
subscriberCount: sub.interestSubscriberCount,
subscribedByMe: true,
}));
setInterests(userInterests);
} catch (error) {
console.error(error);
}
Expand All @@ -227,7 +225,7 @@ export default function ArticlesPage() {
},
{
threshold: 0.8,
}
},
);
if (lastElementRef.current) {
observerRef.current.observe(lastElementRef.current);
Expand All @@ -240,13 +238,13 @@ export default function ArticlesPage() {

const interestNames = useMemo(
() => interests.map((interest) => interest.name),
[interests]
[interests],
);

const handleInterestChange = (value: string) => {
setSelectedInterest(value);
const selectedInterestData = interests.find(
(interest) => interest.name === value
(interest) => interest.name === value,
);

if (selectedInterestData) {
Expand Down Expand Up @@ -292,21 +290,21 @@ export default function ArticlesPage() {

newParams.set(
"direction",
directionValue === "오름차순" ? "ASC" : "DESC"
directionValue === "오름차순" ? "ASC" : "DESC",
);

if (fromDate) {
newParams.set(
"publishDateFrom",
`${fromDate.replace(/\./g, "-")}T00:00:00`
`${fromDate.replace(/\./g, "-")}T00:00:00`,
);
} else {
newParams.delete("publishDateFrom");
}
if (toDate) {
newParams.set(
"publishDateTo",
`${toDate.replace(/\./g, "-")}T23:59:59`
`${toDate.replace(/\./g, "-")}T23:59:59`,
);
} else {
newParams.delete("publishDateTo");
Expand Down
6 changes: 1 addition & 5 deletions src/shared/components/modal/ArticleDetailModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export default function ArticleDetailModal({
},
{
threshold: 0.8,
}
},
);
if (lastElementRef.current) {
observerRef.current.observe(lastElementRef.current);
Expand Down Expand Up @@ -228,12 +228,8 @@ export default function ArticleDetailModal({
title: "댓글 삭제",
message: "정말 삭제하시겠습니까?",
onConfirm: async () => {
console.log("onConfirm 함수 실행 시작");

try {
console.log("deleteComment 호출 전");
await deleteComment(commentId);
console.log("deleteComment 호출 후");
toast.success("댓글이 삭제되었습니다.");
await fetchInitialData();
} catch (error) {
Expand Down