Skip to content

Commit ff88faf

Browse files
authored
Merge pull request #117 from DMU-DebugVisual/inseong
Inseong
2 parents bf26909 + 4b6ef14 commit ff88faf

File tree

8 files changed

+1117
-206
lines changed

8 files changed

+1117
-206
lines changed

src/App.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import Settings from "./components/mypage/Settings";
1717
import Shared from "./components/mypage/Shared";
1818
import MyProject from "./components/mypage/MyProject";
1919
import MyCommunity from "./components/mypage/MyCommunity";
20+
import Notifications from "./components/mypage/Notifications";
2021
import ScrollToTop from "./components/common/ScrollToTop";
2122
import CommunityWrite from "./components/community/CommunityWrite";
2223
import PostDetail from "./components/community/PostDetail";
@@ -129,6 +130,7 @@ function AppContent() {
129130
<Route path="community" element={<MyCommunity nickname={nickname} />} />
130131
<Route path="setting" element={<Settings nickname={nickname} />} />
131132
<Route path="shared" element={<Shared />} />
133+
<Route path="notifications" element={<Notifications />} />
132134
</Route>
133135
<Route path="*" element={<Navigate to="/" replace />} />
134136
</Routes>

src/components/community/Community.jsx

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export default function Community() {
5151
const [searchOperator, setSearchOperator] = useState(DEFAULT_OPERATOR);
5252

5353
const PAGE_SIZE = 10;
54+
const PAGE_BUTTON_LIMIT = 5;
5455

5556
useEffect(() => {
5657
let ignore = false;
@@ -332,9 +333,16 @@ export default function Community() {
332333
setLastKnownPage(currentPage);
333334
}, [currentPage, totalPages]);
334335

335-
const pageNumbers = useMemo(() => (
336-
Array.from({ length: totalPages }, (_, index) => index + 1)
337-
), [totalPages]);
336+
const pageNumbers = useMemo(() => {
337+
if (totalPages <= 0) return [];
338+
if (totalPages <= PAGE_BUTTON_LIMIT) {
339+
return Array.from({ length: totalPages }, (_, index) => index + 1);
340+
}
341+
const chunkIndex = Math.floor((currentPage - 1) / PAGE_BUTTON_LIMIT);
342+
const start = chunkIndex * PAGE_BUTTON_LIMIT + 1;
343+
const end = Math.min(start + PAGE_BUTTON_LIMIT - 1, totalPages);
344+
return Array.from({ length: end - start + 1 }, (_, index) => start + index);
345+
}, [currentPage, totalPages]);
338346

339347
const paginatedPosts = useMemo(() => {
340348
const start = (currentPage - 1) * PAGE_SIZE;
@@ -421,21 +429,22 @@ export default function Community() {
421429
.slice(0, 5);
422430
}, [posts]);
423431

424-
const jumpBy = 5;
425432
const goToPage = (page) => {
426433
if (page < 1 || page > totalPages) return;
427434
setCurrentPage(page);
428435
};
429436

430-
const handleChunkMove = (direction) => {
431-
const target = currentPage + direction * jumpBy;
432-
if (target < 1) {
433-
setCurrentPage(1);
434-
} else if (target > totalPages) {
435-
setCurrentPage(totalPages);
436-
} else {
437-
setCurrentPage(target);
438-
}
437+
const canGoPrev = currentPage > 1;
438+
const canGoNext = currentPage < totalPages;
439+
440+
const handlePrevPage = () => {
441+
if (!canGoPrev) return;
442+
goToPage(currentPage - 1);
443+
};
444+
445+
const handleNextPage = () => {
446+
if (!canGoNext) return;
447+
goToPage(currentPage + 1);
439448
};
440449

441450
return (
@@ -649,17 +658,17 @@ export default function Community() {
649658
type="button"
650659
className="page-button"
651660
onClick={() => goToPage(1)}
652-
disabled={currentPage === 1}
661+
disabled={!canGoPrev}
653662
>
654-
처음
663+
&lt;&lt;
655664
</button>
656665
<button
657666
type="button"
658667
className="page-button"
659-
onClick={() => handleChunkMove(-1)}
660-
disabled={currentPage === 1}
668+
onClick={handlePrevPage}
669+
disabled={!canGoPrev}
661670
>
662-
-5쪽
671+
&lt;
663672
</button>
664673
{pageNumbers.map((page) => (
665674
<button
@@ -674,18 +683,18 @@ export default function Community() {
674683
<button
675684
type="button"
676685
className="page-button"
677-
onClick={() => handleChunkMove(1)}
678-
disabled={currentPage === totalPages}
686+
onClick={handleNextPage}
687+
disabled={!canGoNext}
679688
>
680-
+5쪽
689+
&gt;
681690
</button>
682691
<button
683692
type="button"
684693
className="page-button"
685694
onClick={() => goToPage(totalPages)}
686-
disabled={currentPage === totalPages}
695+
disabled={!canGoNext}
687696
>
688-
마지막
697+
&gt;&gt;
689698
</button>
690699
</div>
691700
</div>

0 commit comments

Comments
 (0)