();
useEffect(() => {
- const fetchPostDetail = async () => {
- console.log('location.state:', location.state);
-
+ const { sharePostId } = location.state.postDetail;
+ const fetchPostDetail = async (postId: number) => {
try {
- if (location.state?.postDetail) {
- const { sharePostId } = location.state.postDetail;
-
- console.log('sharePostId:', sharePostId);
+ console.log('sharePostId:', postId);
- const data = await getSharePostDetail(sharePostId);
+ const data = await getSharePostDetail(postId);
- setPostDetail(data);
- } else {
- console.warn('postDetail not found in location.state');
- }
+ setPostDetail(data);
} catch (error) {
console.error('❌ 공유 게시글 상세 조회에 실패했습니다.', error);
}
};
- fetchPostDetail();
+ const fetchLikeCounts = async (postId: number) => {
+ try {
+ const response = await getSharePostLikeCount(postId);
+ if (!response) throw new Error('error while fetching like count');
+ console.log(response);
+ setLikeCount(response.data.likeCount);
+ } catch (error) {
+ console.error('❌ 편지 좋아요 갯수를 가져오는 중 에러가 발생했습니다', error);
+ throw new Error('편지 좋아요 갯수 가져오기 실패');
+ }
+ };
+
+ if (location.state?.postDetail) {
+ fetchPostDetail(sharePostId);
+ fetchLikeCounts(sharePostId);
+ } else {
+ console.warn('postDetail not found in location.state');
+ }
}, [location.state]);
const handleProposalApproval = async (
diff --git a/src/pages/LetterBoxDetail/index.tsx b/src/pages/LetterBoxDetail/index.tsx
index e2b7097..262cc03 100644
--- a/src/pages/LetterBoxDetail/index.tsx
+++ b/src/pages/LetterBoxDetail/index.tsx
@@ -72,7 +72,6 @@ const LetterBoxDetailPage = () => {
});
const shareMutation = useMutation({
- // Todo : useAuthStore -> myId 대체
mutationFn: () => postShareProposals(selected, userInfo.id, shareComment),
onSuccess: () => {
toggleShareMode();
diff --git a/src/pages/MyPage/components/MyBoardPage.tsx b/src/pages/MyPage/components/MyBoardPage.tsx
new file mode 100644
index 0000000..388934f
--- /dev/null
+++ b/src/pages/MyPage/components/MyBoardPage.tsx
@@ -0,0 +1,66 @@
+import { useQuery } from '@tanstack/react-query';
+import { useNavigate } from 'react-router';
+import { twMerge } from 'tailwind-merge';
+
+import { getMySharePostList } from '@/apis/mypage';
+import BackgroundBottom from '@/components/BackgroundBottom';
+import PageTitle from '@/components/PageTitle';
+
+import LetterPreview from '../../LetterBoard/components/LetterPreview';
+
+const MyBoardPage = () => {
+ const navigate = useNavigate();
+
+ const fetchMyPostList = async () => {
+ try {
+ const response = await getMySharePostList();
+ if (!response) throw new Error('게시글 목록을 불러오는데 실패했습니다.');
+ console.log(response);
+ return response.data;
+ } catch (e) {
+ console.error(e);
+ }
+ };
+
+ const {
+ data: postLists = [],
+ isLoading,
+ isError,
+ } = useQuery({
+ queryKey: ['sharePostList'],
+ queryFn: () => fetchMyPostList(),
+ enabled: true,
+ staleTime: 1000 * 60 * 5,
+ gcTime: 1000 * 60 * 10,
+ });
+
+ if (isError) {
+ navigate('/notFound');
+ }
+ return (
+ <>
+
+ 내가 올린 게시물
+ {isLoading ? (
+ loading
+ ) : (
+
+ {postLists.map((item, index) => (
+
+ ))}
+
+ )}
+
+
+ >
+ );
+};
+
+export default MyBoardPage;
diff --git a/src/pages/MyPage/index.tsx b/src/pages/MyPage/index.tsx
index 4c00707..2ed0b5c 100644
--- a/src/pages/MyPage/index.tsx
+++ b/src/pages/MyPage/index.tsx
@@ -81,9 +81,13 @@ const MyPage = () => {
계정
diff --git a/src/stores/authStore.ts b/src/stores/authStore.ts
index 6c881cc..a0b56c1 100644
--- a/src/stores/authStore.ts
+++ b/src/stores/authStore.ts
@@ -1,7 +1,7 @@
import { create } from 'zustand';
import { persist, createJSONStorage } from 'zustand/middleware';
-import { postLogout } from '@/apis/auth';
+// import { postLogout } from '@/apis/auth';
interface AuthStore {
isLoggedIn: boolean;
@@ -21,12 +21,13 @@ const useAuthStore = create(
zipCode: '',
login: () => set({ isLoggedIn: true }),
logout: async () => {
- try {
- await postLogout();
- } catch (e) {
- console.error(e);
- }
set({ isLoggedIn: false, zipCode: '', accessToken: '' });
+ // location.reload();
+ // try {
+ // await postLogout();
+ // } catch (e) {
+ // console.error(e);
+ // }
},
setZipCode: (zipCode) => set({ zipCode: zipCode }),
setAccessToken: (accessToken) => set({ accessToken: accessToken }),
diff --git a/src/types/share.d.ts b/src/types/share.d.ts
new file mode 100644
index 0000000..df79d3b
--- /dev/null
+++ b/src/types/share.d.ts
@@ -0,0 +1,29 @@
+//공유 게시글 상세 페이지 편지
+interface ShareLetter {
+ id: number;
+ content: string;
+ writerZipCode: string;
+ receiverZipCode: string;
+}
+
+// 공유 게시글 목록 조회 타입
+interface SharePost {
+ writerZipCode: string;
+ receiverZipCode: string;
+ content: string;
+ createdAt: string;
+ active: boolean;
+ sharePostId: number;
+ sharePostContent: string;
+ letters: ShareLetter[];
+}
+
+// 페이징 포함
+interface SharePostResponse {
+// data: any;
+ content: SharePost[];
+ currentPage: number;
+ size: number;
+ totalElements: number;
+ totalPages: number;
+}