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

Feat : notice page (#77) #78

Merged
merged 1 commit into from
Aug 10, 2024
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
12 changes: 12 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"react-dom": "^18.2.0",
"react-minimal-side-navigation": "^1.9.2",
"react-modal": "^3.16.1",
"react-paginate": "^8.2.0",
"react-redux": "^9.1.0",
"react-responsive": "^10.0.0",
"react-router-dom": "^6.22.3",
Expand Down
3 changes: 3 additions & 0 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import EditPage from "./component/admin/EditPage";
import PendingList from "./component/admin/pending/PendingList";
import Layout from "./component/admin/component/Layout";
import ClubReviews from "./component/admin/ClubReviews";
import NoticePage from "./component/main/NoticePage";

function App() {
const isPc = useMediaQuery({
Expand All @@ -38,6 +39,7 @@ function App() {
<Header />
<Routes>
<Route path="/" element={<MainPage />} />
<Route path="/notice" element={<NoticePage />}></Route>
<Route path="/central" element={<CentralClubPage />} />
{/* <Route path="/menu/central_club/detail_page/review_write" element={<ReviewWrite />} /> */}
<Route path="/small" element={<SmallClubPage />} />
Expand Down Expand Up @@ -70,6 +72,7 @@ function App() {
<Header />
<Routes>
<Route path="/" element={<MainPage />} />
<Route path="/notice" element={<NoticePage />}></Route>
<Route path="/central" element={<CentralClubPage />} />
<Route path="/small" element={<SmallClubPage />} />
<Route path="/clubs/:clubId" element={<DetailPage />} />
Expand Down
9 changes: 6 additions & 3 deletions src/component/main/MainNotice.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { useState, useEffect } from "react";
import styles from "./mainNotice.module.css";
import { customAxios } from "../../config/axios-config";
import { LinkItem } from "../branch/BranchCentral";

export default function MainNotice() {
const [noticeData, setNoticeData] = useState([]);

const getNoticeData = async () => {
try {
const res = await customAxios.get(`/v1/notices`);
const res = await customAxios.get(`/v1/notices/main-page`);
if (res.data.success) {
setNoticeData(res.data.data);
console.log(res.data.data);
Expand All @@ -32,11 +33,13 @@ export default function MainNotice() {
// 메인 νŽ˜μ΄μ§€μ— 보여쀄 곡지사항
return (
<div className={styles.container}>
<div className={styles.notice_index}>곡지사항</div>
<LinkItem to={'/notice'}>
<div className={styles.notice_index}>곡지사항</div>
</LinkItem>
<div className={styles.notice_container}>
{noticeData.map((item) => (
<div key={item.noticeId} className={styles.div_notice}>
<div>{item.content}</div>
<div>{item.title}</div>
<p className={styles.notice_line}>|</p>
<p className={styles.notice_date}>{formatDate(item.createdAt)}</p>
</div>
Expand Down
77 changes: 77 additions & 0 deletions src/component/main/NoticePage.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import React, { useState, useEffect } from "react";
import ReactPaginate from "react-paginate";
import { customAxios } from "../../config/axios-config";
import './noticePage.css';

export default function NoticePage() {
const [noticeData, setNoticeData] = useState([]);
const [pageCount, setPageCount] = useState(0);
const [currentPage, setCurrentPage] = useState(0);
const itemsPerPage = 10;

const getNoticeData = async (page = 0) => {
try {
const res = await customAxios.get(`/v1/notices`, {
params: { page, size: itemsPerPage }
});
if (res.data.success && res.data.data.content) {
setNoticeData(res.data.data.content);
setPageCount(res.data.data.totalPages);
} else {
setNoticeData([]);
}
} catch (error) {
console.error("Error fetching data: ", error);
setNoticeData([]);
}
};

useEffect(() => {
getNoticeData(currentPage);
}, [currentPage]);

const handlePageClick = ({ selected }) => {
setCurrentPage(selected);
};

return (
<div className="notice_container">
<h2>곡지사항</h2>
<div className="notice_list">
<div className="notice_header">
<span>번호</span>
<span>제λͺ©</span>
<span>λ‚ μ§œ</span>
<span>μž‘μ„±μž</span>
<span>쑰회수</span>
</div>
{noticeData.length > 0 ? (
noticeData.map((item, index) => (
<div key={item.noticeId} className="notice_item">
<span>{currentPage * itemsPerPage + index + 1}</span>
<span>{item.title}</span>
<span>{new Date(item.createdAt).toLocaleDateString()}</span>
<span>κ΄€λ¦¬μž</span>
{item.totalView ? <span>{item.totalView}</span> : <span>0</span>}
</div>
))
) : (
<div className="notice_item">
<span>곡지사항이 μ—†μŠ΅λ‹ˆλ‹€.</span>
</div>
)}
</div>
<ReactPaginate
previousLabel={'<'}
nextLabel={'>'}
pageCount={pageCount}
onPageChange={handlePageClick}
containerClassName={'pagination'}
previousLinkClassName={'pagination_link'}
nextLinkClassName={'pagination_link'}
disabledClassName={'pagination_link_disabled'}
activeClassName={'pagination_link_active'}
/>
</div>
);
}
76 changes: 76 additions & 0 deletions src/component/main/noticePage.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
.notice_container {
width: 80%;
margin: 0 auto;
font-family: Arial, sans-serif;
}

h2 {
text-align: center;
margin-bottom: 20px;
}

.notice_list {
width: 100%;
border-collapse: collapse;
}

.notice_header, .notice_item {
display: grid;
grid-template-columns: 1fr 4fr 2fr 2fr 1fr;
border-bottom: 1px solid #ddd;
padding: 10px 0;
}

.notice_header {
background-color: #f4f4f4;
font-weight: bold;
}

.notice_item span {
text-align: center;
}

.notice_item {
color: #666;
transition: background-color 0.3s;
}

.notice_item:hover {
background-color: #f9f9f9;
}

.notice_item:nth-child(even) {
background-color: #f4f4f4;
}

.notice_item:nth-child(odd) {
background-color: #fff;
}

.pagination {
display: flex;
justify-content: center;
margin-top: 20px;
list-style: none;
padding: 0;
}

.pagination_link {
margin: 0 5px;
padding: 8px 12px;
border: 1px solid #ddd;
cursor: pointer;
color: #007bff;
}

.pagination_link_active {
background-color: #007bff;
color: #fff;
border: none;
}

.pagination_link_disabled {
color: #ccc;
cursor: not-allowed;
}

Loading