Skip to content

Commit 52031c9

Browse files
Merge pull request #27 from kmc-jp/dev
デザインの刷新
2 parents 2a0edbe + 795f670 commit 52031c9

File tree

9 files changed

+105
-125
lines changed

9 files changed

+105
-125
lines changed

public/search.svg

Lines changed: 1 addition & 0 deletions
Loading

src/app/articles/[id]/page.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,27 @@ export default function ArticlePage({ params }: { params: Promise<{ id: string }
1919
if (id) {
2020
getArticle(id).then((article) => {
2121
setArticle(article);
22+
2223
});
2324
}
2425
}, [id]);
2526

26-
if (!article) {
27-
return <div>記事が見つかりませんでした。</div>;
27+
if (article == null) {
28+
return <div></div>;
2829
}
2930

3031
return (
31-
<div className="container mx-auto px-4 py-8">
32+
33+
<div className="bg-white mx-4 mt-4 px-7 pt-10 pb-20 rounded-sm">
3234
<article className="max-w-none">
33-
<div className="mb-8">
34-
<h1 className="text-4xl font-extrabold text-black mb-2">{safeStringify(article.title)}</h1>
35-
<div className="flex items-center text-gray-500">
36-
<p className="mr-4">By <Link href={`/author/${article.author.inner}`} className="hover:underline">{safeStringify(article.author)}</Link></p>
37-
<p>{new Date(safeStringify(article.created_at)).toLocaleDateString('ja-JP')}</p>
35+
<div className="mb-10">
36+
<h1 className="text-4xl font-extrabold text-gray-600 mb-4">{safeStringify(article.title)}</h1>
37+
<div className="flex items-center">
38+
<p className="mr-4 text-sky-600">By <Link href={`/author/${article.author.inner}`} className="hover:underline">{safeStringify(article.author)}</Link></p>
39+
<p className="text-gray-500">{new Date(safeStringify(article.created_at)).toLocaleDateString('ja-JP')}</p>
3840
</div>
3941
</div>
40-
<p className="text-black">{safeStringify(article.content)}</p>
42+
<p className="text-gray-700">{safeStringify(article.content)}</p>
4143
</article>
4244
</div>
4345
);

src/app/articles/page.tsx

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,37 @@
11
'use client'
22

3-
import Link from 'next/link';
43
import { getArticles } from '@/lib/api';
5-
import { safeStringify } from '@/lib/utils';
64
import { useState, useEffect } from 'react';
5+
import { safeStringify } from '@/lib/utils';
6+
import ArticleCard from '@/app/components/ArticleCard';
77

88
export default function Home() {
99
const [articles, setArticles] = useState<any[]>([]);
1010

1111
useEffect(() => {
1212
getArticles().then((articles) => {
1313
setArticles(articles);
14+
if (!Array.isArray(articles)) {
15+
return <div>記事が見つかりませんでした。</div>;
16+
}
17+
18+
if (articles.length === 0) {
19+
return <div>記事がありません。</div>;
20+
}
1421
});
1522
}, [])
1623

17-
if (!Array.isArray(articles)) {
18-
return <div>記事が見つかりませんでした。</div>;
19-
}
2024

21-
if (articles.length === 0) {
22-
return <div>記事がありません。</div>;
23-
}
2425

2526
return (
2627
<>
27-
{articles.map((article: any, index: number) => (
28-
<div key={safeStringify(article._id) || `article-${index}`}
29-
className="border-b border-gray-200 p-10">
30-
<div className="text-sm font-bold text-gray-500">{safeStringify(article._id)}</div>
31-
<Link href={`/articles/${safeStringify(article._id)}`}>
32-
<div className="text-xl font-bold cursor-pointer hover:underline">{safeStringify(article.title)}</div>
33-
</Link>
34-
<div className="text-lg font-bold">
35-
<Link href={`/author/${safeStringify(article.author.inner)}`} className="hover:underline">
36-
{safeStringify(article.author)}
37-
</Link>
38-
</div>
39-
<div className="text-base font-bold">{safeStringify(article.created_at)}</div>
40-
<div className="border border-gray-200 p-5 m-2">
41-
<div className="text-sm">{safeStringify(article.content)}</div>
28+
<div className="mx-8 mt-8">
29+
{articles.map((article: any) => (
30+
<div key={safeStringify(article._id)} className="my-4">
31+
<ArticleCard article={article} showAuthor={true} />
4232
</div>
43-
</div>
44-
))}
33+
))}
34+
</div>
4535
</>
4636
);
4737
}

src/app/author/[author]/page.tsx

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
'use client'
22

3-
import Link from 'next/link';
43
import { getArticlesByUser } from '@/lib/api';
5-
import { safeStringify } from '@/lib/utils';
64
import { useState, useEffect } from 'react';
5+
import { safeStringify } from '@/lib/utils';
6+
import ArticleCard from '@/app/components/ArticleCard';
77

88
export default function Home({ params }: { params: Promise<{ author: string }> }) {
99
const [userName, setUserName] = useState<string>('');
@@ -19,39 +19,31 @@ export default function Home({ params }: { params: Promise<{ author: string }> }
1919
if (userName) {
2020
getArticlesByUser(userName).then((articles) => {
2121
setArticles(articles);
22+
if (!Array.isArray(articles)) {
23+
return <div>記事が見つかりませんでした。</div>;
24+
}
25+
if (articles.length === 0) {
26+
return <div>記事がありません。</div>;
27+
}
2228
});
2329
}
30+
2431
}, [userName]);
2532

26-
if (!userName) {
27-
return <div>読み込み中...</div>;
28-
}
29-
30-
if (!Array.isArray(articles)) {
31-
return <div>記事が見つかりませんでした。</div>;
32-
}
33-
34-
if (articles.length === 0) {
35-
return <div></div>
36-
// return <div>記事がありません。</div>;
37-
}
33+
// if (!userName) {
34+
// return <div></div>;
35+
// }
3836

3937
return (
4038
<>
41-
{articles.map((article: any, index: number) => (
42-
<div key={safeStringify(article._id) || `article-${index}`}
43-
className="border-b border-gray-200 p-10">
44-
<div className="text-sm font-bold text-gray-500">{safeStringify(article._id)}</div>
45-
<Link href={`/articles/${safeStringify(article._id)}`}>
46-
<div className="text-xl font-bold cursor-pointer hover:underline">{safeStringify(article.title)}</div>
47-
</Link>
48-
<div className="text-lg font-bold">{safeStringify(article.author)}</div>
49-
<div className="text-base font-bold">{safeStringify(article.created_at)}</div>
50-
<div className="border border-gray-200 p-5 m-2">
51-
<div className="text-sm">{safeStringify(article.content)}</div>
39+
<div className="mx-8 mt-8">
40+
{userName && <h1 className="text-2xl font-medium p-2 text-gray-600">{ safeStringify(userName) }の記事一覧</h1> }
41+
{articles.map((article: any) => (
42+
<div key={safeStringify(article._id)} className="my-4">
43+
<ArticleCard article={article} showAuthor={false} />
5244
</div>
53-
</div>
54-
))}
45+
))}
46+
</div>
5547
</>
5648
);
5749
}

src/app/components/ArticleCard.tsx

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import Link from 'next/link';
2+
import { safeStringify } from '@/lib/utils';
3+
4+
type Article = {
5+
_id: any;
6+
title: any;
7+
author: any;
8+
created_at: any;
9+
content: any;
10+
};
11+
12+
type Props = {
13+
article: Article;
14+
showAuthor: boolean;
15+
};
16+
17+
export default function ArticleCard({ article, showAuthor }: Props) {
18+
return (
19+
<Link href={`/articles/${safeStringify(article._id)}`} className="group bg-white shadow-md px-8 pt-6 pb-5 rounded-sm block">
20+
<div className="flex text-sm text-gray-500 mb-2">{new Date(safeStringify(article.created_at)).toLocaleDateString()}</div>
21+
22+
<h2 className="text-2xl font-medium mb-4 text-sky-600 group-hover:text-red-400">{safeStringify(article.title)}</h2>
23+
24+
<p className="text-gray-500 line-clamp-2 mb-4">{safeStringify(article.content)}</p>
25+
26+
<div className="flex items-center text-sm text-gray-400">
27+
<div className="font-medium">
28+
{showAuthor ? (
29+
<div className="flex items-center">
30+
<p className="mr-1">By</p>
31+
<p>{safeStringify(article.author)}</p>
32+
</div>
33+
) : (
34+
""
35+
)}
36+
</div>
37+
</div>
38+
39+
</Link>
40+
);
41+
}

src/app/components/client-layout.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,20 @@
33
import { ReactNode } from "react";
44
import Header from "./header";
55
import Footer from "./footer";
6-
import Sidebar, { useSidebar } from "./sidebar";
76

87
interface ClientLayoutProps {
98
children: ReactNode;
109
}
1110

1211
export default function ClientLayout({ children }: ClientLayoutProps) {
13-
const { isOpen, closeSidebar, toggleSidebar } = useSidebar();
1412

1513
return (
1614
<>
17-
<Header onMenuClick={toggleSidebar} />
18-
<Sidebar isOpen={isOpen} onClose={closeSidebar} />
15+
<Header />
1916
<main className="min-h-screen mb-40">
2017
{children}
2118
</main>
2219
<Footer />
2320
</>
2421
);
25-
}
22+
}

src/app/components/footer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Link from "next/link";
22

33
export default function Footer() {
44
return (
5-
<footer className="bg-gray-900 text-white fixed bottom-0 left-0 right-0">
5+
<footer className="bg-gray-900 text-white flex items-center justify-center">
66
<div className="px-2 py-3">
77
{/* <div className="flex items-center space-x-2">
88
<span className="font-bold text-xl">みんウェブ Blog Platform</span>

src/app/components/header.tsx

Lines changed: 14 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,36 @@
11
import Link from "next/link";
2+
import Image from "next/image";
23

34
interface HeaderProps {
45
onMenuClick?: () => void;
56
}
67

78
export default function Header({ onMenuClick }: HeaderProps) {
89
return (
9-
<header className="bg-white shadow-sm border-b border-gray-200 sticky top-0 z-50">
10+
<header className="bg-white shadow-sm border-b border-gray-200 top-0 z-50">
1011
<div className="mx-7">
1112
<div className="flex justify-between items-center h-16">
1213
<div className="flex items-center space-x-4">
13-
{/* ハンバーガーメニューボタン */}
14-
<button
15-
onClick={onMenuClick}
16-
className="rounded-lg hover:bg-gray-100 transition-colors duration-200"
17-
aria-label="メニューを開く"
18-
>
19-
<svg
20-
className="w-6 h-6 text-gray-600"
21-
fill="none"
22-
stroke="currentColor"
23-
viewBox="0 0 24 24"
24-
>
25-
<path
26-
strokeLinecap="round"
27-
strokeLinejoin="round"
28-
strokeWidth={2}
29-
d="M4 6h16M4 12h16M4 18h16"
30-
/>
31-
</svg>
32-
</button>
33-
14+
3415
<Link href="/" className="flex items-center space-x-2">
35-
<span className="font-bold text-sm sm:text-base md:text-lg lg:text-xl text-gray-900 whitespace-nowrap">みんウェブ Blog Platform</span>
36-
</Link>
37-
</div>
38-
39-
{/* デスクトップナビゲーション */}
40-
<div className="hidden lg:flex items-center space-x-6">
41-
<Link
42-
href="/search"
43-
className="text-gray-600 hover:text-gray-900 transition-colors duration-200 font-medium"
44-
>
45-
検索
46-
</Link>
47-
<Link
48-
href="/category"
49-
className="text-gray-600 hover:text-gray-900 transition-colors duration-200 font-medium"
50-
>
51-
カテゴリー
52-
</Link>
53-
<Link
54-
href="/about"
55-
className="text-gray-600 hover:text-gray-900 transition-colors duration-200 font-medium"
56-
>
57-
About
16+
<span className="font-bold text-sm sm:text-base md:text-lg lg:text-xl text-gray-800 whitespace-nowrap">Blog Platform</span>
5817
</Link>
5918
</div>
6019

6120
<div className="flex items-center space-x-4">
62-
<Link
63-
href="/login"
64-
className="text-sm sm:text-base text-gray-600 hover:text-gray-900 transition-colors duration-200 font-medium"
65-
>
66-
ログイン
67-
</Link>
68-
<Link
69-
href="/signup"
70-
className="text-sm sm:text-base bg-gradient-to-r from-blue-600 to-purple-600 text-white px-4 py-2 rounded-lg hover:shadow-lg transition-all duration-200 font-medium"
71-
>
72-
新規登録
21+
<Link href="/search">
22+
<Image src="/search.svg" alt="Search" width={24} height={24} className="cursor-pointer" />
7323
</Link>
24+
<div className="flex items-center px-4 py-2 rounded-2xl border border-gray-300 hover:bg-gray-200 transition-colors duration-200">
25+
<Link
26+
href="/auth"
27+
className="text-s font-bold text-gray-500">
28+
ログイン
29+
</Link>
30+
</div>
7431
</div>
7532
</div>
7633
</div>
7734
</header>
7835
);
79-
}
36+
}

src/app/globals.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@import "tailwindcss";
22

33
:root {
4-
--background: #ffffff;
4+
--background: #f3f4f5;
55
--foreground: #171717;
66
}
77

0 commit comments

Comments
 (0)