Skip to content

Commit b85c675

Browse files
Merge branch 'dev'
2 parents 1fa4c25 + d14a6e3 commit b85c675

File tree

4 files changed

+73
-7
lines changed

4 files changed

+73
-7
lines changed

src/app/[article_year]/[month]/[aid]/page.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ html {
77
.article-container {
88
display: flex;
99
gap: 20px;
10+
align-items: flex-start;
11+
justify-content: center;
1012
flex-wrap: wrap;
1113
overflow-x: hidden auto;
1214
min-height: 100vh;
@@ -244,9 +246,13 @@ html {
244246
}
245247

246248
.other-articles {
249+
align-items: center;
250+
justify-content: center;
247251
margin-top: 40px;
248252
top: 20px;
249253
max-width: 250px;
254+
margin-left: 0 auto;
255+
margin-right: 0 auto;
250256
background-color: transparent;
251257
/* スクロール時に追従 */
252258
}
@@ -296,6 +302,10 @@ html {
296302
.other-articles {
297303
position: relative;
298304
/* stickyを無効化 */
305+
display: flex;
306+
flex-direction: column;
307+
align-items: center;
308+
justify-content: center;
299309
max-width: 90vw;
300310
margin: 0 auto;
301311
top: auto;
@@ -305,6 +315,7 @@ html {
305315

306316
.other-articles .article-link {
307317
width: 90%;
318+
margin: 0 auto;
308319
}
309320

310321
.article-content {
Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,71 @@
11
"use client";
2-
import { ReactNode } from "react";
2+
import { ReactNode, useState } from "react";
33
import { generateArticleButton, Article } from "../article-client";
4-
import { useLocale } from "@/app/i18nProvider";
4+
import { useTranslations } from "next-intl";
55

66
interface ArticleListProps {
77
articles: Article[];
88
}
99

1010
export default function ArticleList({ articles }: ArticleListProps) {
11-
const locale = useLocale();
12-
const filteredArticles = articles.filter((a) => a.lang === locale);
11+
const t = useTranslations();
12+
const locale = t("info.lang");
13+
const [searchQuery, setSearchQuery] = useState("");
14+
const [currentPage, setCurrentPage] = useState(1);
15+
16+
const articlesPerPage = 8;
17+
18+
// 検索とフィルタリング
19+
const filteredArticles = articles
20+
.filter((a) => a.lang === locale)
21+
.filter((a) =>
22+
a.title.toLowerCase().includes(searchQuery.toLowerCase())
23+
);
24+
25+
// ページネーション用の計算
26+
const totalPages = Math.ceil(filteredArticles.length / articlesPerPage);
27+
const startIndex = (currentPage - 1) * articlesPerPage;
28+
const currentArticles = filteredArticles.slice(
29+
startIndex,
30+
startIndex + articlesPerPage
31+
);
32+
33+
// ページ変更ハンドラー
34+
const handlePageChange = (page: number) => {
35+
if (page >= 1 && page <= totalPages) {
36+
setCurrentPage(page);
37+
}
38+
};
39+
1340
return (
1441
<section className="articles">
15-
{filteredArticles.map(
42+
<input
43+
type="text"
44+
placeholder="Search articles..."
45+
value={searchQuery}
46+
onChange={(e) => setSearchQuery(e.target.value)}
47+
className="search-input"
48+
/>
49+
{currentArticles.map(
1650
(article: Article): ReactNode => generateArticleButton(article)
1751
)}
52+
<div className="pagination">
53+
<button
54+
onClick={() => handlePageChange(currentPage - 1)}
55+
disabled={currentPage === 1}
56+
>
57+
{t("pages.article.words.previous")}
58+
</button>
59+
<span>
60+
Page {currentPage} of {totalPages}
61+
</span>
62+
<button
63+
onClick={() => handlePageChange(currentPage + 1)}
64+
disabled={currentPage === totalPages}
65+
>
66+
{t("pages.article.words.next")}
67+
</button>
68+
</div>
1869
</section>
1970
);
2071
}

src/i18n/en/common.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
"msg2": "I write about various topics, so please take a look!"
2222
},
2323
"words": {
24-
"search": "Search"
24+
"search": "Search",
25+
"previous":"Previous",
26+
"next":"Next"
2527
},
2628
"content": {
2729
"words": {

src/i18n/ja/common.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
"msg2": "色々書いているので是非見てください!"
2222
},
2323
"words": {
24-
"search": "検索"
24+
"search": "検索",
25+
"previous":"前へ",
26+
"next":"次へ"
2527
},
2628
"content":{
2729
"words":{

0 commit comments

Comments
 (0)