Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

마이페이지 찜한 게시물 리스트 작업 및 github action세팅 #46

Merged
merged 16 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
21 changes: 21 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: CD
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
on:
push:
branches:
- main
jobs:
Deploy-Production:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install Vercel CLI
run: npm install --global vercel@latest
- name: Pull Vercel Environment Information
run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }}
- name: Build Project Artifacts
run: vercel build --prod --token=${{ secrets.VERCEL_TOKEN }}
- name: Deploy Project Artifacts to Vercel
run: vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }}
27 changes: 27 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: CI

on: [pull_request]

jobs:
lint:
name: Lint
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v2
with:
node-version: '18'
- run: npm install
- run: npm run lint
build:
name: Build
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v2
with:
node-version: '18'
- run: npm install
- run: CI='false' npm run build
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ dist-ssr
*.sw?

.env

.vercel
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"lint": "eslint \"src/**/*.{js,jsx,ts,tsx}\"",
"lint:fix": "eslint --fix \"src/**/*.{js,jsx,ts,tsx}\"",
"preview": "vite preview"
},
"dependencies": {
Expand Down
11 changes: 8 additions & 3 deletions src/components/Inner.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { ReactNode } from 'react';
import { CSSProperties, ReactNode } from 'react';
import styles from './Inner.module.scss';

interface InnerProp {
children: ReactNode;
style?: CSSProperties;
}

const Inner = ({ children }: InnerProp) => {
return <div className={styles.inner}>{children}</div>;
const Inner = ({ children, style }: InnerProp) => {
return (
<div className={styles.inner} style={style}>
{children}
</div>
);
};

export default Inner;
2 changes: 1 addition & 1 deletion src/components/button/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import styles from './button.module.scss';
import styles from './Button.module.scss';

interface Props {
data: string;
Expand Down
113 changes: 113 additions & 0 deletions src/components/mypage/LikedPosts.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import { deleteDocument, getAllDocument } from '@/lib/firebaseQuery';
import useUserStore from '@/store/useUsersStore';
import { useEffect, useState } from 'react';
import { useNavigate } from 'react-router-dom';
import RenderLikedPosts from './RenderLikedPosts';
import styles from './Mypage.module.scss';
import { Pagination } from 'antd';
import { DocumentData } from 'firebase/firestore';

export interface Liked {
id: string;
data: DocumentData;
}

const MyPosts = () => {
const itemsPerPage = 4;
const [likes, setLikes] = useState<Liked[]>([]);
const [currentPage, setCurrentPage] = useState(1);
const navigate = useNavigate();

const { user } = useUserStore();

const indexOfLastItem = currentPage * itemsPerPage;
const indexOfFirstItem = indexOfLastItem - itemsPerPage;
const currentItems = likes.slice(indexOfFirstItem, indexOfLastItem);

useEffect(() => {
const fetchData = async () => {
if (!user) return;

try {
const docSnap = await getAllDocument(`/heart/${user.uid}/like`);

setLikes(docSnap);
} catch (error) {
console.error('데이터를 가져오는 중 오류 발생:', error);
}
};

fetchData();
}, [user]);

const handlePageChange = (pageNumber: number) => {
setCurrentPage(pageNumber);
};

const onCancleLikedPost = async (likeId: string) => {
const confirm = window.confirm('해당 게시물의 좋아요를 취소하시겠습니까?');

if (confirm && user) {
try {
await deleteDocument(`/heart/${user.uid}/like/${likeId}`);

setLikes((prev) => prev.filter((like) => like.id !== likeId));

const newTotal = likes.length - 1;
const maxPage = Math.ceil(newTotal / itemsPerPage);
if (currentPage > maxPage) {
setCurrentPage(maxPage > 0 ? maxPage : 1);
}
console.log('글이 삭제 되었습니다.');
} catch (error) {
console.log(error);
}
}

return;
};

const onMoveToDocument = (likeId: string) => {
navigate(`/community/detail/${likeId}`);
};

return (
<div style={{ height: '100%' }}>
<div className={styles.myactive__posts__title}>
<span>좋아요한 게시물</span>
</div>
{likes.length === 0 ? (
<>
<div className={styles.myactive__posts__box__none}>
좋아요한 게시물이 없습니다.
</div>
</>
) : (
<>
<div className={styles.myactive__posts__box}>
{currentItems.map((like) => (
<RenderLikedPosts
key={like.id}
like={like}
onCancleLikedPost={onCancleLikedPost}
onMoveToDocument={onMoveToDocument}
/>
))}
</div>
</>
)}

<div className={styles.pagination}>
<Pagination
defaultCurrent={currentPage}
total={likes.length}
pageSize={itemsPerPage}
onChange={handlePageChange}
hideOnSinglePage={true}
/>
</div>
</div>
);
};

export default MyPosts;
5 changes: 4 additions & 1 deletion src/components/mypage/MyActive.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import LikedPosts from './LikedPosts';
import MyLikedPokemon from './MyLikedPokemon';
import MyPosts from './MyPosts';
import styles from './Mypage.module.scss';
Expand All @@ -9,7 +10,9 @@ const MyActive = () => {
<div className={styles.myactive__posts}>
<MyPosts />
</div>
<div className={styles.myactive__posts__favorite}></div>
<div className={styles.myactive__posts__favorite}>
<LikedPosts />
</div>
</div>
<MyLikedPokemon />
</div>
Expand Down
7 changes: 7 additions & 0 deletions src/components/mypage/MyPosts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,18 @@ const MyPosts = () => {
console.error(error);
}
}

return;
};

const handlePageChange = (pageNumber: number) => {
setCurrentPage(pageNumber);
};

const onMovetoDocument = (postId: string) => {
navigate(`/community/detail/${postId}`);
};

return (
<div style={{ height: '100%' }}>
<div className={styles.myactive__posts__title}>
Expand All @@ -102,6 +108,7 @@ const MyPosts = () => {
post={post}
onEdit={onEdit}
onDelete={onDelete}
onMovetoDocument={onMovetoDocument}
/>
))}
</div>
Expand Down
4 changes: 3 additions & 1 deletion src/components/mypage/Mypage.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@
span {
color: #000;
font-family: Gmarket Sans;
font-size: 28px;
font-size: 24px;
font-style: normal;
font-weight: 600;
line-height: normal;
Expand All @@ -306,6 +306,7 @@
display: flex;
flex-direction: column;
align-items: center;
cursor: pointer;

&__none {
display: flex;
Expand All @@ -316,6 +317,7 @@

&__item {
width: 549px;
height: 52px;
display: flex;
align-items: center;
justify-content: space-between;
Expand Down
36 changes: 36 additions & 0 deletions src/components/mypage/RenderLikedPosts.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { MouseEvent, memo } from 'react';

import styles from './Mypage.module.scss';
import { Liked } from './LikedPosts';
import { IoIosHeart } from '@react-icons/all-files/io/IoIosHeart';

interface RenderLikedPostsProps {
like: Liked;
onCancleLikedPost: (likeId: string) => void;
onMoveToDocument: (likeId: string) => void;
}

const RenderLikedPosts = memo(
({ like, onCancleLikedPost, onMoveToDocument }: RenderLikedPostsProps) => {
return (
<div
className={styles.myactive__posts__box__item}
onClick={() => onMoveToDocument(like.id)}
>
<span>{like.data.title}</span>
<div>
<button
onClick={(e: MouseEvent<HTMLButtonElement>) => {
e.stopPropagation();
onCancleLikedPost(like.id);
}}
>
<IoIosHeart color={'#fd0000'} size={20} />
</button>
</div>
</div>
);
},
);

export default RenderLikedPosts;
41 changes: 24 additions & 17 deletions src/components/mypage/RenderPost.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,36 @@
import { memo } from 'react';
import { MouseEvent, memo } from 'react';
import { PostData, Posts } from './MyPosts';
import styles from './Mypage.module.scss';

interface RenderPostProps {
post: Posts;
onDelete: (postId: string) => void;
onEdit: (data: PostData, id: string) => void;
onMovetoDocument: (postId: string) => void;
}

const RenderPost = memo(({ post, onDelete, onEdit }: RenderPostProps) => {
return (
<div className={styles.myactive__posts__box__item}>
<span>{post.data.title}</span>
<div className={styles.myactive__posts__box__btn__group}>
<button
onClick={() => {
onEdit(post.data, post.id);
}}
>
수정
</button>
<button onClick={() => onDelete(post.id)}>삭제</button>
const RenderPost = memo(
({ post, onDelete, onEdit, onMovetoDocument }: RenderPostProps) => {
return (
<div
className={styles.myactive__posts__box__item}
onClick={() => onMovetoDocument(post.id)}
>
<span>{post.data.title}</span>
<div className={styles.myactive__posts__box__btn__group}>
<button
onClick={(e: MouseEvent<HTMLButtonElement>) => {
e.stopPropagation();
onEdit(post.data, post.id);
}}
>
수정
</button>
<button onClick={() => onDelete(post.id)}>삭제</button>
</div>
</div>
</div>
);
});
);
},
);

export default RenderPost;
1 change: 1 addition & 0 deletions src/hook/useCommunityDataList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const useCommunityDataList = (val: string) => {
};

fetchData();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []); // 빈 배열을 전달하여 컴포넌트가 마운트될 때 한 번만 실행되도록 함

return { dataList, commentsList, repliesList, setDataList };
Expand Down
2 changes: 1 addition & 1 deletion src/pages/mypage/myPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Mycard from '@/components/mypage/Mycard';
const myPage = () => {
return (
<>
<Inner>
<Inner style={{ marginBottom: '100px' }}>
<Introduce />
<Mycard />
<MyActive />
Expand Down
2 changes: 2 additions & 0 deletions src/styles/global.scss
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,6 @@ body {

button {
cursor: pointer;
border: none;
background-color: inherit;
}
Loading