Skip to content

Commit fa289f7

Browse files
authored
Merge pull request #2 from tkokhing/postgen
major revamp to components housekeep
2 parents d75a599 + 9ff2148 commit fa289f7

16 files changed

Lines changed: 89 additions & 50 deletions

File tree

src/app/_components/all-stories-title.tsx

Lines changed: 0 additions & 29 deletions
This file was deleted.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
"use client";
2+
3+
import { useState } from "react";
4+
import { Post } from "@/interfaces/post";
5+
import { TitlePreview } from "../title-preview";
6+
7+
type Props = {
8+
posts: Post[];
9+
};
10+
11+
export function AllStoriesTitle({ posts }: Props) {
12+
const [sortBy, setSortBy] = useState<"title" | "date">("title");
13+
14+
const sortedPosts = [...posts].sort((a, b) => {
15+
if (sortBy === "title") {
16+
return a.title.localeCompare(b.title);
17+
} else {
18+
return new Date(b.date).getTime() - new Date(a.date).getTime();
19+
}
20+
});
21+
22+
return (
23+
<section>
24+
<div className="flex justify-between items-center mb-4">
25+
<h2 className="text-4xl md:text-6xl font-thin tracking-tighter leading-tight">
26+
Browse by {sortBy === "title" ? "Title (A–Z)" : "Date (Newest)"}
27+
</h2>
28+
<div className="flex gap-2">
29+
<button
30+
onClick={() => setSortBy("title")}
31+
disabled={sortBy === "title"}
32+
className={`px-3 py-1 rounded transition ${
33+
sortBy === "title"
34+
? "bg-gray-700 dark:bg-gray-600 text-tkokhing-blue cursor-default"
35+
: "bg-gray-200 hover:bg-gray-500 dark:text-tkokhing-blue hover:text-tkokhing-dark hover:dark:text-tkokhing-dark"
36+
}`}
37+
>
38+
A–Z
39+
</button>
40+
<button
41+
onClick={() => setSortBy("date")}
42+
disabled={sortBy === "date"}
43+
className={`px-3 py-1 rounded transition ${
44+
sortBy === "date"
45+
? "bg-gray-700 dark:bg-gray-600 text-tkokhing-blue cursor-default"
46+
: "bg-gray-200 hover:bg-gray-500 dark:text-tkokhing-blue hover:text-tkokhing-dark hover:dark:text-tkokhing-dark"
47+
}`}
48+
>
49+
Date
50+
</button>
51+
</div>
52+
</div>
53+
54+
<div>
55+
{sortedPosts.map((post) => (
56+
<TitlePreview
57+
key={post.slug}
58+
title={post.title}
59+
date={post.date}
60+
slug={post.slug}
61+
subPath={post.subPath}
62+
postStatus={post.postStatus}
63+
/>
64+
))}
65+
</div>
66+
</section>
67+
);
68+
}

src/app/_components/hero-post.tsx renamed to src/app/_components/post_gen/hero-post.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Avatar from "@/app/_components/avatar";
22
import CoverImage from "@/app/_components/cover-image";
33
import { type Author } from "@/interfaces/author";
44
import Link from "next/link";
5-
import DateFormatter from "./date-formatter";
5+
import DateFormatter from "../date-formatter";
66

77
type Props = {
88
title: string;
File renamed without changes.
File renamed without changes.

src/app/_components/post-body.tsx renamed to src/app/_components/post_gen/post-body.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { MDXRemote } from 'next-mdx-remote/rsc';
22
import rehypeSlug from 'rehype-slug';
33
import rehypeAutolinkHeadings from 'rehype-autolink-headings';
44
import remarkGfm from 'remark-gfm';
5-
import PostBodyClient from '@/app/_components/post-body-client'; // 👈 import client wrapper
5+
import PostBodyClient from '@/app/_components/post_gen/post-body-client'; // 👈 import client wrapper
66

77
type Props = {
88
content: string;

src/app/_components/post-header.tsx renamed to src/app/_components/post_gen/post-header.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import Avatar from "./avatar";
2-
import CoverImage from "./cover-image";
3-
import DateFormatter from "./date-formatter";
4-
import { PostTitle } from "@/app/_components/post-title";
1+
import Avatar from "../avatar";
2+
import CoverImage from "../cover-image";
3+
import DateFormatter from "../date-formatter";
4+
import { PostTitle } from "@/app/_components/post_gen/post-title";
55
import { type Author } from "@/interfaces/author";
66

77
type Props = {

src/app/_components/post-preview.tsx renamed to src/app/_components/post_gen/post-preview.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { type Author } from "@/interfaces/author";
22
import Link from "next/link";
3-
import Avatar from "./avatar";
4-
import CoverImage from "./cover-image";
5-
import DateFormatter from "./date-formatter";
3+
import Avatar from "../avatar";
4+
import CoverImage from "../cover-image";
5+
import DateFormatter from "../date-formatter";
66

77
type Props = {
88
title: string;
File renamed without changes.

src/app/blog/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Container from "@/app/_components/container";
22
import { getAllPosts } from "@/lib/api";
3-
import { HeroPost } from "@/app/_components/hero-post";
4-
import { MoreStories } from "@/app/_components/more-stories";
3+
import { HeroPost } from "@/app/_components/post_gen/hero-post";
4+
import { MoreStories } from "@/app/_components/post_gen/more-stories";
55

66
export default function Index() {
77
const allPosts = getAllPosts("_posts");

0 commit comments

Comments
 (0)